def _make_context_header(
self,
switches=None,
correlation_id=None,
context_extra=None,
):
# Copy the underlying context object, if it was provided
context = dict(self.context.items()) if self.context else {}
# Either add on, reuse or generate a correlation ID
if correlation_id is not None:
context['correlation_id'] = correlation_id
elif 'correlation_id' not in context:
context['correlation_id'] = six.u(uuid.uuid1().hex)
# Switches can come from three different places, so merge them
# and ensure that they are unique
switches = set(switches or [])
if context_extra:
switches |= set(context_extra.pop('switches', []))
context['switches'] = list(set(context.get('switches', [])) | switches)
# Add any extra stuff
if context_extra:
context.update(context_extra)
return context
评论列表
文章目录