uber-common / opentracing-python-instrumentation

A collection of Python instrumentation tools for the OpenTracing API
MIT License
164 stars 58 forks source link

Context manager API for patches #74

Closed StasEvseev closed 5 years ago

StasEvseev commented 5 years ago

Hey guys! it is amazing work you did! I am trying to integrate it in my projects. But I am facing problem I can't undo patching install_all_patches().

Why I need this? I want to do next. I want to control collecting spans by using simple logic. If application have some flag meaning to collect spans (it can be settings or etcd) OR getting trace_id in headers then our application start collecting spans within not only application itself, but also sending headers to other application. And application below use the same logic (it would be middleware).

And do want to use patching your API provide (install_all_patches()), but it is sending headers always. I could add applying patch in the middleware if conditions mentions above was meet, and undo patch in the exit of middleware.

Could anybody help me with that?

yurishkuro commented 5 years ago

Whether to collect the spans or not is typically decided by the tracer implementation, not by the instrumentation (which is this lib). Most of what you described is how sampling in tracers works anyway. Jaeger tracer supports as samplers whose probability can be controlled from the collectors.

I strongly recommend looking for other solutions before trying to undo patches on the fly, that sounds like an anti-pattern to me.

StasEvseev commented 5 years ago

Yes. You are right. But I found it is nice to do patch to enforce collecting spans (no manual work needed). And my idea were to prevent sending trace_id in headers for requests,urllib, urllib2 libraries based on some conditions on application level. We can try to do it in different manners.

And I like idea to have one point of trace process from up to bottom. When first application gets trace_id then it activate tracing process and pass headers through to application it is calling.