Skip to content

Commit 3a5283a

Browse files
committed
Use plugin configurations to configure connection to OTELCollector
1 parent 0686e28 commit 3a5283a

2 files changed

Lines changed: 41 additions & 14 deletions

File tree

src/workflows/services/common_service.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -193,20 +193,24 @@ def start_transport(self):
193193
self._transport_interceptor
194194
)
195195

196-
# Configure OTELTracing
197-
resource = Resource.create({
198-
SERVICE_NAME: self._service_name,
199-
})
200-
201-
self.log.debug("Configuring OTELTracing")
202-
provider = TracerProvider(resource=resource)
203-
trace.set_tracer_provider(provider)
204-
205-
# Configure BatchProcessor and OTLPSpanExporter to point to OTELCollector
206-
otlp_exporter = OTLPSpanExporter(
207-
endpoint="https://otel.tracing.diamond.ac.uk:4318/v1/traces",
208-
timeout=10
209-
)
196+
# Configure OTELTracing if configuration is available
197+
otel_config = OTEL.config if hasattr(OTEL, 'config') and OTEL.config else None
198+
199+
if otel_config:
200+
# Configure OTELTracing
201+
resource = Resource.create({
202+
SERVICE_NAME: self._service_name,
203+
})
204+
205+
self.log.debug("Configuring OTELTracing")
206+
provider = TracerProvider(resource=resource)
207+
trace.set_tracer_provider(provider)
208+
209+
# Configure BatchProcessor and OTLPSpanExporter using config values
210+
otlp_exporter = OTLPSpanExporter(
211+
endpoint=otel_config["endpoint"],
212+
timeout=otel_config.get("timeout", 10)
213+
)
210214
span_processor = BatchSpanProcessor(otlp_exporter)
211215
provider.add_span_processor(span_processor)
212216

src/workflows/util/zocalo/configuration.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,29 @@
77
from workflows.transport.pika_transport import PikaTransport
88
from workflows.transport.stomp_transport import StompTransport
99

10+
class OTEL:
11+
"""A Zocalo configuration plugin to pre-populate OTELTracing config defaults"""
12+
13+
class Schema(PluginSchema):
14+
host = fields.Str(required=True)
15+
port = fields.Int(required=True)
16+
endpoint = fields.Str(required=False)
17+
timeout = fields.Int(required=False, load_default=10)
18+
19+
# Store configuration for access by services
20+
config = {}
21+
22+
@staticmethod
23+
def activate(configuration):
24+
# Build the full endpoint URL if not provided
25+
if "endpoint" not in configuration:
26+
endpoint = f"https://{configuration['host']}:{configuration['port']}/v1/traces"
27+
else:
28+
endpoint = configuration["endpoint"]
29+
30+
OTEL.config["endpoint"] = endpoint
31+
OTEL.config["timeout"] = configuration.get("timeout", 10)
32+
1033

1134
class Stomp:
1235
"""A Zocalo configuration plugin to pre-populate StompTransport config defaults"""

0 commit comments

Comments
 (0)