-
Notifications
You must be signed in to change notification settings - Fork 790
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
feat(opentelemetry-sdk-trace-base): Add mandatory forceFlush property to SpanExporter interface #3071
Conversation
…to SpanExporter interface Signed-off-by: Sidartha Gracias <[email protected]>
Signed-off-by: Sidartha Gracias <[email protected]>
Signed-off-by: Sidartha Gracias <[email protected]>
Thank you for your contribution! I think built-in SpanProcessors like BatchSpanProcessor and SimpleSpanProcessor need to adopt the method and invoke the exporter's |
I see thank you, let me look at the span processors. For the test cases, do mean for testing span processors once the change is made? |
Yes the span processors will need to be tested. There really is no other way to test an interface than to test its implementers. |
Codecov Report
@@ Coverage Diff @@
## main #3071 +/- ##
==========================================
+ Coverage 93.18% 93.21% +0.02%
==========================================
Files 196 196
Lines 6431 6440 +9
Branches 1359 1359
==========================================
+ Hits 5993 6003 +10
+ Misses 438 437 -1
|
@legendecas @dyladan Also looking at BatchSpanProcessorBase, it currently implements forceFlush to call export for each batch, it doesn't seem to make sense to invoke the forceFlush on the exporter (since there shouldn't be anything left to export) |
Force flush in the exporter should return a promise which resolves when the currently export completes. If there is no batch currently exporting then it immediately resolves. |
Signed-off-by: Sidartha Gracias <[email protected]>
… for downstream exporters Signed-off-by: Sidartha Gracias <[email protected]>
BatchSpanProcessorBase already implements forceFlush. I have not changed it. Should we leave it as is or re-implement that functionality to invoke the exporters forceFlush function? Making the forceFlush function mandatory required updating a few downstream exporters
I have given these empty implementations for now, does that make sense? I spent a little time looking at these classes but it wasn't obvious to me what the implementation of forceFlush should be for these classes. |
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.
Please change the title as the interface is no longer optional
@@ -82,6 +82,10 @@ export class JaegerExporter implements SpanExporter { | |||
return this._shutdownOnce.call(); | |||
} | |||
|
|||
forceFlush(): Promise<void> { | |||
return Promise.resolve(); |
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.
Same as OTLP if it is possible then ForceFlush should only resolve when any in-flight exports are complete.
@@ -109,6 +109,10 @@ export class ZipkinExporter implements SpanExporter { | |||
}); | |||
} | |||
|
|||
forceFlush(): Promise<void> { | |||
return Promise.resolve(); |
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.
Same here
return this._flush(); | ||
} | ||
|
||
private _flush(): Promise<void> { |
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.
Why have a separate _flush method? Can't shutdown just call ForceFlush?
return this._flush(); | ||
} | ||
|
||
private _flush(): Promise<void> { | ||
this._finishedSpans = []; |
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.
Flushing should not reset. There is a dedicated method 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.
@dyladan thank you for the review, can you give your thoughts on BatchSpanProcessorBase (I posted a comment above) should we reimplement it, or leave as is
The batch span processor is specified to not call the exporter multiple times in parallel so you should be able to use forceflush to make sure the export is finished before the next batch is sent. |
.then(() => { | ||
/** ignore resolved values */ | ||
}); |
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.
No need to do .then
if you're just going to ignore the value.
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.
I can remove this, it was mostly a refactor (I moved the code out of the current shutdown function
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.
ah i see. i would just remove it since it doesn't serve a purpose
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.
Okay I will wrap this in a new promise, returning promise.all wouldn't work with the function type returning a promise
the current behavior of forceFlush on the processor returns a promise which resolves when all spans have been exported, so we currently
I don't really see where in this flow we would wan't to add a forceflush call. Do you think something like we do a bit of cleanup when each export completes |
The force flush isn't meant to be used in most cases. It is for special situations like shutdown and when you are in an environment that might unexpectedly get frozen or stopped like lambda. |
I think you can go either way but if you don't implement it please open an issue and we can get it fixed asap |
> I think you can go either way but if you don't implement it please open an issue and we can get it fixed asap
I have updated all the downstream exporters |
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.
Thank you for your contribution. Overall LGTM % some nits.
packages/opentelemetry-sdk-trace-base/src/export/BatchSpanProcessorBase.ts
Outdated
Show resolved
Hide resolved
packages/opentelemetry-sdk-trace-base/test/common/export/SimpleSpanProcessor.test.ts
Show resolved
Hide resolved
packages/opentelemetry-sdk-trace-base/test/common/export/ConsoleSpanExporter.test.ts
Outdated
Show resolved
Hide resolved
packages/opentelemetry-exporter-zipkin/test/node/zipkin.test.ts
Outdated
Show resolved
Hide resolved
experimental/packages/otlp-exporter-base/test/node/util.test.ts
Outdated
Show resolved
Hide resolved
@legendecas thank you, let me know if the updated pr looks alright to you |
experimental/packages/otlp-exporter-base/src/OTLPExporterBase.ts
Outdated
Show resolved
Hide resolved
@dyladan can you let me know if this pr looks okay to you now |
This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days. |
This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days. |
@dyladan another look at this is appreciated :) |
@sgracias1 Would it be possible for me to pull down your PR and make the appropriate suggested changes? |
Which problem is this PR solving?
Add optional forceFlush property to SpanExporter interface per spec
Fixes #3067
Short description of the changes
Type of change
How Has This Been Tested?
added unit tests
Checklist: