Skip to content

Instantly share code, notes, and snippets.

@pridhi-arora
Last active February 20, 2023 13:33
Show Gist options
  • Save pridhi-arora/4a97d6403cc8fa582b636d00bdb832a9 to your computer and use it in GitHub Desktop.
Save pridhi-arora/4a97d6403cc8fa582b636d00bdb832a9 to your computer and use it in GitHub Desktop.
opentelemetry Outreachy
Things to read:
grpc: https://grpc.io/docs/what-is-grpc/core-concepts/
https://opentelemetry.io/docs/instrumentation/python/
@pridhi-arora
Copy link
Author

I tried to set up and get tracing telemetry from an HTTP server with Flask. For this, I installed flask and opentelemetry-distro package after this created the HTTP server with the /rolldice route. The code for the same is

from random import randint
from flask import Flask, request

app = Flask(__name__)

@app.route("/rolldice")
def roll_dice():
    return str(do_roll())

def do_roll():
    return randint(1, 6)

But I failed to run this. So, I added the following lines to the end of code

if __name__ == " __main__ " :
    app.run()

After this, I installed flask instrumentation
opentelemetry-bootstrap -a install
For running the instrumented app :

opentelemetry-instrument \
    --traces_exporter console \
    --metrics_exporter console \
    flask run

After sending a request to the server we now get a trace with a span in the console.

@pridhi-arora
Copy link
Author

typed-ast error, switch to python 3.9 for all the errors.

@pridhi-arora
Copy link
Author

pridhi-arora commented Feb 20, 2023

Also, use tox from the development version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment