def inject(self, span_context, format, carrier): """Inject `span_context` into `carrier`. The type of `carrier` is determined by `format`. See the :class:`Format` class/namespace for the built-in OpenTracing formats. Implementations *must* raise :exc:`UnsupportedFormatException` if `format` is unknown or disallowed. :param span_context: the :class:`SpanContext` instance to inject :type span_context: SpanContext :param format: a python object instance that represents a given carrier format. `format` may be of any type, and `format` equality is defined by python ``==`` equality. :type format: Format :param carrier: the format-specific carrier object to inject into """ propagator = self.registry.get(format) if not propagator: raise opentracing.UnsupportedFormatException( 'Invalid format ' + str(format)) if isinstance(span_context, WavefrontSpan): # be flexible and allow Span as argument, not only SpanContext span_context = span_context.context if not isinstance(span_context, WavefrontSpanContext): raise TypeError( 'Expecting WavefrontSpanContext, not ' + type(span_context)) propagator.inject(span_context, carrier)
def extract(self, format, carrier): if format != opentracing.Format.HTTP_HEADERS and isinstance( carrier, dict): raise opentracing.UnsupportedFormatException(format) if 'span-identity' not in carrier: raise opentracing.SpanContextCorruptedException return _SpanContext(int(carrier['span-identity']))
def inject(self, span_context, format, carrier): """ inject span context into a carrier :param span_context: :param format: :param carrier: :return: """ if format != opentracing.Format.TEXT_MAP: raise opentracing.UnsupportedFormatException() for k, v in span_context.baggage.items(): carrier[self._prefix + k] = str(v) return carrier
def extract(self, format, carrier): """Return a :class:`SpanContext` instance extracted from a `carrier`. :param format: a python object instance that represents a given carrier format. `format` may be of any type, and `format` equality is defined by python ``==`` equality. :type format: opentracing.Format :param carrier: the format-specific carrier object to extract from :type carrier: dict :return: a :class:`SpanContext` extracted from `carrier` or ``None`` if no such :class:`SpanContext` could be found. :rtype: SpanContext """ propagator = self.registry.get(format) if not propagator: raise opentracing.UnsupportedFormatException( 'Invalid format ' + str(format)) return propagator.extract(carrier)
def extract(self, format, carrier): """ return a span context :param format: :param carrier: dict: currently support: SofaHeader(dict) :return: """ if format != opentracing.Format.TEXT_MAP: raise opentracing.UnsupportedFormatException() try: d = { k.split('.', 1)[1]: carrier[k] for k in carrier if k.startswith(self._prefix) } return self.spanContextCls(None, **d) except: raise opentracing.InvalidCarrierException()
def extract(self, format, carrier): if format in self._propagators: return self._propagators[format].extract(carrier) else: raise ot.UnsupportedFormatException()
def inject(self, span_context, format, carrier): if format in self._propagators: self._propagators[format].inject(span_context, carrier) else: raise ot.UnsupportedFormatException()
def inject(self, span_context, format, carrier): if format != opentracing.Format.HTTP_HEADERS and isinstance( carrier, dict): raise opentracing.UnsupportedFormatException(format) carrier['span-identity'] = str(span_context.identity)