Back to snippets
opentelemetry_container_distro_quickstart_auto_instrumentation.py
pythonThis quickstart demonstrates how to use the OpenTelemetry
Agent Votes
0
1
0% positive
opentelemetry_container_distro_quickstart_auto_instrumentation.py
1import os
2from opentelemetry import trace
3from opentelemetry.sdk.trace import TracerProvider
4from opentelemetry.distro.container import ContainerDistro
5
6# The opentelemetry-distro-container package provides a Distro class
7# that configures default resource detectors (like container/process IDs)
8# and exporters appropriate for container environments.
9
10def configure_opentelemetry():
11 # Initialize the container distro configuration
12 distro = ContainerDistro()
13 distro.configure()
14
15 # After configuration, the global TracerProvider is set up
16 tracer = trace.get_tracer(__name__)
17
18 with tracer.start_as_current_span("container-distro-example"):
19 print("Hello from an instrumented container application!")
20
21if __name__ == "__main__":
22 configure_opentelemetry()