{"slug": "auto-instrumentation-of-python-applications-with-opentelemetry", "title": "Auto-instrumentation of Python applications with OpenTelemetry", "summary": "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.", "body_md": "# Auto-instrumentation of Python applications with OpenTelemetry\n\nThis article is part of the **OpenTelemetry Python series**:\n\n- Previous Article:\n[Setting up SigNoz](https://signoz.io/opentelemetry/setting-up-signoz/) **You are here:** Auto-instrumentation of Python applications with OpenTelemetry- Next Article:\n[Manually configuring agent for instrumenting Python applications](https://signoz.io/opentelemetry/manually-configuring-opentelemetry-agent/)\n\nCheck out the complete series at: [Overview - Implementing OpenTelemetry in Python applications](https://signoz.io/opentelemetry/python-overview/)\n\nIn the [previous tutorial](https://signoz.io/opentelemetry/setting-up-signoz/), we set up SigNoz to send the data collected by OpenTelemetry to it.\n\nIn 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.\n\nInstrumenting Flask application\n\nGetting started with OpenTelemetry is as simple as prefixing your application command with `opentelemetry-instrument`\n\n. For example, if you start your application with `python app.py`\n\nthen run (with your desired settings in place of the example environment variables):\n\n```\nopentelemetry-instrument python app.py\n```\n\n[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.\n\nCode for this tutorial: [GitHub Repo Link](https://github.com/SigNoz/opentelemetry-python-example/tree/main/lesson-3-1)\n\nStep 1: Install Distro Package\n\nFirst, we need to install the *distro* package with the OTLP exporter. Run the following command to install.\n\n```\npython -m pip install 'opentelemetry-distro[otlp]'==0.45b0\n```\n\nOr alternatively, you can add `opentelemetry-distro[otlp]==0.45b0`\n\nto your `requirements.txt`\n\nfile and run:\n\n```\npython -m pip install -r requirements.txt\n```\n\nThis package includes the [OpenTelemetry SDK](https://signoz.io/comparisons/opentelemetry-api-vs-sdk/), the OTLP exporter, and the necessary libraries.\n\nStep 2: Use `opentelemetry-bootstrap`\n\nfor Auto-Instrumentation\n\nWith the distro package installed, we can use the `opentelemetry-bootstrap`\n\ntool to automatically install the required instrumentation libraries for our application. This tool inspects the environment and detects the frameworks and libraries installed.\n\nIt 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`\n\npackage (as long as the version is supported).\n\nRun the following command to install the required instrumentation packages:\n\n```\nopentelemetry-bootstrap --action=install\n```\n\nTo verify that the required instrumentation packages are installed, run the following command and make sure you see the `opentelemetry-instrumentation-*`\n\nfor Flask and other libraries:\n\n```\npython -m pip list | grep \"opentelemetry-instrumentation\"\n```\n\nStep 3: Configure OpenTelemetry to Send Data to SigNoz Cloud\n\nTo send data to SigNoz Cloud, set up the environment variables and define the SigNoz Cloud endpoint, region, and authentication headers.\n\nObtain SigNoz Ingestion Key\n\nBefore configuring OpenTelemetry, ensure you have the following information from SigNoz Cloud:\n\n- Region: The SigNoz Cloud region you're using.\n- Ingestion Key: The ingestion key for sending traces to SigNoz Cloud.\n\nYou can get it from `Ingestion Settings`\n\nunder `Settings`\n\nas described in the previous article.\n\nEnvironment Variables\n\nSet environment variables to configure OpenTelemetry to send traces to SigNoz Cloud:\n\n```\n# Set the service name, SigNoz endpoint, and authentication token\nOTEL_RESOURCE_ATTRIBUTES=service.name=<service_name> \\\nOTEL_EXPORTER_OTLP_ENDPOINT=\"https://ingest.{region}.signoz.cloud:443\" \\\nOTEL_EXPORTER_OTLP_HEADERS=\"signoz-ingestion-key=<SIGNOZ_INGESTION_KEY>\" \\\nOTEL_EXPORTER_OTLP_PROTOCOL=grpc \\\nOTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true\n```\n\nReplace `{region}`\n\nwith the SigNoz Cloud region, `<service_name>`\n\nwith the desired name for your service, and `<SIGNOZ_INGESTION_KEY>`\n\nwith your SigNoz Ingestion Key.\n\nRun application\n\nWith the correct environment variables, start service with OpenTelemetry instrumentation:\n\n```\nOTEL_RESOURCE_ATTRIBUTES=service.name=my-application \\\nOTEL_EXPORTER_OTLP_ENDPOINT=\"https://ingest.{region}.signoz.cloud:443\" \\\nOTEL_EXPORTER_OTLP_HEADERS=\"signoz-ingestion-key=<SIGNOZ_INGESTION_KEY>\" \\\nOTEL_EXPORTER_OTLP_PROTOCOL=grpc \\\nOTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true \\\nopentelemetry-instrument python lesson-3-1/app.py\n```\n\nStep 4: Test the Application and Generate Trace Data\n\nInteract with the Flask application to generate tracing data and send it to SigNoz Cloud.\n\nStep 5: See Trace Data in SigNoz\n\nOnce you've created some dummy telemetry by interacting with your application, you will be able to find your application under the `Services`\n\ntab of SigNoz.\n\nYou can click on the application to see useful application metrics like latency, requests rates, error rates, [apdex score](https://signoz.io/docs/alerts-management/apdex-alerts/), key operations, etc. This is very powerful considering auto-instrumentation with OpenTelemetry required no code changes at all.\n\nAdditional: Troubleshooting if you can’t see data in SigNoz\n\n- Make sure that the environment variables are set correctly.\n- Verify if the instrumentation is working using the console exporter. Add the following environment variables to export traces to the console. The modified command should look like this:\n\n```\nOTEL_RESOURCE_ATTRIBUTES=service.name=my-application \\\nOTEL_EXPORTER_OTLP_ENDPOINT=\"https://ingest.{region}.signoz.cloud:443\" \\\nOTEL_EXPORTER_OTLP_HEADERS=\"signoz-ingestion-key=<SIGNOZ_INGESTION_KEY>\" \\\nOTEL_EXPORTER_OTLP_PROTOCOL=grpc \\\nOTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true \\\nOTEL_TRACES_EXPORTER=console \\\nOTEL_METRICS_EXPORTER=console \\\nOTEL_LOGS_EXPORTER=console \\\nopentelemetry-instrument python lesson-3-1/app.py\n```\n\nThis command will export traces, metrics, and logs to the console. If you don't see data in the console, there might be an issue with the instrumentation.\n\nPlease check the version compatibility of the instrumentation libraries. However, if you see data in the console, the issue might be with network connectivity or the SigNoz Cloud.\n\n- Check the logs for any errors or warnings. The logs can provide more information about what's going wrong. If you see errors related to the export, check the network connectivity.\n- If you still can't see data in SigNoz, reach out to the SigNoz support team for assistance.\n\nNext Steps\n\nIn this tutorial, we set up auto-instrumentation for our Flask app with OpenTelemetry. Implementing tracing/metrics/logs with OpenTelemetry is easy as it involves no code changes.\n\nIn the next lesson, we will manually configure the agent to instrument our application.\n\nRead Next Article of OpenTelemetry Python series on [Manually configuring agent for instrumenting Python applications](https://signoz.io/opentelemetry/manually-configuring-opentelemetry-agent/)", "url": "https://wpnews.pro/news/auto-instrumentation-of-python-applications-with-opentelemetry", "canonical_source": "https://signoz.io/opentelemetry/python-auto-instrumentation", "published_at": "2026-06-16 00:00:00+00:00", "updated_at": "2026-06-17 13:25:07.616617+00:00", "lang": "en", "topics": ["developer-tools"], "entities": ["SigNoz", "OpenTelemetry", "Flask", "Python"], "alternates": {"html": "https://wpnews.pro/news/auto-instrumentation-of-python-applications-with-opentelemetry", "markdown": "https://wpnews.pro/news/auto-instrumentation-of-python-applications-with-opentelemetry.md", "text": "https://wpnews.pro/news/auto-instrumentation-of-python-applications-with-opentelemetry.txt", "jsonld": "https://wpnews.pro/news/auto-instrumentation-of-python-applications-with-opentelemetry.jsonld"}}