Coverage for src/couchers/tracing.py: 61%
18 statements
« prev ^ index » next coverage.py v7.5.0, created at 2024-11-04 02:51 +0000
« prev ^ index » next coverage.py v7.5.0, created at 2024-11-04 02:51 +0000
1from opentelemetry import trace
2from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
3from opentelemetry.instrumentation.grpc import GrpcInstrumentorServer
4from opentelemetry.instrumentation.sqlalchemy import SQLAlchemyInstrumentor
5from opentelemetry.instrumentation.threading import ThreadingInstrumentor
6from opentelemetry.sdk.resources import Resource
7from opentelemetry.sdk.trace import TracerProvider
8from opentelemetry.sdk.trace.export import BatchSpanProcessor
10from couchers.config import config
11from couchers.db import _get_base_engine
14def setup_tracing():
15 if config["OPENTELEMETRY_ENDPOINT"] != "":
16 ThreadingInstrumentor().instrument()
18 grpc_server_instrumentor = GrpcInstrumentorServer()
19 grpc_server_instrumentor.instrument()
20 SQLAlchemyInstrumentor().instrument(engine=_get_base_engine(), enable_commenter=True, commenter_options={})
22 trace.set_tracer_provider(TracerProvider(resource=Resource(attributes={"service.name": "backend"})))
24 trace.get_tracer_provider().add_span_processor(
25 BatchSpanProcessor(OTLPSpanExporter(endpoint=config["OPENTELEMETRY_ENDPOINT"], insecure=True))
26 )