How to use the basictracer.context.SpanContext function in basictracer

To help you get started, we’ve selected a few basictracer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lightstep / lightstep-tracer-python / lightstep / lightstep_binary_propagator.py View on Github external
def extract(self, carrier):
        if type(carrier) is not bytearray:
            raise InvalidCarrierException()
        serializedProto = standard_b64decode(carrier)
        state = BinaryCarrier()
        state.ParseFromString(bytes(serializedProto))
        baggage = {}
        for k in state.basic_ctx.baggage_items:
            baggage[k] = state.basic_ctx.baggage_items[k]

        return SpanContext(
            span_id=state.basic_ctx.span_id,
            trace_id=state.basic_ctx.trace_id,
            baggage=baggage,
            sampled=state.basic_ctx.sampled)
github instana / python-sensor / instana / span.py View on Github external
def finish(self, finish_time=None):
        if self.parent_id is None:
            self.tracer.cur_ctx = None
        else:
            # Set tracer context to the parent span
            pctx = SpanContext(span_id=self.parent_id,
                               trace_id=self.context.trace_id,
                               baggage={},
                               sampled=True)
            self.tracer.cur_ctx = pctx
        super(InstanaSpan, self).finish(finish_time)
github lightstep / lightstep-tracer-python / lightstep / b3_propagator.py View on Github external
if flags == 1:
                baggage[_FLAGS] = flags
                if sampled is not None:
                    warn(
                        "x-b3-flags: 1 implies x-b3-sampled: 1, ignoring "
                        "the received value of x-b3-sampled"
                    )
            elif sampled is not None:
                baggage[_SAMPLED] = sampled

            baggage.update(carrier)

            if baggage == OTSpanContext.EMPTY_BAGGAGE:
                baggage = None

        return SpanContext(
            trace_id=int(traceid, 16),
            span_id=int(spanid, 16),
            baggage=baggage
        )
github opentracing / basictracer-python / basictracer / binary_propagator.py View on Github external
def extract(self, carrier):
        if type(carrier) is not bytearray:
            raise InvalidCarrierException()
        state = TracerState()
        state.ParseFromString(bytes(carrier[_proto_size_bytes:]))
        baggage = {}
        for k in state.baggage_items:
            baggage[k] = state.baggage_items[k]

        return SpanContext(
            span_id=state.span_id,
            trace_id=state.trace_id,
            baggage=baggage,
            sampled=state.sampled)
github opentracing / basictracer-python / basictracer / text_propagator.py View on Github external
sampled = parse_boolean_for_field(field_name_sampled, v)
                count += 1
            elif k.startswith(prefix_baggage):
                baggage[k[len(prefix_baggage):]] = v

        if count != field_count:
            msg = (
                'expected to parse {field_count} fields'
                ', but parsed {count} instead'
            )
            raise SpanContextCorruptedException(msg.format(
                field_count=field_count,
                count=count,
            ))

        return SpanContext(
            span_id=span_id,
            trace_id=trace_id,
            baggage=baggage,
            sampled=sampled)