Skip to content

Commit 0d4d825

Browse files
committed
simplified logic for log context and corrected self.config.opentelemetry to self.config._opentelemetry
1 parent 5aae712 commit 0d4d825

File tree

2 files changed

+10
-24
lines changed

2 files changed

+10
-24
lines changed

src/workflows/recipe/__init__.py

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -74,47 +74,33 @@ def unwrap_recipe(header, message):
7474

7575
rw = RecipeWrapper(message=message, transport=transport_layer)
7676

77-
if hasattr(rw, "environment") and rw.environment.get("ID"):
77+
if log_extender and rw.environment["ID"]:
7878
# Extract recipe ID from environment and add to current span
7979
span = trace.get_current_span()
80-
recipe_id = rw.environment.get("ID")
81-
82-
if recipe_id:
83-
span.set_attribute("recipe_id", recipe_id)
80+
recipe_id = rw.environment["ID"]
81+
span.set_attribute("recipe_id", recipe_id)
8482

8583
# Extract span_id and trace_id for logging
8684
span_context = span.get_span_context()
8785
otel_logs = None
88-
if span_context and span_context.is_valid:
86+
if span_context.is_valid:
8987
span_id = span_context.span_id
9088
trace_id = span_context.trace_id
9189

9290
otel_logs = {
9391
"span_id": span_id,
9492
"trace_id": trace_id,
93+
"recipe_id": recipe_id
9594
}
9695

97-
if recipe_id:
98-
otel_logs["recipe_id"] = recipe_id
99-
10096
with ExitStack() as stack:
10197

10298
# Configure the context depending on if service is emitting spans
103-
if (
104-
otel_logs
105-
and log_extender
106-
and rw.environment
107-
and rw.environment.get("ID")
108-
):
109-
stack.enter_context(
110-
log_extender("recipe_ID", rw.environment.get("ID"))
111-
)
99+
stack.enter_context(
100+
log_extender("recipe_ID", recipe_id)
101+
)
102+
if otel_logs:
112103
stack.enter_context(log_extender("otel_logs", otel_logs))
113-
elif log_extender and rw.environment and rw.environment.get("ID"):
114-
stack.enter_context(
115-
log_extender("recipe_ID", rw.environment.get("ID"))
116-
)
117-
118104
return callback(rw, header, message.get("payload"))
119105

120106
return callback(rw, header, message.get("payload"))

src/workflows/services/common_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def start_transport(self):
196196
# Configure OTELTracing if configuration is available
197197
otel_config = (
198198
self.config._opentelemetry
199-
if self.config and hasattr(self.config, "opentelemetry")
199+
if self.config and hasattr(self.config, "_opentelemetry")
200200
else None
201201
)
202202
if otel_config:

0 commit comments

Comments
 (0)