Skip to content

Commit 9e5adb7

Browse files
committed
Moved plugin functionality to python-workflows
1 parent 902a7df commit 9e5adb7

File tree

2 files changed

+38
-29
lines changed

2 files changed

+38
-29
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ OfflineTransport = "workflows.transport.offline_transport:OfflineTransport"
5353
pika = "workflows.util.zocalo.configuration:Pika"
5454
stomp = "workflows.util.zocalo.configuration:Stomp"
5555
transport = "workflows.util.zocalo.configuration:DefaultTransport"
56+
opentelemetry = "workflows.util.zocalo.configuration:OTEL"
5657

5758
[project.scripts]
5859
"workflows.validate_recipe" = "workflows.recipe.validate:main"

src/workflows/services/common_service.py

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import workflows
1919
import workflows.logging
2020
from workflows.transport.middleware.otel_tracing import OTELTracingMiddleware
21-
from workflows.util.zocalo.configuration import OTEL
2221

2322

2423
class Status(enum.Enum):
@@ -193,38 +192,47 @@ def start_transport(self):
193192
self.transport.subscription_callback_set_intercept(
194193
self._transport_interceptor
195194
)
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
208199
)
209200

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+
)
213214

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)
221218

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))
228236

229237
metrics = self._environment.get("metrics")
230238
if metrics:

0 commit comments

Comments
 (0)