From the course: Mastering Observability with OpenTelemetry

Unlock the full course today

Join today to access over 24,400 courses taught by industry experts.

Instrumenting Python for tracing

Instrumenting Python for tracing

- [Instructor] In this video, we will be instrumenting our Python services. Let's open the folder for the Python gateway. As with Node.js, the Python service already contains all the dependencies that we will need throughout this course. They are in the file requirements.txt, and we installed them when we created the virtual environment. Compared to Node, Python needs slightly more direct code changes. So let's get to it. For that, I'm opening the app.py file. And there you see that this is a Flask application, so that's a framework similar to Express. And now we have to add the instrumentation for Flask to this file. And for that, I just start typing right below, I'm importing Flask. And let's also close the left menu bar. From opentelemetry, and intelligence should help you here, .instrumentation.flask, import FlaskInstrumentor. So now we have imported the Instrumentor. Now we have to apply it to our instance of the Flask app, and we can do this in line six, right after the instance…

Contents