-
Notifications
You must be signed in to change notification settings - Fork 316
Avoid globals? #10
Comments
I agree that there will be a tendency to use the default/global tracer, and of course that makes me sad. I think it's also important to recognize what a hassle monitoring instrumentation is for engineers, so anything that lowers the barrier to instrumentation might ultimately be in our best interests. We could (?) add a strongly-worded comment about the default tracer explaining how it should be an option of last resort. For example, in OSS libs I would expect the option to configure the lib with a non-default tracer, but the fallback would be, well, the default tracer. |
Yeah, that is a very fair and valid argument. I too worry about raising the barrier to entry here as well. Instead of a strongly-worded note, how about we just push devs in the right direction gently with a comment like:
Thinking about it more, I'll send a PR for this later. |
@slimsag what is your use case for more than one tracer in the app? |
@yurishkuro As an example:
In this fictional scenario, it would be nice to be able to use Zipkin with this forum software while remaining to use Appdash for the rest of our app. Perhaps not the most concrete example, and one could argue there should only ever be one tracer in an app, but for users ending up in this scenario their only option will become to "write a tracer that delegates to another process, which then delegates to Zipkin/Appdash depending on what the data looks like". I think it's simple enough to avoid with a comment like what I suggested above, so my question is: why not? |
Yeah, so originally we were thinking that more than one tracing per app would be achievable by providing a raw.Reporter that would fan out to more than one underlying real reporters. However, we later moved towards Tracer being the plug-in point (I recall you were also in favor of that in the earlier discussions), and fan-out won't be possible with Tracer API. I am not disagreeing with you that a singleton may create problems (especially for testing), and I don't object to the comment, but a comment is not enforceable, and your example above would still be in trouble if the two parts of the app chose to ignore that comment and instrument via global tracer. I am not sure I get the example though. If your app embeds a forum library, then you, as the app developer, is the user of tracing, and you would want to use the same tracing system across all of your apps. So if there's a real problem with the API, I would like to have our story straight, not just say "aha, we did tell you not to do that.."
|
@yurishkuro I didn't find anything in the API named
I completely agree. Though enforceable is still a relative term; for example nothing stops a user from defining their own global tracer somewhere and using that across all their projects, either. I think the comment could be a good tradeoff, but am open to other ideas too.
Sorry for the confusion, I was trying to make the point of my example that:
Though, I admit, this is just a fictitious example I've come up with. I don't have such a situation currently, and may not ever in the future. I don't see much harm in officially suggesting the idea that APIs support using a non-global tracer, though. It seems to come at a relatively low cost (a comment) and enable some more complex patterns like my example above, even if it is not enforced / must be handled on a case-by-case basis. |
On the java side of things, I'd expect some users to want to use That said, I suspect there will be those who think of this as a system concern, and will want no-config options. Other than a static method, one trick is hiding the "default". Ex. |
I think I've lost the argument for not using globals here (which is okay), and they do have some clear benefits. I also don't have a strong real-world example yet as to why we should avoid them, so I'll close this issue for now and raise it later if one comes up. |
I do see the value in the default tracer at https://github.com/opentracing/api-golang/blob/master/opentracing/defaulttracer.go#L13-L15 but at the same time it seems like more trouble than it is worth.
I'm curious if others could elaborate on why it's a good idea to have around instead of encouraging passing a tracer around via other means (your apps own global var, via
context.Context
, or some other means)?The reason I am inherently opposed to it, is that OSS libraries will just use the global by default (this is easiest!) and suddenly it's much more difficult to run two tracers for the same process or other more complex environments.
The text was updated successfully, but these errors were encountered: