quaint-telephone-89068
02/24/2023, 1:46 PMpip 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:
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/pexuser
02/26/2023, 5:36 PM