From 90f959223c829d39fdb49206d79f729a21cfa1ed Mon Sep 17 00:00:00 2001 From: PhanThanhTrung Date: Tue, 29 Oct 2024 14:43:48 +0700 Subject: [PATCH] update --- cope2n-api/fwd/opentelemetry_config.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/cope2n-api/fwd/opentelemetry_config.py b/cope2n-api/fwd/opentelemetry_config.py index 50f175f..70e50e5 100644 --- a/cope2n-api/fwd/opentelemetry_config.py +++ b/cope2n-api/fwd/opentelemetry_config.py @@ -11,16 +11,21 @@ from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import BatchSpanProcessor -def setup_tracing(): +def setup_tracing(tracer_endpoint, service_name): # Set up a tracer provider - trace.set_tracer_provider(TracerProvider()) + span_exporter = OTLPSpanExporter(endpoint=f"{tracer_endpoint}/v1/traces") + processor = BatchSpanProcessor(span_exporter=span_exporter) - # Configure the OTLP exporter - otlp_exporter = OTLPSpanExporter(endpoint="http://localhost:4317", insecure=True) + attributes = {SERVICE_NAME: service_name} + resource = Resource(attributes=attributes) + trace_provider = TracerProvider(resource=resource) + trace_provider.add_span_processor(span_processor=processor) + trace.set_tracer_provider(tracer_provider=trace_provider) - # Add a BatchSpanProcessor to handle traces - span_processor = BatchSpanProcessor(otlp_exporter) - trace.get_tracer_provider().add_span_processor(span_processor) + reader = PeriodicExportingMetricReader( + OTLPMetricExporter(endpoint=f"{tracer_endpoint}/v1/metrics")) + meter_provider = MeterProvider(resource=resource, metric_readers=[reader]) + metrics.set_meter_provider(meter_provider=meter_provider) # Instrument Django DjangoInstrumentor().instrument() \ No newline at end of file