in src/Backend/src/api/tracing.py [0:0]
def load_baggage(self, context: Context | None = None) -> None:
"""
Load the baggage from the given context.
"""
trace_id = typing.cast(
str | None,
baggage.get_baggage(TRACE_ID_BAGGAGE_KEY, context=context),
)
if trace_id:
# value present in received baggage, so we already propagated values before,
# keep that as correlation id, then use the current request id
request_id = self._get_current_request_id()
else:
# value not present in received baggage, we've propagated no values yet,
# this is the first entry point, use trace id as correlation and request id
trace_id = request_id = self.get_trace_id()
# causation taken from baggage if present, otherwise current request id itself
causation_request_id = (
typing.cast(
str | None,
baggage.get_baggage(CAUSATION_REQ_ID_BAGGAGE_KEY, context=context),
)
or request_id
)
self._set_current_tracing_values(
request_id=request_id,
trace_id=trace_id,
causation_request_id=causation_request_id,
)
# set new values in the baggage context for other distributed systems to use
attach(baggage.set_baggage(TRACE_ID_BAGGAGE_KEY, trace_id))
attach(baggage.set_baggage(CAUSATION_REQ_ID_BAGGAGE_KEY, request_id))