<#2065 Pex files do not allow for OpenTelemetry au...
# github-notifications
q
#2065 Pex files do not allow for OpenTelemetry auto-instrumentation Issue created by Peder2911 We are using pantsbuild to set up a developer platform with an emphasis on a nice, frictionless developer experience. A part of this experience is codeless auto-instrumentation such as is provided by Opentelemetry with auto instrumentation. Specifically, we are looking to auto-instrument using the Kubernetes Operator offered by OpenTelemetry. Auto-instrumentation with OpenTelemetry works by monkey-patching libraries, creating passthrough functions that wrap existing functions with logging statements. The way this works is kind of obscure to me, and is something I have to figure out a bit more before I can give constructive input into how to support this. Auto-instrumentation of non-pexified applications can be as easy as running (for example from a clean Python3.9 docker container):
Copy code
pip install flask opentelemetry-distro opentelemetry-instrumentation-flask

cat << EOF > app.py
import flask
app = flask.Flask(__name__)
@app.route("/")
def helloworld():
  return "<h1>Hello world!</h1>"
app.run()
EOF

opentelemetry-instrument \
  --traces_exporter console \
  --metrics_exporter console \
 python app.py
This will spin up a Flask server that also emits telemetry. This separation of code and logging is super useful for maintaining a clean developer experience. This does not work out-of-the-box with Pex, however. Ideally, one would be able to run the following to achieve the same thing:
Copy code
pip install pex opentelemetry-distro opentelemetry-instrumentation-flask

cat << EOF > app.py
import flask
app = flask.Flask(__name__)
@app.route("/")
def helloworld():
  return "Hello from Pex"
app.run()
EOF

pex flask -o app.pex --exe ./app.py
opentelemetry-instrument \
  --metrics_exporter console \
  --traces_exporter console \
  ./app.pex
This does, as expected, not allow OpenTelemetry to inject any instrumentation ,and will not result in any telemetry being emitted. It would be pretty awesome if it did though! I would appreciate any thoughts and ideas for how to implement this. pantsbuild/pex