-
Notifications
You must be signed in to change notification settings - Fork 782
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
Is there a way to synchronously flush any remaining logs that have not been exported over OTLP? #5102
Comments
Disposing the loggerfactory should have taken care of this. Since you mentioned even SimpleExportProcessor did not work, I am not sure if this is even related to lack of flush!. Could you share a minimal repro of the code you are using? |
I'm running in to a similar problem. A short lived .net app constructed using the
Any pointers would be appreciated. |
@BasJ93 See my reply above. Need to see a minimal code setup to give any other suggestions/fixes. |
This ^ is not the correct way to configure processor options for otlp log exporter. Setting that option has no effect on otlp log export processor and it will default to Batch OR
|
@cijothomas Did not realize that the force flush was tied to logger factory disposal! After playing around with that we were able to get something working, appreciate the pointer. @vishweshbankwar I see this is documented, but it's a bit confusing given that it sits right next to all the other options like |
@vishweshbankwar Makes sense, thanks! |
ForceFlush and disposal are slightly different things, but both achieve the goal of flushing out in-memory things! |
@cijothomas Thanks for clarifying that, just for my education is there an example of calling |
Almost all unit-tests in the repo (using inmemoryexporters) use ForceFlush() to avoid waiting for metrics to be exported. |
@cijothomas I see you are talking about metrics again. I can't seem to find a public api entry that allows for calling |
I used metrics merely as an example only! The concept is same for traces and logs. |
FYI if you are using a prerelease SDK version with the var appBuilder = WebApplication.CreateBuilder(args);
appBuilder.Logging.AddOpenTelemetry(builder => builder.AddOtlpExporter());
var app = appBuilder.Build();
var loggerProvider = app.Services.GetRequiredService<LoggerProvider>();
app.Run();
loggerProvider.ForceFlush(); That being said, it should not be necessary. Just make sure you dispose your host! var appBuilder = WebApplication.CreateBuilder(args);
appBuilder.Logging.AddOpenTelemetry(builder => builder.AddOtlpExporter());
using var app = appBuilder.Build(); // <- Added "using" to this
app.Run(); Disposing the host should dispose the |
That helped! Just not when the The loggers still work, but OpenTelemetry is already disposed and therefore does not export anything. Anyway, turns out this is not an OpenTelemetry bug for me! |
Question
Is there a way to attempt to synchronously flush any remaining logs that have not be exported over OTLP?
Context
We're running into a scenario where we have a very short lived .NET app (sometimes less than 1 second) that sets up logging with an OTLP exporter, logs a couple of statements while working, and exits. We've noticed that most the time the logs are not exported over OTLP, but are present in the console. We want a reliable way to make sure that the logs have at least been attempted to be exported before the process exits.
Attempted solutions
otlpOptions.ExportProcessorType = ExportProcessorType.Simple
did not workForceFlush
functionality described in the OTel documentation and also in the dotnet sdk here, but couldn't figure out exactly how to call it. It seems to show up in this "Unshipped Public Api" doc, so perhaps that's why.Would appreciate any pointers you could provide, thanks!
The text was updated successfully, but these errors were encountered: