Open Paulskit opened 1 year ago
You need to override the implementation of OnForceFlush
:
Also this is just a "base implementation" and it is up to the "concrete implementation" to do its best to adhere to the specification. Doing any logic would be a breaking change.
Also the docs says that one can implement OnForceFlush
.
@Paulskit Do you see any area of improvement or can we close the issue?
Hey @pellared, thanks for taking a look. Exporter in the repro is just to showcase the problem. OTLP Exporter behaves the same way.
My expectation, ForceFlush
should return only after all activities in queue has been processed. I see other implementations in otel, where we rely on the same behaviour.
Like this one in AWS Lambda:
https://github.com/open-telemetry/opentelemetry-dotnet-contrib/blob/2960a9defbe35ae14acc3b0b00983d09b186d61a/src/OpenTelemetry.Instrumentation.AWSLambda/AWSLambdaWrapper.cs#L201
We use force flush to make sure all recorded activities has been exported before lambda completes.
Quick investigation shows that combination of 2 behaviours lead to this issue: 1) CIrcularBuffer implementation where items end up in removed right after we read them https://github.com/open-telemetry/opentelemetry-dotnet/blob/fe78453c03feb8dbe506b2a0284312bdfa1367c5/src/OpenTelemetry/Internal/CircularBuffer.cs#L159
2) BatchExportProcessor implementation where exit condition is based on removed items https://github.com/open-telemetry/opentelemetry-dotnet/blob/fe78453c03feb8dbe506b2a0284312bdfa1367c5/src/OpenTelemetry/BatchExportProcessor.cs#L194
We have to read items in order to process them. Once we read items, ForceFlush exits (exit condition is successful), despite export process might still be in progress.
Thus, I think we should fix either the OTLP Exporter or BatchExportProcessor to properly support ForceFlush.
We are also encountering this issue with short-lived cron jobs running in Kubernetes.
@Paulskit did you find any workaround?
Bug Report
List of all OpenTelemetry NuGet packages and version that you are using:
Symptom
ForceFlush returns true, despite Activity export is still in progress and not finished.
What is the expected behavior?
ForceFlush should return true only when all activities was exported successfully.
What is the actual behavior?
Reproduce