コード例 #1
0
ファイル: tracers.py プロジェクト: mvalkon/opentracing-utils
def init_opentracing_tracer(tracer, **kwargs):
    if tracer == OPENTRACING_BASIC:
        from basictracer import BasicTracer  # noqa

        recorder = kwargs.get('recorder')
        sampler = kwargs.get('sampler')

        opentracing.tracer = BasicTracer(recorder=recorder, sampler=sampler)
    elif tracer == OPENTRACING_INSTANA:
        import instana.options as InstanaOpts
        import instana.tracer  # noqa

        service = kwargs.pop('service',
                             os.environ.get('OPENTRACING_INSTANA_SERVICE'))
        log_level = kwargs.pop('log_level', logging.INFO)

        instana.tracer.init(
            InstanaOpts.Options(service=service, log_level=log_level,
                                **kwargs))
    elif tracer == OPENTRACING_LIGHTSTEP:
        import lightstep

        # Get Lightstep specific config vars
        component_name = kwargs.pop(
            'component_name',
            os.environ.get('OPENTRACING_LIGHTSTEP_COMPONENT_NAME'))
        access_token = kwargs.pop(
            'access_token',
            os.environ.get('OPENTRACING_LIGHTSTEP_ACCESS_TOKEN'))
        collector_host = kwargs.pop(
            'collector_host',
            os.environ.get('OPENTRACING_LIGHTSTEP_COLLECTOR_HOST',
                           'collector.lightstep.com'))
        collector_port = kwargs.pop(
            'collector_port',
            int(os.environ.get('OPENTRACING_LIGHTSTEP_COLLECTOR_PORT', 443)))
        verbosity = kwargs.pop(
            'verbosity',
            int(os.environ.get('OPENTRACING_LIGHTSTEP_VERBOSITY', 0)))

        if not access_token:
            logger.warn('Initializing LighStep tracer with no access_token!')

        opentracing.tracer = lightstep.Tracer(component_name=component_name,
                                              access_token=access_token,
                                              collector_host=collector_host,
                                              collector_port=collector_port,
                                              verbosity=verbosity,
                                              **kwargs)
    elif tracer == OPENTRACING_JAEGER:
        from jaeger_client import Config

        service_name = kwargs.pop(
            'service_name', os.environ.get('OPENTRACING_JAEGER_SERVICE_NAME'))
        config = kwargs.pop('config', {})

        jaeger_config = Config(config=config, service_name=service_name)
        opentracing.tracer = jaeger_config.initialize_tracer()
    else:
        opentracing.tracer = opentracing.Tracer()
コード例 #2
0
    def __init__(self, options=o.Options()):
        self.sensor = instana.global_sensor
        super(InstanaTracer, self).__init__(r.InstanaRecorder(self.sensor),
                                            r.InstanaSampler())

        self._propagators[ot.Format.HTTP_HEADERS] = HTTPPropagator()
        self._propagators[ot.Format.TEXT_MAP] = TextPropagator()
コード例 #3
0
def test_text_no_context_extract():
    opts = options.Options()
    ot.tracer = InstanaTracer(opts)

    carrier = {}
    ctx = ot.tracer.extract(ot.Format.TEXT_MAP, carrier)

    assert ctx is None
コード例 #4
0
def test_text_mixed_case_extract():
    opts = options.Options()
    ot.tracer = InstanaTracer(opts)

    carrier = {'x-insTana-T': '1', 'X-inSTANa-S': '1', 'X-INstana-l': '1'}
    ctx = ot.tracer.extract(ot.Format.TEXT_MAP, carrier)

    assert (ctx is None)
コード例 #5
0
def test_http_no_context_extract():
    opts = options.Options()
    ot.tracer = InstanaTracer(opts)

    carrier = {}
    ctx = ot.tracer.extract(ot.Format.HTTP_HEADERS, carrier)

    assert ctx is None
コード例 #6
0
def test_text_basic_extract():
    opts = options.Options()
    ot.tracer = InstanaTracer(opts)

    carrier = {'X-INSTANA-T': '1', 'X-INSTANA-S': '1', 'X-INSTANA-L': '1'}
    ctx = ot.tracer.extract(ot.Format.TEXT_MAP, carrier)

    assert type(ctx) is span_context.InstanaSpanContext
    assert_equals('0000000000000001', ctx.trace_id)
    assert_equals('0000000000000001', ctx.span_id)
コード例 #7
0
def test_http_mixed_case_extract():
    opts = options.Options()
    ot.tracer = InstanaTracer(opts)

    carrier = {'x-insTana-T': '1', 'X-inSTANa-S': '1', 'X-INstana-l': '1'}
    ctx = ot.tracer.extract(ot.Format.HTTP_HEADERS, carrier)

    assert type(ctx) is span_context.InstanaSpanContext
    assert_equals('0000000000000001', ctx.trace_id)
    assert_equals('0000000000000001', ctx.span_id)
コード例 #8
0
def test_basic_extract():
    opts = options.Options()
    ot.tracer = InstanaTracer(opts)

    carrier = {'X-Instana-T': '1', 'X-Instana-S': '1', 'X-Instana-L': '1'}
    ctx = ot.tracer.extract(ot.Format.HTTP_HEADERS, carrier)

    assert type(ctx) is basictracer.context.SpanContext
    assert_equals('0000000000000001', ctx.trace_id)
    assert_equals('0000000000000001', ctx.span_id)
コード例 #9
0
def test_text_inject_with_list():
    opts = options.Options()
    ot.tracer = InstanaTracer(opts)

    carrier = []
    span = ot.tracer.start_span("nosetests")
    ot.tracer.inject(span.context, ot.Format.TEXT_MAP, carrier)

    assert ('X-INSTANA-T', span.context.trace_id) in carrier
    assert ('X-INSTANA-S', span.context.span_id) in carrier
    assert ('X-INSTANA-L', "1") in carrier
コード例 #10
0
def test_http_inject_with_list():
    opts = options.Options()
    ot.tracer = InstanaTracer(opts)

    carrier = []
    span = ot.tracer.start_span("nosetests")
    ot.tracer.inject(span.context, ot.Format.HTTP_HEADERS, carrier)

    assert ('X-Instana-T', span.context.trace_id) in carrier
    assert ('X-Instana-S', span.context.span_id) in carrier
    assert ('X-Instana-L', "1") in carrier
コード例 #11
0
 def initialize(self):
     SERVICE = "🦄 Stan ❤️s Python 🦄"
     tracer.init(o.Options(service=SERVICE, log_level=logging.DEBUG))
     print("Calling initialize " + str(self) + str(SERVICE))
     today = datetime.datetime.now()
     print(today)
     self.tracer = Tracer()
     self.span = self.tracer.start_span(operation_name='root')
     self.span.set_tag('RequestHandler', 'MainHandler')
     self.requestmethod = ""
     self.clazzName = self.__class__.__name__
コード例 #12
0
def test_128bit_headers():
    opts = options.Options()
    ot.tracer = InstanaTracer(opts)

    carrier = {'X-Instana-T': '0000000000000000b0789916ff8f319f',
               'X-Instana-S': '0000000000000000b0789916ff8f319f', 'X-Instana-L': '1'}
    ctx = ot.tracer.extract(ot.Format.HTTP_HEADERS, carrier)

    assert type(ctx) is basictracer.context.SpanContext
    assert_equals('b0789916ff8f319f', ctx.trace_id)
    assert_equals('b0789916ff8f319f', ctx.span_id)
コード例 #13
0
def test_inject_with_list():
    opts = options.Options()
    ot.tracer = InstanaTracer(opts)

    carrier = []
    span = ot.tracer.start_span("nosetests")
    ot.tracer.inject(span.context, ot.Format.HTTP_HEADERS, carrier)

    assert ('X-Instana-T', span.context.trace_id) in carrier
    assert ('X-Instana-S', span.context.span_id) in carrier
    assert ('X-Instana-L', "1") in carrier
    server_timing_value = "intid;desc=%s" % span.context.trace_id
    assert ('Server-Timing', server_timing_value) in carrier
コード例 #14
0
def test_text_128bit_headers():
    opts = options.Options()
    ot.tracer = InstanaTracer(opts)

    carrier = {
        'X-INSTANA-T': '0000000000000000b0789916ff8f319f',
        'X-INSTANA-S': ' 0000000000000000b0789916ff8f319f',
        'X-INSTANA-L': '1'
    }
    ctx = ot.tracer.extract(ot.Format.TEXT_MAP, carrier)

    assert type(ctx) is span_context.InstanaSpanContext
    assert_equals('b0789916ff8f319f', ctx.trace_id)
    assert_equals('b0789916ff8f319f', ctx.span_id)
コード例 #15
0
def test_http_inject_with_dict():
    opts = options.Options()
    ot.tracer = InstanaTracer(opts)

    carrier = {}
    span = ot.tracer.start_span("nosetests")
    ot.tracer.inject(span.context, ot.Format.HTTP_HEADERS, carrier)

    assert 'X-Instana-T' in carrier
    assert_equals(carrier['X-Instana-T'], span.context.trace_id)
    assert 'X-Instana-S' in carrier
    assert_equals(carrier['X-Instana-S'], span.context.span_id)
    assert 'X-Instana-L' in carrier
    assert_equals(carrier['X-Instana-L'], "1")
コード例 #16
0
def test_text_inject_with_dict():
    opts = options.Options()
    ot.tracer = InstanaTracer(opts)

    carrier = {}
    span = ot.tracer.start_span("nosetests")
    ot.tracer.inject(span.context, ot.Format.TEXT_MAP, carrier)

    assert 'X-INSTANA-T' in carrier
    assert_equals(carrier['X-INSTANA-T'], span.context.trace_id)
    assert 'X-INSTANA-S' in carrier
    assert_equals(carrier['X-INSTANA-S'], span.context.span_id)
    assert 'X-INSTANA-L' in carrier
    assert_equals(carrier['X-INSTANA-L'], "1")
コード例 #17
0
def test_inject():
    opts = options.Options()
    ot.tracer = tracer.InstanaTracer(opts)

    carrier = {}
    span = ot.tracer.start_span("nosetests")
    ot.tracer.inject(span.context, ot.Format.HTTP_HEADERS, carrier)

    assert 'X-Instana-T' in carrier
    assert_equals(carrier['X-Instana-T'],
                  util.id_to_header(span.context.trace_id))
    assert 'X-Instana-S' in carrier
    assert_equals(carrier['X-Instana-S'],
                  util.id_to_header(span.context.span_id))
    assert 'X-Instana-L' in carrier
    assert_equals(carrier['X-Instana-L'], "1")
コード例 #18
0
def test_inject_with_dict():
    opts = options.Options()
    ot.tracer = InstanaTracer(opts)

    carrier = {}
    span = ot.tracer.start_span("nosetests")
    ot.tracer.inject(span.context, ot.Format.HTTP_HEADERS, carrier)

    assert 'X-Instana-T' in carrier
    assert_equals(carrier['X-Instana-T'], span.context.trace_id)
    assert 'X-Instana-S' in carrier
    assert_equals(carrier['X-Instana-S'], span.context.span_id)
    assert 'X-Instana-L' in carrier
    assert_equals(carrier['X-Instana-L'], "1")
    assert 'Server-Timing' in carrier
    server_timing_value = "intid;desc=%s" % span.context.trace_id
    assert_equals(carrier['Server-Timing'], server_timing_value)
コード例 #19
0
ファイル: probe.py プロジェクト: rosscdh/python-sensor
import opentracing as ot

from instana import options, tracer

# This file is the hook for autoinstrumenation.
# Here, we should:
#  1. Make sure instana sensor is not already active in the process
#  2. Activate properly
#    a. Runtime metrics
#    b. Detect and instrument framework
#    c. Detect and instrument any libraries

opts = options.Options()
ot.tracer = tracer.InstanaTracer(opts)