|
5 | 5 |
|
6 | 6 | from django.conf import settings
|
7 | 7 | from opentelemetry import trace
|
8 |
| -from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter |
| 8 | +from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import ( |
| 9 | + OTLPSpanExporter as OTLPSpanExporterGrpc, |
| 10 | +) |
| 11 | +from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter |
9 | 12 | from opentelemetry.instrumentation.celery import CeleryInstrumentor
|
10 | 13 | from opentelemetry.instrumentation.django import DjangoInstrumentor
|
11 | 14 | from opentelemetry.instrumentation.psycopg import PsycopgInstrumentor
|
@@ -56,11 +59,18 @@ def configure_opentelemetry() -> Optional[TracerProvider]:
|
56 | 59 | headers = {}
|
57 | 60 |
|
58 | 61 | try:
|
59 |
| - otlp_exporter = OTLPSpanExporter( |
60 |
| - endpoint=otlp_endpoint, |
61 |
| - headers=headers, |
62 |
| - insecure=getattr(settings, "OPENTELEMETRY_INSECURE", True), |
63 |
| - ) |
| 62 | + use_grpc = getattr(settings, "OPENTELEMETRY_USE_GRPC", False) |
| 63 | + if use_grpc: |
| 64 | + otlp_exporter = OTLPSpanExporterGrpc( |
| 65 | + endpoint=otlp_endpoint, |
| 66 | + headers=headers, |
| 67 | + insecure=getattr(settings, "OPENTELEMETRY_INSECURE", True), |
| 68 | + ) |
| 69 | + else: |
| 70 | + otlp_exporter = OTLPSpanExporter( |
| 71 | + endpoint=otlp_endpoint, |
| 72 | + headers=headers, |
| 73 | + ) |
64 | 74 |
|
65 | 75 | tracer_provider.add_span_processor(
|
66 | 76 | BatchSpanProcessor(
|
|
0 commit comments