opentelemetry-python icon indicating copy to clipboard operation
opentelemetry-python copied to clipboard

Open telemetry auto instrumentation log flush error

Open ayuksekkaya opened this issue 5 months ago • 1 comments

Describe your environment

OS: Windows 11 Python version: 3.11.9 SDK version: 1.35.0 API version: 1.35.0

What happened?

I have a very basic FastAPI that I am orchestrating with dotnet aspire (I don't think the aspire part is related, but mentioning it to be sure). I am using the zero code instrumentation to export all logs, traces, and metrics to the aspire dashboard, however, in log,s I keep getting this error non-stop:

Traceback (most recent call last):
  File "D:\repos\...\PythonApp\.venv\Lib\site-packages\opentelemetry\sdk\_shared_internal\__init__.py", line 152, in _export
    self._exporter.export(
  File "D:\repos\...\PythonApp\.venv\Lib\site-packages\opentelemetry\sdk\_logs\_internal\export\__init__.py", line 98, in export
    self.out.flush()
OSError: [Errno 22] Invalid argument

The error starts happening shortly after the app starts, and even before the app receives a single HTTP request.

I can see that the app is started with this command:

D:\repos...\PythonApp.venv\Scripts\opentelemetry-instrument.exe --traces_exporter otlp --logs_exporter console,otlp --metrics_exporter otlp D:\repos...\PythonApp.venv\Scripts\python.exe main.py

I have some auto instrumentation libraries installed such as: "opentelemetry-instrumentation-fastapi". I can paste them all here if it will be useful. I am not using any manual instrumentation.

To be clear: everything is still working, both the console logger and the aspire dashboard. I can see all the traces, metrics, and logs in the dashboard.

And this error only appears on the Aspire dashboard, where the structured logs are supposed to appear, and not in the console, and that makes sense since the error seems to be coming from the exporter.

Steps to Reproduce

Start an auto-instrumented FastAPI that exports logs using grpc protocol to some compatible visualizer such as Grafana, Sentry, Azure App Insights or the Dotnet Aspire Dashboard (I only tested it with the Aspire dashboard, but I think it would be the same in other ones too)

Expected Result

I don't want to see the errors showing up every time it tries to flush. Everything is still working, but it's pretty annoying since it makes it impossible to see anything else on the dashboard.

Actual Result

Non-stop error message from the log exporter.

Additional context

No response

Would you like to implement a fix?

None

ayuksekkaya avatar Jul 24 '25 02:07 ayuksekkaya

Going by the stack trace, it looks like an error in the console exporter.

https://github.com/open-telemetry/opentelemetry-python/blob/23aad5e4adc143e8ca0cbca4b05802822b6d554f/opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/export/init.py#L98

I don't think this is related to #4688. It looks like you're using Windows, I'm guessing this is a Windows specific issue with that exporter since there is an OSError, possibly related to an invalid path.

Can you provide a minimal reproducer using just the console exporter (ideally without auto instrumentation) to help pinpoint the problem?

aabmass avatar Jul 28 '25 16:07 aabmass