Example: Python OpenTelemetrySDK Instrumentation
This guide demonstrates how to use OpenTelemetry SDK to instrument Python code and send traces to TrueFoundry’s OtelCollector.
In this example, we’ll show how to instrument a simple Python application with nested function calls using OpenTelemetry’s context managers.
Create Tracing Project, API Key and copy tracing code
Follow the instructions in Getting Started to create a tracing project, generate API key and copy the tracing code.
Install Dependencies
First, you need to install the following packages:
Add tracing code to Python application
To enable tracing, you’ll need to configure opentelemetry sdk and intialize it. This section shows how to instrument your Python code using OpenTelemetry’s context managers. The example demonstrates nested function calls with proper tracing.
Run your application and view logged trace