Core Concepts
- TracesRequest flow
- MetricsMeasurements
- LogsEvent records
- ContextPropagation
- ResourceService metadata
- BaggageCross-service data
Trace Components
- SpanSingle operation
- Trace IDRequest identifier
- Span IDOperation identifier
- Parent Span IDParent reference
- AttributesKey-value metadata
- EventsTimestamped logs
Metric Types
- CounterCumulative sum
- UpDownCounterIncrease/decrease
- GaugeCurrent value
- HistogramValue distribution
Collector Components
- ReceiversData ingestion
- ProcessorsData transformation
- ExportersData output
- ExtensionsHealth, pprof
Python SDK Example
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
# Setup
provider = TracerProvider()
processor = BatchSpanProcessor(OTLPSpanExporter())
provider.add_span_processor(processor)
trace.set_tracer_provider(provider)
# Create spans
tracer = trace.get_tracer("my-service")
with tracer.start_as_current_span("my-operation") as span:
span.set_attribute("http.method", "GET")
Collector Config (otel-collector.yaml)
receivers:
otlp:
protocols:
grpc:
endpoint: "0.0.0.0:4317"
http:
endpoint: "0.0.0.0:4318"
processors:
batch:
timeout: 1s
exporters:
jaeger:
endpoint: "jaeger:14250"
prometheus:
endpoint: "0.0.0.0:8889"
service:
pipelines:
traces:
receivers: [otlp]
processors: [batch]
exporters: [jaeger]
SDK Components
- TracerProviderCreates tracers
- MeterProviderCreates meters
- LoggerProviderCreates loggers
- SpanProcessorProcess spans
- SpanExporterExport spans
Span Kinds
- INTERNALInternal operation
- SERVERServer-side request
- CLIENTClient-side request
- PRODUCERMessage producer
- CONSUMERMessage consumer
Environment Variables
# Service identification
OTEL_SERVICE_NAME="my-service"
OTEL_RESOURCE_ATTRIBUTES="deployment.environment=production"
# Exporter configuration
OTEL_EXPORTER_OTLP_ENDPOINT="http://collector:4317"
OTEL_EXPORTER_OTLP_PROTOCOL="grpc"
# Trace sampling
OTEL_TRACES_SAMPLER="parentbased_traceidratio"
OTEL_TRACES_SAMPLER_ARG="0.1"
Semantic Conventions
- http.methodHTTP method
- http.urlRequest URL
- http.status_codeResponse code
- db.systemDatabase type
- db.statementQuery string
Popular Exporters
- OTLPOpenTelemetry Protocol
- JaegerDistributed tracing
- ZipkinDistributed tracing
- PrometheusMetrics