From a5bd63df911eb83eb8f3a55591072cbec8c90360 Mon Sep 17 00:00:00 2001 From: PhanThanhTrung Date: Tue, 29 Oct 2024 14:41:35 +0700 Subject: [PATCH] update --- cope2n-ai-fi/Dockerfile | 3 +-- cope2n-api/fwd/opentelemetry_config.py | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 cope2n-api/fwd/opentelemetry_config.py diff --git a/cope2n-ai-fi/Dockerfile b/cope2n-ai-fi/Dockerfile index 3cebda1..beb113b 100755 --- a/cope2n-ai-fi/Dockerfile +++ b/cope2n-ai-fi/Dockerfile @@ -35,5 +35,4 @@ WORKDIR /workspace ENV PYTHONPATH="." ENV TZ="Asia/Ho_Chi_Minh" -CMD [ "sh", "run.sh"] -# ENTRYPOINT [ "sleep", "infinity" ] \ No newline at end of file +CMD [ "sh", "run.sh"] \ No newline at end of file diff --git a/cope2n-api/fwd/opentelemetry_config.py b/cope2n-api/fwd/opentelemetry_config.py new file mode 100644 index 0000000..50f175f --- /dev/null +++ b/cope2n-api/fwd/opentelemetry_config.py @@ -0,0 +1,26 @@ +from opentelemetry import metrics, trace +from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import \ + OTLPSpanExporter +from opentelemetry.exporter.otlp.proto.http.metric_exporter import \ + OTLPMetricExporter +from opentelemetry.instrumentation.django import DjangoInstrumentor +from opentelemetry.sdk.metrics import MeterProvider +from opentelemetry.sdk.metrics.export import PeriodicExportingMetricReader +from opentelemetry.sdk.resources import SERVICE_NAME, Resource +from opentelemetry.sdk.trace import TracerProvider +from opentelemetry.sdk.trace.export import BatchSpanProcessor + + +def setup_tracing(): + # Set up a tracer provider + trace.set_tracer_provider(TracerProvider()) + + # Configure the OTLP exporter + otlp_exporter = OTLPSpanExporter(endpoint="http://localhost:4317", insecure=True) + + # Add a BatchSpanProcessor to handle traces + span_processor = BatchSpanProcessor(otlp_exporter) + trace.get_tracer_provider().add_span_processor(span_processor) + + # Instrument Django + DjangoInstrumentor().instrument() \ No newline at end of file