jaegertracing/jaeger-client-python

How to set Jaeger endpoint

nlamirault opened this issue ยท 9 comments

Hi, i try to use the python version of the jaeger client.
In go i do that to create the tracer :

cfg := jaegercfg.Configuration{
		Sampler: &jaegercfg.SamplerConfig{
			Type:  jaeger.SamplerTypeConst,
			Param: 1,
		},
		Reporter: &jaegercfg.ReporterConfig{
		LogSpans:           true,
		LocalAgentHostPort: "192.168.1.10:5775",
	},
}

jLogger := jaegerlog.StdLogger
jMetricsFactory := metrics.NullFactory
tracer, _, err := cfg.New(
		"myservice",
		jaegercfg.Logger(jLogger),
		jaegercfg.Metrics(jMetricsFactory),
)

How do that in Python ?
Thanks

The address of the agent is configured automatically (in Go as well), you do not need to provide it in the configuration. If you still really want to, you can override the port via:

config = {
    'local_agent': {
        'reporting_port': number,
        'sampling_port': number,
    },
}

OK.
But i would like to use the jaeger all-in-one image. :

docker run -d -p5775:5775/udp -p16686:16686 jaegertracing/all-in-one:latest

It's not on the same host.

I think Python client doesn't support talking to an agent on another host (it's also not recommended because clients use UDP to send the packets, which won't be lossless, unlike when talking over the loopback interface).

A quick fix would be to extend Python client to support reporting_host_port config param as an alternative to just the port.

Longer term, we are having ongoing discussions about supporting reporting over HTTP.

When an application running in docker container, i can't communicate with the jaeger agent by using localhost. So providing an reporting_host will be a good choice?

I believe this, and #49 are addressed in #51

I launch the all-in-one image :

$ docker run -d -p5775:5775/udp -p6831:6831/udp -p6832:6832/udp -p5778:5778 -p16686:16686 -p14268:14268 jaegertracing/all-in-one:latest

Try this code :

import opentracing
import logging
import time
from jaeger_client import Config

if __name__ == "__main__":
    log_level = logging.DEBUG
    logging.getLogger('').handlers = []
    logging.basicConfig(format='%(asctime)s %(message)s', level=log_level)

    config = Config(
        config={ # usually read from some yaml config
            'sampler': {
                'type': 'const',
                'param': 1,
            },
            'local_agent': {
                'reporting_host': "127.0.0.1",
                'reporting_port': 5775,
            },
            'logging': True,
        },
        service_name='my-app',
    )
    tracer = config.initialize_tracer()

    with opentracing.tracer.start_span('TestSpan') as span:
        span.log_event('test message', payload={'life': 42})

        with opentracing.tracer.start_span('ChildSpan', child_of=span) as child_span:
            span.log_event('down below')

    time.sleep(2)   # yield to IOLoop to flush the spans - https://github.com/uber/jaeger-client-python/issues/50
    tracer.close()  # flush any buffered spans

And the output logs :

$ python foo.py
2017-09-11 16:34:08,509 Initializing Jaeger Tracer with UDP reporter
2017-09-11 16:34:08,512 Using sampler ConstSampler(True)
2017-09-11 16:34:08,513 opentracing.tracer initialized to <jaeger_client.tracer.Tracer object at 0x7fe7e3d68c50>[app_name=my-app]
2017-09-11 16:34:08,514 Reporting span d8f5c5f29cb6c02d:de0863b7a8ed4610:d8f5c5f29cb6c02d:1 my-app.ChildSpan
2017-09-11 16:34:08,514 Reporting span d8f5c5f29cb6c02d:d8f5c5f29cb6c02d:0:1 my-app.TestSpan
Exception in thread Thread-1 (most likely raised during interpreter shutdown):
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
  File "/usr/lib/python2.7/threading.py", line 754, in run
  File "/home/vagrant/Projets/sirocco/venv/local/lib/python2.7/site-packages/threadloop/threadloop.py", line 78, in _start_io_loop
  File "/home/vagrant/Projets/sirocco/venv/local/lib/python2.7/site-packages/tornado/ioloop.py", line 904, in start
<type 'exceptions.AttributeError'>: 'NoneType' object has no attribute '_current'

reporting_host and reporting_port seem to work fine now. I think this issue can be closed? @yurishkuro

Yes, closing.

@nlamirault the exception you showed is something inside tornado, could you please open a new issue with it and include the versions of the dependencies you're using? I have run https://github.com/yurishkuro/opentracing-tutorial/tree/master/python with the latest jaeger client and it had no issues (using Python 2.7)

@yurishkuro What is the meaning of local_agent config? If I'm running jager-all-in-one using jaeger-operator on k8s, what should be the config array here?

def tracer():
    install_all_patches()
    config = Config(
        config={
            'sampler': {
                'type': 'const',
                'param': 1,
            },
            'local_agent': {
                'reporting_host': 'jaeger',
                'reporting_port': '6831',
            },
            'logging': True,
        },  
        service_name='devhubserver',
        validate=True,
        metrics_factory=PrometheusMetricsFactory(namespace='devhubserver')
    )
    return config.initialize_tracer()

// default is False
OPENTRACING_TRACE_ALL = True

// default is []
OPENTRACING_TRACED_ATTRIBUTES = ['path', 'method', 'META', 'body', 'path_info', 'content_type', 'content_params', 'GET', 'POST', 'COOKIES', 'FILES', 'headers']```