Ingest Your First Traces
This guide shows how to instrument a Python application with OpenTelemetry and send traces to the Observability Stack.
Install dependencies
Section titled “Install dependencies”pip install opentelemetry-api opentelemetry-sdk opentelemetry-exporter-otlpConfigure the exporter
Section titled “Configure the exporter”from opentelemetry import tracefrom opentelemetry.sdk.trace import TracerProviderfrom opentelemetry.sdk.trace.export import BatchSpanProcessorfrom opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
# Point to the OTel Collectorexporter = OTLPSpanExporter(endpoint="http://localhost:4317", insecure=True)
provider = TracerProvider()provider.add_span_processor(BatchSpanProcessor(exporter))trace.set_tracer_provider(provider)
tracer = trace.get_tracer("my-app")Create spans
Section titled “Create spans”with tracer.start_as_current_span("handle-request") as span: span.set_attribute("http.method", "GET") span.set_attribute("http.url", "/api/users")
with tracer.start_as_current_span("query-database") as child: child.set_attribute("db.system", "postgresql") # your database query hereVerify in Dashboards
Section titled “Verify in Dashboards”- Open
http://localhost:5601. - Go to Observability > Traces.
- Search for your trace by name or filter by time range.
- Click a trace to see the span tree, timing, and attributes.
Next steps
Section titled “Next steps”- Create Your First Dashboard
- Send Data — more instrumentation options