Skip to content

Ingest Your First Traces

Terminal window
pip install opentelemetry-api opentelemetry-sdk opentelemetry-exporter-otlp
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
exporter = 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")
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 here

For other languages, see Send Data.

  1. Open OpenSearch Dashboards
  2. Navigate to ObservabilityTraces
  3. Search for your trace by name or filter by time range
  4. Click a trace to see the span tree, timing, and attributes