Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ dependencies = [
"requests",
"pydantic>=2,<3",
"workflows>=3.0",
"opentelemetry-api"
]

[dependency-groups]
Expand Down
14 changes: 14 additions & 0 deletions src/zocalo/service/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@
from importlib.metadata import entry_points

import workflows.recipe
from opentelemetry import trace
from workflows.services.common_service import CommonService


def _extract_dcid(params: dict) -> int | None:
"""Helper method to get dcid. Used for injecting it into current span"""
return params.get("ispyb_dcid") or params.get("dcid")


class Dispatcher(CommonService):
"""
Single point of contact service that takes in job meta-information
Expand Down Expand Up @@ -205,6 +211,14 @@ def process(self, rw, header, message):
recipe_id = parameters.get("guid") or str(uuid.uuid4())
parameters["guid"] = recipe_id

# Extract DCID and set on trace span if OpenTelemetry is available
span = trace.get_current_span()
if span.is_recording():
dcid = _extract_dcid(parameters)
if dcid:
span.set_attribute("dcid", dcid)
self.log.debug(f"Set DCID {dcid} on trace span")

if rw:
# If we received a recipe wrapper then we already have a recipe_ID
# attached to logs. Make a note of the downstream recipe ID so that
Expand Down
Loading