Auto-instrumentation of Python applications with OpenTelemetry SigNoz released a tutorial on auto-instrumenting Python applications with OpenTelemetry, enabling automatic collection of traces, metrics, and logs without code changes. The guide covers installing the distro package, using opentelemetry-bootstrap for auto-instrumentation, and configuring OpenTelemetry to send data to SigNoz Cloud. This simplifies observability setup for Python developers. Auto-instrumentation of Python applications with OpenTelemetry This article is part of the OpenTelemetry Python series : - Previous Article: Setting up SigNoz https://signoz.io/opentelemetry/setting-up-signoz/ You are here: Auto-instrumentation of Python applications with OpenTelemetry- Next Article: Manually configuring agent for instrumenting Python applications https://signoz.io/opentelemetry/manually-configuring-opentelemetry-agent/ Check out the complete series at: Overview - Implementing OpenTelemetry in Python applications https://signoz.io/opentelemetry/python-overview/ In the previous tutorial https://signoz.io/opentelemetry/setting-up-signoz/ , we set up SigNoz to send the data collected by OpenTelemetry to it. In this tutorial, we will set up automatic traces, metrics, and logs collection in our Flask application with OpenTelemetry https://signoz.io/opentelemetry/ . We will use auto-instrumentation tools to set everything up for us. With auto-instrumentation, you can configure your Python application to collect telemetry without any changes in the application code. Instrumenting Flask application Getting started with OpenTelemetry is as simple as prefixing your application command with opentelemetry-instrument . For example, if you start your application with python app.py then run with your desired settings in place of the example environment variables : opentelemetry-instrument python app.py Automatic instrumentation https://signoz.io/blog/opentelemetry-auto-instrumentation/ will generate telemetry data for the most common use cases, such as HTTP requests, database queries, and other common operations. Code for this tutorial: GitHub Repo Link https://github.com/SigNoz/opentelemetry-python-example/tree/main/lesson-3-1 Step 1: Install Distro Package First, we need to install the distro package with the OTLP exporter. Run the following command to install. python -m pip install 'opentelemetry-distro otlp '==0.45b0 Or alternatively, you can add opentelemetry-distro otlp ==0.45b0 to your requirements.txt file and run: python -m pip install -r requirements.txt This package includes the OpenTelemetry SDK https://signoz.io/comparisons/opentelemetry-api-vs-sdk/ , the OTLP exporter, and the necessary libraries. Step 2: Use opentelemetry-bootstrap for Auto-Instrumentation With the distro package installed, we can use the opentelemetry-bootstrap tool to automatically install the required instrumentation libraries for our application. This tool inspects the environment and detects the frameworks and libraries installed. It then finds and installs the appropriate instrumentation libraries, ensuring comprehensive auto-instrumentation. For example, if you have Flask installed, it will install the opentelemetry-instrumentation-flask package as long as the version is supported . Run the following command to install the required instrumentation packages: opentelemetry-bootstrap --action=install To verify that the required instrumentation packages are installed, run the following command and make sure you see the opentelemetry-instrumentation- for Flask and other libraries: python -m pip list | grep "opentelemetry-instrumentation" Step 3: Configure OpenTelemetry to Send Data to SigNoz Cloud To send data to SigNoz Cloud, set up the environment variables and define the SigNoz Cloud endpoint, region, and authentication headers. Obtain SigNoz Ingestion Key Before configuring OpenTelemetry, ensure you have the following information from SigNoz Cloud: - Region: The SigNoz Cloud region you're using. - Ingestion Key: The ingestion key for sending traces to SigNoz Cloud. You can get it from Ingestion Settings under Settings as described in the previous article. Environment Variables Set environment variables to configure OpenTelemetry to send traces to SigNoz Cloud: Set the service name, SigNoz endpoint, and authentication token OTEL RESOURCE ATTRIBUTES=service.name=