25 lines
860 B
Python
25 lines
860 B
Python
# This file is intended for examples exporting traces to a local OTLP listener
|
|
from opentelemetry import trace
|
|
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import (
|
|
OTLPSpanExporter,
|
|
) # noqa
|
|
from opentelemetry.sdk.trace import TracerProvider
|
|
from opentelemetry.sdk.trace.export import (
|
|
ConsoleSpanExporter,
|
|
SimpleSpanProcessor,
|
|
)
|
|
|
|
|
|
def setup_tracing() -> None:
|
|
# Sets the tracer_provider. This is only allowed once per execution
|
|
# context and will log a warning if attempted multiple times.
|
|
trace.set_tracer_provider(TracerProvider())
|
|
trace.get_tracer_provider().add_span_processor(
|
|
SimpleSpanProcessor(
|
|
OTLPSpanExporter(endpoint="http://localhost:4317", insecure=True)
|
|
)
|
|
)
|
|
trace.get_tracer_provider().add_span_processor(
|
|
SimpleSpanProcessor(ConsoleSpanExporter())
|
|
)
|