-
Notifications
You must be signed in to change notification settings - Fork 780
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ForceFlush to TracerProvider #1837
Add ForceFlush to TracerProvider #1837
Conversation
If you want to do a ForceFlush on your BatchExporter, you could store a reference to the BatchExportProcessor, pass it AddProcessor method when building the TracerProvider, and call ForceFlush on it when needed. You could try something like this:
ForceFlush is not meant for TracerProvider. According to the spec, it is only provided for Processors and is relevant only to BatchExportProcessors. |
The latest link of OpenTelemetry Java I guess we want to test the water if this is something that should be added in the spec? |
@utpilla I thought about this approach, but if you have a look at exporters none of them provides such a feature.
The same you can say about
So my question is: |
If you check the issue template, it mentioned: Before opening a feature request against this repo, consider whether the feature should/could be implemented in the other OpenTelemetry client libraries. If so, please open an issue on opentelemetry-specification first. What I want to test: if the spec is okay to take the change and add |
Also, found the java PR. The conversation there may be useful. The author of this PR had the same issue with the lambda, so probably people will want to have something like this feature. |
@@ -199,6 +199,11 @@ internal TracerProviderSdk AddProcessor(BaseProcessor<Activity> processor) | |||
return this; | |||
} | |||
|
|||
internal bool OnForceFlush(int timeoutMilliseconds) | |||
{ | |||
return this.processor.ForceFlush(timeoutMilliseconds); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could throw NullReferenceException
if this.processor
is null.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change and the rationale make sense to me.
LGTM assuming the NullReferenceException comment is resolved.
Consider adding a small test case just to prevent the regression. |
Consider updating the CHANGELOG. |
@reyang thank you, good points. Everything is fixed. Please, check it's correct. |
Codecov Report
@@ Coverage Diff @@
## main #1837 +/- ##
==========================================
+ Coverage 82.88% 83.79% +0.91%
==========================================
Files 193 187 -6
Lines 6005 5967 -38
==========================================
+ Hits 4977 5000 +23
+ Misses 1028 967 -61
|
/// Thrown when the <c>timeoutMilliseconds</c> is smaller than -1. | ||
/// </exception> | ||
/// <remarks> | ||
/// This function guarantees thread-safety. Only the first call will |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// This function guarantees thread-safety. |
The semantic is a bit different than Shutdown
, ForceFlush
can be called multiple times and there is no restriction on which call will win (it is a win-win situation😄).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider borrow the wording from
/// Flushes the processor, blocks the current thread until flush |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, copypaste issue :D
I will change according to this doc: https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/src/OpenTelemetry/BaseProcessor.cs#L81
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider borrow the wording from
Thank you. Took this part and also added information about TracerProviderSdk
like it was made on the Shutdown
method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks perfect to me now.
You can achieve the same for Zipkin or Jaeger or any other exporter using the same approach:
No the spec explicitly asks to provide a Shutdown method for TracerProvider. Here is the link to that: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/sdk.md#shutdown.
"Shutdown MUST include the effects of ForceFlush." is applicable to the Shutdown of Span Processors. Also, if you look at the requirements for TracerProvider Shutdown it says that: Shutdown MUST be implemented at least by invoking Shutdown within all internal processors. So, in effect, if you call the Shutdown on the TracerProvider, it will call the Shutdown on all of its processor which include the effects of a ForceFlush.
I have just been stating why we have the TracerProvider and Processors implemented the way they are. Having said that, if we feel that we need to add ForceFlush to TracerProvider, we should go forward with it and also update the spec. |
@kipwoker Thanks for the PR. In this case, this issue is not limited to .NET or Java, so please open a spec issue. |
For me, it seems done and ready to merge. |
throw new ArgumentNullException(nameof(provider)); | ||
} | ||
|
||
if (provider is TracerProviderSdk tracerProviderSdk) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a hack. There should be some public type (class or interface) representing TracerProviderSdk. But I guess it's too late for that 😃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree. :)
I just made it like it was done for Shutdown
method. In my opinion, it's better to change nothing at the moment and make architectural changes at separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets not address any other issue in this PR :)
Happy to address them separate. (or not address :D)
Co-authored-by: Cijo Thomas <cithomas@microsoft.com>
I'm using OpenTelemetry for AWS lambda functions. And I'm using dotnet opentelemetry library to achieve that. After each call, lambda goes to sleep and freezes background threads. Therefore I need to send activities to the exporter forcibly if I want to use the batch processor instead of the simple one.
Thankfully,
BaseProcessor
already contains aForceFlush
method that works perfectly in this case.I've made a proof of concept
and it works as I expected. The only problem — access modifiers. This PR allows the user to trigger
TracerProvider.ForceFlush
without reflection. As I can see java solution has the same feature.Related to: open-telemetry/opentelemetry-java#1068