frontend/src/container/OnboardingContainer/Modules/APM/Python/md-docs/python.md
Based on your application environment, you can choose the setup below to send traces to SigNoz Cloud.
From VMs, there are two ways to send data to SigNoz Cloud.
Step 1. Install the OpenTelemetry dependencies
pip install opentelemetry-distro==0.38b0
pip install opentelemetry-exporter-otlp==1.17.0
Step 2. Add automatic instrumentation
opentelemetry-bootstrap --action=install
Step 3. Run your application
OTEL_RESOURCE_ATTRIBUTES=service.name={{MYAPP}} \
OTEL_EXPORTER_OTLP_ENDPOINT="https://ingest.{{REGION}}.signoz.cloud:443" \
OTEL_EXPORTER_OTLP_HEADERS="signoz-ingestion-key={{SIGNOZ_INGESTION_KEY}}" \
opentelemetry-instrument <your_run_command>
<your_run_command> can be python3 app.py or flask runNote: Don’t run app in reloader/hot-reload mode as it breaks instrumentation.
OTel Collector binary helps to collect logs, hostmetrics, resource and infra attributes. It is recommended to install Otel Collector binary to collect and send traces to SigNoz cloud. You can correlate signals and have rich contextual data through this way.
You can find instructions to install OTel Collector binary here in your VM. Once you are done setting up your OTel Collector binary, you can follow the below steps for instrumenting your Python application.
Step 1. Install the OpenTelemetry dependencies
pip install opentelemetry-distro==0.38b0
pip install opentelemetry-exporter-otlp==1.17.0
Step 2. Add automatic instrumentation
opentelemetry-bootstrap --action=install
Step 3. To run your application and send data to collector in same VM
OTEL_RESOURCE_ATTRIBUTES=service.name={{MYAPP}} \
OTEL_EXPORTER_OTLP_ENDPOINT="http://localhost:4317" \
OTEL_EXPORTER_OTLP_PROTOCOL=grpc opentelemetry-instrument <your_run_command>
where,
<your_run_command> can be python3 app.py or flask runhttp://localhost:4317 for gRPC exporter and http://localhost:4318 for HTTP exporter.
The port numbers are 4317 and 4318 for the gRPC and HTTP exporters respectively.
In case you have OtelCollector Agent in different VM, replace localhost:4317 with <IP Address of the VM>:4317.
For Python application deployed on Kubernetes, you need to install OTel Collector agent in your k8s infra to collect and send traces to SigNoz Cloud. You can find the instructions to install OTel Collector agent here.
Once you have set up OTel Collector agent, you can proceed with OpenTelemetry Python instrumentation by following the below steps:
Step 1. Install the OpenTelemetry dependencies
pip install opentelemetry-distro==0.38b0
pip install opentelemetry-exporter-otlp==1.17.0
Step 2. Add automatic instrumentation
opentelemetry-bootstrap --action=install
Step 3. Run your application
OTEL_RESOURCE_ATTRIBUTES=service.name={{MYAPP}} \
OTEL_EXPORTER_OTLP_ENDPOINT="http://localhost:4317" \
OTEL_EXPORTER_OTLP_PROTOCOL=grpc opentelemetry-instrument <your_run_command>
where,
<your_run_command> can be python3 app.py or flask runStep 4. Make sure to dockerise your application along with OpenTelemetry instrumentation.