Skip to main content

OpenTelemetry

Log

{
"_timestamp": 1757579545084764,
"body": "Starting #0",
"code_file_path": "/app/main.py",
"code_function_name": "lifespan",
"code_line_number": 67,
"deployment_environment": "production",
"dropped_attributes_count": 0,
"instrumentation_library_name": "app.main",
"service_name": "api",
"service_namespace": "app",
"service_version": "1.0.0",
"severity": "INFO",
"telemetry_sdk_language": "python",
"telemetry_sdk_name": "opentelemetry",
"telemetry_sdk_version": "1.36.0"
}

环境变量

envdemofor
OTEL_RESOURCE_ATTRIBUTES
OTEL_SERVICE_NAMEservice.name
OTEL_LOG_LEVEL
OTEL_PROPAGATORS
OTEL_TRACES_SAMPLER
OTEL_EXPORTER_OTLP_ENDPOINThttp://localhost:4318
OTEL_EXPORTER_OTLP_TRACES_ENDPOINThttp://localhost:4318/v1/traces
OTEL_EXPORTER_OTLP_METRICS_ENDPOINThttp://my-api-endpoint/v1/metrics
OTEL_EXPORTER_OTLP_LOGS_ENDPOINThttp://my-api-endpoint/v1/logs
OTEL_EXPORTER_OTLP_HEADERS
OTEL_EXPORTER_OTLP_{TRACES,METRICS,LOGS}_HEADERS
OTEL_EXPORTER_OTLP_TIMEOUT
OTEL_EXPORTER_OTLP_{TRACES,METRICS,LOGS}_TIMEOUT
OTEL_EXPORTER_OTLP_PROTOCOLgrpcgrpc,http/protobuf,http/json
OTEL_EXPORTER_OTLP_*_PROTOCOL
OTEL_SDK_DISABLED
OTEL_TRACES_EXPORTERotlp
OTEL_METRICS_EXPORTERotlp
OTEL_LOGS_EXPORTERotlp
TRACEPARENT一般用于 IPC
TRACESTATE一般配合 TRACEPARENT
  • OTEL_TRACES_EXPORTER - otlp, zipkin, console, logging, none
  • OTEL_METRICS_EXPORTER - otlp, prometheus, console, none
  • OTEL_LOGS_EXPORTER - otlp, console, logging, none
  • OTEL_{LANGUAGE}_{FEATURE}
OTEL_PROPAGATORSDescription
tracecontextW3C Trace Context
baggageW3C Baggage
b3B3 Single
b3multiB3 Multi
jaegerJaeger
xrayAWS X-Ray
ottraceOT Trace
noneNo automatically configured propagator.
OTEL_TRACES_SAMPLERDescription
always_onAlwaysOnSampler
always_offAlwaysOffSampler
traceidratioTraceIdRatioBased
parentbased_always_onParentBased(root=AlwaysOnSampler)
parentbased_always_offParentBased(root=AlwaysOffSampler)
parentbased_traceidratioParentBased(root=TraceIdRatioBased)
parentbased_jaeger_remoteParentBased(root=JaegerRemoteSampler)
jaeger_remoteJaegerRemoteSampler
xrayAWS X-Ray Centralized Sampling (third party)