Open kuza55 opened 1 year ago
After digging a bit more, it seems like adding this line to the top of my program fixes the issue, but I am not clear on whether this is a stable situation:
from opentelemetry.instrumentation.auto_instrumentation import sitecustomize
Is it possible that pants isn't detecting the instrumentor as a dependency. and so it isn't showing up in the pex? If so, you can explicitly add it as a dependency to your BUILD, as you did with the logging lib and otel exporter.
The issue is that opentelemetry-instrument is trying to inject this code at runtime via sitecustomize, but pex is built to be hermetic and not allow code injection like this.
FWIW, I also found a bug on this from the pex side that required a bunch of workaround: https://github.com/pantsbuild/pex/issues/2065
I don't fundamentally have an opinion here on what should happen (and importing sitecustomize is working for me), but I would like some sort of supported solution that hopefully doesn't require too much configuration/code.
But unused import won't pass cicd linter, is there a better way?
Describe your environment
Python 3.10.12
Steps to reproduce Describe exactly how to reproduce the error. Include a code sample if applicable.
Clone this repo: https://github.com/kuza55/pants_debug_otel/tree/main
Then run
OTEL_TRACES_EXPORTER=console OTEL_METRICS_EXPORTER=console OTEL_LOGS_EXPORTER=console OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true opentelemetry-instrument python3 dist/src/no_configuration.pex
What is the expected behavior? What did you expect to see?
I expected to see the same output as when I run the command on the python file directly
What is the actual behavior? What did you see instead?
Note: the logging integration is being executed inside the pex file, which is why we see any output at all
Additional context
It seems like I can configure all the exporters/etc from code inside my python code and it will work, but I would much rather just reuse the existing auto-instrumentation code, either through the binary wrapper as-is, or by calling a python function that does all the setup for me.