Exemplo n.º 1
0
 def test_context_from_readable_headers(self):
     # provide headers all the way through Config object
     config = Config(service_name='test',
                     config={
                         'trace_id_header': 'Trace_ID',
                         'baggage_header_prefix': 'Trace-Attr-',
                     })
     tracer = config.create_tracer(
         reporter=InMemoryReporter(),
         sampler=ConstSampler(True),
     )
     for url_encoding in [False, True]:
         if url_encoding:
             codec = tracer.codecs[Format.HTTP_HEADERS]
             headers = {
                 'Trace-ID': '100%3A7f:0:1',
                 'trace-attr-Kiff': 'Amy%20Wang',
                 'trace-atTR-HERMES': 'LaBarbara%20Hermes'
             }
         else:
             codec = tracer.codecs[Format.HTTP_HEADERS]
             headers = {
                 'Trace-ID': '100:7f:0:1',
                 'trace-attr-Kiff': 'Amy Wang',
                 'trace-atTR-HERMES': 'LaBarbara Hermes'
             }
         ctx = codec.extract(headers)
         assert ctx.trace_id == 256
         assert ctx.span_id == 127
         assert ctx.parent_id is None
         assert ctx.flags == 1
         assert ctx.baggage == {
             'kiff': 'Amy Wang',
             'hermes': 'LaBarbara Hermes',
         }
Exemplo n.º 2
0
def initialize_tracer(service_name,
                      async_transport=False,
                      host=None,
                      port=0,
                      sample_rate=1.0):
    if sample_rate == 1.0:
        # sample all traces
        sampler_config = {'type': 'const', 'param': 1}
    elif sample_rate == 0.0:
        # sample none traces
        sampler_config = {'type': 'const', 'param': 0}
    else:
        # random sampling decision with the probability
        sampler_config = {'type': 'probabilistic', 'param': sample_rate}

    tracer_config = {
        'sampler': sampler_config,
    }

    if host:
        tracer_config['local_agent'] = {
            'reporting_host': host,
            'reporting_port': port
        }

    config = Config(
        config=tracer_config,
        service_name=service_name,
        validate=True,
        scope_manager=AsyncioScopeManager() if async_transport else None,
    )

    return config.new_tracer()
def init_tracer(service_name,
                host_ip,
                reporting_port=6831,
                sampling_port=5778):
    """init jaeger client"""
    global _tracer
    config = Config(config={
        'sampler': {
            'type': 'const',
            'param': 1,
        },
        'local_agent': {
            'sampling_port': sampling_port,
            'reporting_port': reporting_port,
            'reporting_host': host_ip
        },
        'logging': True,
        'propagation': 'b3',
    },
                    service_name=service_name,
                    validate=True)
    jaeger_tracer = config.initialize_tracer()
    if jaeger_tracer:
        _tracer = TracerProxy(jaeger_tracer)
    return _tracer
Exemplo n.º 4
0
    def __init__(self):
        cfg = Config(config)
        init_sampler = cfg.sampler
        channel = self.local_agent_sender

        reporter = Reporter(channel=channel,
                            flush_interval=cfg.reporter_flush_interval)

        remote_sampler = RemoteControlledSampler(
            channel=channel,
            service_name=cfg.service_name,
            sampling_refresh_interval=cfg.sampling_refresh_interval,
            init_sampler=init_sampler)

        remote_tracer = Tracer(service_name=cfg.service_name,
                               reporter=reporter,
                               sampler=remote_sampler)

        const_tracer = Tracer(service_name=cfg.service_name,
                              reporter=reporter,
                              sampler=ConstSampler(decision=True))

        self._tracers = {
            SAMPLER_TYPE_CONST: const_tracer,
            SAMPLER_TYPE_REMOTE: remote_tracer
        }
Exemplo n.º 5
0
    def init_config(cls):
        cls.store_http_body = cls.is_enabled('TRACING_STORE_HTTP_BODY')
        http_body_size_limit = os.getenv('TRACING_HTTP_BODY_SIZE_LIMIT')
        if http_body_size_limit:
            cls.http_body_size_limit = int(http_body_size_limit)

        service_name = os.environ['TRACING_SERVICE_NAME']
        reporting_host = os.getenv('TRACING_AGENT_HOST',
                                   DEFAULT_REPORTING_HOST)
        reporting_port = os.getenv('TRACING_AGENT_PORT',
                                   DEFAULT_REPORTING_PORT)

        cls.config = Config(
            config={
                'sampler': {
                    'type': 'const',
                    'param': 1,
                },
                'local_agent': {
                    'reporting_host': reporting_host,
                    'reporting_port': reporting_port,
                },
                'logging': cls.is_enabled('TRACING_LOGGING'),
                'tags': {
                    'intracing.version': intracing.__version__,
                },
            },
            service_name=service_name,
        )
Exemplo n.º 6
0
    def __init__(self):
        cfg = Config(config)
        init_sampler = cfg.sampler
        channel = self.local_agent_sender

        sender = UDPSender(
            io_loop=channel.io_loop,
            host=os.getenv('AGENT_HOST', 'jaeger-agent'),
            port=cfg.local_agent_reporting_port,
        )
        reporter = Reporter(sender=sender,
                            flush_interval=cfg.reporter_flush_interval)

        remote_sampler = RemoteControlledSampler(
            channel=channel,
            service_name=cfg.service_name,
            sampling_refresh_interval=cfg.sampling_refresh_interval,
            init_sampler=init_sampler)

        remote_tracer = Tracer(service_name=cfg.service_name,
                               reporter=reporter,
                               sampler=remote_sampler)

        const_tracer = Tracer(service_name=cfg.service_name,
                              reporter=reporter,
                              sampler=ConstSampler(decision=True))

        self._tracers = {
            SAMPLER_TYPE_CONST: const_tracer,
            SAMPLER_TYPE_REMOTE: remote_tracer
        }
Exemplo n.º 7
0
def initialize_tracer(service_name):
    # pylint: disable=E0401
    from jaeger_client.config import Config
    from opentracing.scope_managers.asyncio import AsyncioScopeManager

    # pylint: enable=E0401

    config = Config(
        config={'sampler': {
            'type': 'const',
            'param': 1
        }},
        service_name=service_name,
        validate=True,
        scope_manager=AsyncioScopeManager(),
    )

    return config.initialize_tracer()
Exemplo n.º 8
0
def configure_tracing(graph):
    """
    See https://www.jaegertracing.io/docs/1.12/sampling/ for more info about
    available sampling strategies.

    """
    config = Config(
        config={
            "sampler": {
                "type": graph.config.tracer.sample_type,
                "param": graph.config.tracer.sample_param,
            },
            "local_agent": {
                "sampling_port": graph.config.tracer.sampling_port,
                "reporting_port": graph.config.tracer.reporting_port,
                "reporting_host": graph.config.tracer.reporting_host,
            },
            "logging": True,
        },
        service_name=graph.metadata.name,
    )
    return config.initialize_tracer()
Exemplo n.º 9
0
 def test_context_from_readable_headers(self):
     # provide headers all the way through Config object
     config = Config(
         service_name='test',
         config={
             'trace_id_header': 'Trace_ID',
             'baggage_header_prefix': 'Trace-Attr-',
         })
     tracer = config.create_tracer(
         reporter=InMemoryReporter(),
         sampler=ConstSampler(True),
     )
     for url_encoding in [False, True]:
         if url_encoding:
             codec = tracer.codecs[Format.HTTP_HEADERS]
             headers = {
                 'Trace-ID': '100%3A7f:0:1',
                 'trace-attr-Kiff': 'Amy%20Wang',
                 'trace-atTR-HERMES': 'LaBarbara%20Hermes'
             }
         else:
             codec = tracer.codecs[Format.HTTP_HEADERS]
             headers = {
                 'Trace-ID': '100:7f:0:1',
                 'trace-attr-Kiff': 'Amy Wang',
                 'trace-atTR-HERMES': 'LaBarbara Hermes'
             }
         ctx = codec.extract(headers)
         assert ctx.trace_id == 256
         assert ctx.span_id == 127
         assert ctx.parent_id is None
         assert ctx.flags == 1
         assert ctx.baggage == {
             'kiff': 'Amy Wang',
             'hermes': 'LaBarbara Hermes',
         }
Exemplo n.º 10
0
import os

from jaeger_client.config import Config
from jaeger_client.constants import TRACE_ID_HEADER as DEFAULT_TRACE_ID_HEADER

# global jaeger config
JAEGER_SERVICE_NAME = os.getenv('JAEGER_SERVICE_NAME', "default_jaeger_service_name")
TRACE_ID_HEADER = os.getenv('TRACE_ID_HEADER', DEFAULT_TRACE_ID_HEADER)
OPERATION_NAME = os.getenv('OPERATION_NAME', "default_operation_name")

config = Config(
    config={
        'sampler': {
            'type': 'const',
            'param': 1,
        },
        'logging': True,
    },
    service_name=JAEGER_SERVICE_NAME,
)
# global tracer
tracer = config.initialize_tracer()


__all__ = [
    "tracer"
]