Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: How use opentracing.global_tracer() when using jaeger_client lib #35

Open
jan25 opened this issue Jun 8, 2019 · 3 comments
Open

Comments

@jan25
Copy link
Contributor

jan25 commented Jun 8, 2019

This example https://github.com/opentracing-contrib/python-flask/blob/master/example/server.py#L28 uses the tracer returned by jaeger_client's initialize_tracer method. This method internally sets the opentracing.tracer to jaeger tracer object, this means for any request handler there after can do opentracing.global_tracer().start_span(...) and this sends traces to jaeger

I noticed when i run a flask dev server(using app.run) opentracing.global_tracer() is not the same as jaeger tracer i initialised earlier(as in the the link above) when starting up the server. Is there something i'm missing on flask side?

I could use returned jaeger_tracer from initialize_tracer(), which would mean i'd have to pass this around or create my own process/request local storage. I suppose according to jaeger tracer docs https://github.com/jaegertracing/jaeger-client-python#production, the initialised jaeger tracer must be available via opentracing.global_tracer()

@jan25
Copy link
Contributor Author

jan25 commented Jun 9, 2019

I was able to solve this by setting up a uwsgi.ini to start up the server, and use @postfork from uwsgidecorators to ensure the tracer is initialized once per forked process. I suppose, this is more of a production way to set things up

The dev server issue still remains though, Afaik the app.run way to start up flask dev server creates one process so i expect the tracer to work there without @postfork. I even tried app.run(threaded=False, ...) with no luck

@donnlee
Copy link

donnlee commented Oct 14, 2020

I was able to solve this by setting up a uwsgi.ini to start up the server, and use @postfork from uwsgidecorators to ensure the tracer is initialized once per forked process. I suppose, this is more of a production way to set things up

@jan25 , Could you please share an example of a @postfork function that worked? I have tried the following and it fails:

@postfork
def set_tracer_globals():
    global jaeger_tracer, flask_tracer
    jaeger_tracer = init_tracer('my_service')
    flask_tracer = FlaskTracing(jaeger_tracer, True, app)

Where init_tracer() returns config.initialize_tracer()

@jan25
Copy link
Contributor Author

jan25 commented Oct 14, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants