# Python [Languages](README.md) · [Shared configuration](../../common.md) · [Verification](../../verification.md) This example uses Python 3.10 or later and OpenTelemetry Python **1.45.0**. It sends one manual trace to the local [Collector](../../../collector.md). Upstream traces and metrics are Stable; logs are Development as checked on 2026-09-28. The program below configures traces only. ## Install Create a new example directory and virtual environment: ```sh mkdir corridora-python cd corridora-python python3 -m venv .venv . .venv/bin/activate python -m pip install 'opentelemetry-api==1.45.0' \ 'opentelemetry-sdk==1.45.0' \ 'opentelemetry-exporter-otlp-proto-http==1.45.0' ``` Set the exporter endpoint. The HTTP exporter appends `/v1/traces` to this base URL: ```sh export OTEL_EXPORTER_OTLP_ENDPOINT='http://127.0.0.1:4318' unset OTEL_EXPORTER_OTLP_TRACES_ENDPOINT unset OTEL_EXPORTER_OTLP_HEADERS OTEL_EXPORTER_OTLP_TRACES_HEADERS ``` ## Initialize and emit Save as `app.py`: ```python import time from opentelemetry import trace from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter from opentelemetry.sdk.resources import Resource from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import BatchSpanProcessor provider = TracerProvider(resource=Resource.create({ "service.name": "corridora-python", "service.version": "example-1", "deployment.environment.name": "development", })) provider.add_span_processor(BatchSpanProcessor(OTLPSpanExporter())) trace.set_tracer_provider(provider) tracer = trace.get_tracer("corridora.examples.python") try: with tracer.start_as_current_span("example.calculate") as span: span.set_attribute("example.language", "python") time.sleep(0.05) print(f"trace_id={span.get_span_context().trace_id:032x}") finally: provider.shutdown() ``` Run it and keep the printed trace ID: ```sh python app.py python -m pip freeze > requirements.lock.txt ``` In a service, retain one provider for the process and shut it down after requests and background work stop. Do not shut it down after every request. Initialize after worker processes fork when using a process-based application server; each worker needs its own functioning exporter. ## Instrument real work For an existing supported framework, a separate automatic setup can install the distribution and matching instrumentation release: ```sh python -m pip install 'opentelemetry-distro==0.66b0' opentelemetry-bootstrap -a install export OTEL_SERVICE_NAME='my-python-service' export OTEL_EXPORTER_OTLP_PROTOCOL='http/protobuf' export OTEL_TRACES_EXPORTER='otlp' export OTEL_METRICS_EXPORTER='none' export OTEL_LOGS_EXPORTER='none' opentelemetry-instrument python your_application.py ``` Replace the final command with your actual application startup. Bootstrap selects instrumentation for installed libraries; review and lock its resolved dependencies. Do not launch `app.py` above with this wrapper because it already initializes its own provider. `start_as_current_span` makes child work inherit the active context. Supported HTTP instrumentation extracts and injects W3C trace context. For custom transports, use the propagation API at both send and receive boundaries; do not invent a new trace ID in each hop. For correlated logs, emit through an OpenTelemetry logging bridge while the span is current. Python `print()` and the ordinary `logging` module do not become OTLP logs merely because tracing is initialized. Logging instrumentation that injects IDs into formatted text is also distinct from a log exporter. ## Add metrics or logs Metrics require `MeterProvider`, a `PeriodicExportingMetricReader`, and `OTLPMetricExporter` from `opentelemetry.exporter.otlp.proto.http.metric_exporter`. Create instruments through the meter API and close the meter provider at shutdown. Use `/v1/metrics` for a signal-specific endpoint. Logs require the Python logs SDK, an OTLP log exporter, and an application logging bridge. Their Development status means you should pin and test the logging packages together. Share the same resource identity with the tracer provider. This trace sample does not enable either pipeline. ## Direct export and verification For direct Corridora export, replace `OTEL_EXPORTER_OTLP_ENDPOINT` with your HTTPS ingest base URL and set `OTEL_EXPORTER_OTLP_HEADERS="X-CORRIDORA-KEY=${CORRIDORA_INGEST_KEY}"` after securely loading the key as described in [shared configuration](../../common.md). Do not put a signal path in the base variable. The signal-specific variable, if set, overrides it and needs `/v1/traces`. Search Corridora for service `corridora-python` and the printed ID. Expect `example.calculate` lasting roughly 50 milliseconds. If it is absent, check exporter warnings, the actual virtual environment, endpoint overrides, and whether the process reaches `shutdown()`. Then follow [verification](../../verification.md).