|
18 | 18 | import workflows |
19 | 19 | import workflows.logging |
20 | 20 | from workflows.transport.middleware.otel_tracing import OTELTracingMiddleware |
21 | | -from workflows.util.zocalo.configuration import OTEL |
22 | 21 |
|
23 | 22 |
|
24 | 23 | class Status(enum.Enum): |
@@ -193,38 +192,47 @@ def start_transport(self): |
193 | 192 | self.transport.subscription_callback_set_intercept( |
194 | 193 | self._transport_interceptor |
195 | 194 | ) |
196 | | - |
197 | | - # Configure OTELTracing if configuration is available |
198 | | - otel_config = ( |
199 | | - OTEL.config if hasattr(OTEL, "config") and OTEL.config else None |
200 | | - ) |
201 | | - |
202 | | - if otel_config: |
203 | | - # Configure OTELTracing |
204 | | - resource = Resource.create( |
205 | | - { |
206 | | - SERVICE_NAME: self._service_name, |
207 | | - } |
| 195 | + try: |
| 196 | + # Configure OTELTracing if configuration is available |
| 197 | + otel_config = ( |
| 198 | + self.config.opentelemetry if self.config and hasattr(self.config, "opentelemetry") else None |
208 | 199 | ) |
209 | 200 |
|
210 | | - self.log.debug("Configuring OTELTracing") |
211 | | - provider = TracerProvider(resource=resource) |
212 | | - trace.set_tracer_provider(provider) |
| 201 | + if otel_config: |
| 202 | + if "endpoint" not in otel_config: |
| 203 | + self.log.warning("Missing required OTEL configuration field `endpoint`.") |
| 204 | + |
| 205 | + if "timeout" not in otel_config: |
| 206 | + self.log.warning("Missing optional OTEL configuration field `timout`. Will default to 10 seconds. ") |
| 207 | + |
| 208 | + # Configure OTELTracing |
| 209 | + resource = Resource.create( |
| 210 | + { |
| 211 | + SERVICE_NAME: self._service_name, |
| 212 | + } |
| 213 | + ) |
213 | 214 |
|
214 | | - # Configure BatchProcessor and OTLPSpanExporter using config values |
215 | | - otlp_exporter = OTLPSpanExporter( |
216 | | - endpoint=otel_config["endpoint"], |
217 | | - timeout=otel_config.get("timeout", 10), |
218 | | - ) |
219 | | - span_processor = BatchSpanProcessor(otlp_exporter) |
220 | | - provider.add_span_processor(span_processor) |
| 215 | + self.log.debug("Configuring OTELTracing") |
| 216 | + provider = TracerProvider(resource=resource) |
| 217 | + trace.set_tracer_provider(provider) |
221 | 218 |
|
222 | | - # Add OTELTracingMiddleware to the transport layer |
223 | | - tracer = trace.get_tracer(__name__) |
224 | | - otel_middleware = OTELTracingMiddleware( |
225 | | - tracer, service_name=self._service_name |
226 | | - ) |
227 | | - self._transport.add_middleware(otel_middleware) |
| 219 | + # Configure BatchProcessor and OTLPSpanExporter using config values |
| 220 | + otlp_exporter = OTLPSpanExporter( |
| 221 | + endpoint=otel_config["endpoint"], |
| 222 | + timeout=otel_config.get("timeout", 10), |
| 223 | + ) |
| 224 | + span_processor = BatchSpanProcessor(otlp_exporter) |
| 225 | + provider.add_span_processor(span_processor) |
| 226 | + |
| 227 | + # Add OTELTracingMiddleware to the transport layer |
| 228 | + tracer = trace.get_tracer(__name__) |
| 229 | + otel_middleware = OTELTracingMiddleware( |
| 230 | + tracer, service_name=self._service_name |
| 231 | + ) |
| 232 | + self._transport.add_middleware(otel_middleware) |
| 233 | + except Exception as e: |
| 234 | + # Continue without tracing if configuration fails |
| 235 | + self.log.warning("Failed to configure OpenTelemetry tracing: %s", str(e)) |
228 | 236 |
|
229 | 237 | metrics = self._environment.get("metrics") |
230 | 238 | if metrics: |
|
0 commit comments