Skip to content

Commit a2974f3

Browse files
committed
bugsnag: propagate cloud_provider into contextual logging for queued executions
Adds CLOUD_PROVIDER_ANNOTATION_KEY to common_annotations so the annotation key has a single definition in the OSS layer. In the queued-execution processing span, reads the cloud_provider value from task_spec annotations (already in memory) and adds it to the contextual logging context when present. The existing _before_notify hook then includes it automatically in the tangle_context tab on every Bugsnag event raised during that execution's processing.
1 parent 4730f88 commit a2974f3

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

cloud_pipelines_backend/instrumentation/contextual_logging.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,14 @@
2222
"""
2323

2424
import contextvars
25+
import typing
2526
from contextlib import contextmanager
2627
from typing import Any, Optional
2728

29+
from .. import backend_types_sql as bts
30+
31+
_CLOUD_PROVIDER_ANNOTATION_KEY = "cloud-pipelines.net/orchestration/cloud_provider"
32+
2833
# Single context variable to store all metadata as a dictionary
2934
_context_metadata: contextvars.ContextVar[dict[str, Any]] = contextvars.ContextVar(
3035
"context_metadata", default={}
@@ -125,3 +130,21 @@ def logging_context(**metadata: Any):
125130
finally:
126131
# Restore previous metadata
127132
_context_metadata.set(prev_metadata)
133+
134+
135+
def execution_logging_context(execution: bts.ExecutionNode):
136+
"""Return a logging context populated with metadata for *execution*.
137+
138+
Always sets ``execution_id``. Also sets ``cloud_provider`` when the
139+
``cloud-pipelines.net/orchestration/cloud_provider`` annotation is present
140+
on the task spec.
141+
"""
142+
ctx: dict[str, typing.Any] = {"execution_id": execution.id}
143+
cloud_provider = (
144+
(execution.task_spec or {})
145+
.get("annotations", {})
146+
.get(_CLOUD_PROVIDER_ANNOTATION_KEY)
147+
)
148+
if cloud_provider is not None:
149+
ctx["cloud_provider"] = cloud_provider
150+
return logging_context(**ctx)

cloud_pipelines_backend/orchestrator_sql.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def internal_process_queued_executions_queue(self, session: orm.Session):
131131
self._queued_executions_queue_idle = False
132132
start_timestamp = time.monotonic_ns()
133133

134-
with contextual_logging.logging_context(execution_id=queued_execution.id):
134+
with contextual_logging.execution_logging_context(queued_execution):
135135
_logger.info("Before processing queued execution")
136136
try:
137137
self.internal_process_one_queued_execution(

0 commit comments

Comments
 (0)