How to use the basictracer.span.BasicSpan 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 opentracing / basictracer-python / basictracer / tracer.py View on Github external
if scope is not None:
                parent_ctx = scope.span.context

        # Assemble the child ctx
        ctx = SpanContext(span_id=generate_id())
        if parent_ctx is not None:
            if parent_ctx._baggage is not None:
                ctx._baggage = parent_ctx._baggage.copy()
            ctx.trace_id = parent_ctx.trace_id
            ctx.sampled = parent_ctx.sampled
        else:
            ctx.trace_id = generate_id()
            ctx.sampled = self.sampler.sampled(ctx.trace_id)

        # Tie it all together
        return BasicSpan(
            self,
            operation_name=operation_name,
            context=ctx,
            parent_id=(None if parent_ctx is None else parent_ctx.span_id),
            tags=tags,
            start_time=start_time)
github instana / python-sensor / instana / span.py View on Github external
from basictracer.span import BasicSpan
from basictracer.context import SpanContext


class InstanaSpan(BasicSpan):
    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)

    def log_exception(self, e):
        if hasattr(e, 'message'):
            self.log_kv({'message': e.message})
        elif hasattr(e, '__str__'):
github instana / python-sensor / instana / span.py View on Github external
    @property
    def baggage(self):
        return self._baggage

    def with_baggage_item(self, key, value):
        new_baggage = self._baggage.copy()
        new_baggage[key] = value
        return SpanContext(
            trace_id=self.trace_id,
            span_id=self.span_id,
            sampled=self.sampled,
            baggage=new_baggage)


class InstanaSpan(BasicSpan):
    stack = None
    synthetic = False

    def finish(self, finish_time=None):
        super(InstanaSpan, self).finish(finish_time)

    def set_tag(self, key, value):
        # Key validation
        if not isinstance(key, six.text_type) and not isinstance(key, six.string_types) :
            logger.debug("(non-fatal) span.set_tag: tag names must be strings. tag discarded for %s", type(key))
            return self

        final_value = value
        value_type = type(value)

        # Value validation
github opentracing / basictracer-python / basictracer / span.py View on Github external
def set_operation_name(self, operation_name):
        with self._lock:
            self.operation_name = operation_name
        return super(BasicSpan, self).set_operation_name(operation_name)