This commit is contained in:
PhanThanhTrung 2024-10-29 14:41:35 +07:00
parent bb48329fee
commit a5bd63df91
2 changed files with 27 additions and 2 deletions

View File

@ -36,4 +36,3 @@ ENV PYTHONPATH="."
ENV TZ="Asia/Ho_Chi_Minh"
CMD [ "sh", "run.sh"]
# ENTRYPOINT [ "sleep", "infinity" ]

View File

@ -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()