Where spans go
tracing.init() configures an OTLP/HTTP exporter pointed at Surface Area. The exporter authenticates with HTTP Basic auth built from your public and secret keys, so the same three variables that connect the SDK also authorize the export.
When
GATEWAY_OTLP_ENDPOINT is not set, the endpoint is derived from the host by appending /api/public/otel/v1/traces. A host of https://withgateway.ai exports to https://withgateway.ai/api/public/otel/v1/traces.
All three of
GATEWAY_HOST, GATEWAY_PUBLIC_KEY, and GATEWAY_SECRET_KEY must be present for the exporter to configure. If any is missing, init() logs that no exporter was configured and spans are not persisted. Run with debug="INFO" to see the export status.Override the endpoint
Point at a different ingestion URL with thegateway_endpoint parameter (or GATEWAY_OTLP_ENDPOINT). The override replaces the derived path entirely.
Spans are batched in the background
The exporter buffers spans and sends them in batches, so individual spans do not each make a network call. Tune the batching at init when the defaults do not fit your workload.Buffered spans reach the dashboard within the flush interval, or immediately after a
flush() or shutdown() call.Flush before exit
Calltracing.shutdown() before the process exits so the buffer drains. Register it with atexit:
tracing.flush() to drain the buffer at a checkpoint without ending the tracing session. It returns True when the flush completes and False if it times out.
A short-lived script that exits without
shutdown() can drop its last spans, because they are still buffered when the process ends. Always flush or shut down before exit.Send custom exporters alongside Surface Area
Pass your own OpenTelemetrySpanExporter instances to init(exporters=[...]) to send spans to another backend. Custom exporters replace the auto-configured Surface Area exporter, so include a Surface Area exporter explicitly when you still want spans in Surface Area.
Where to go next
- Instrument an agent: produce the spans that get exported.
- Auto-instrumentation: the library calls Surface Area exports for you.
- Metadata & identity: the attributes that ride along on every exported span.