Open HaloFour opened 4 years ago
Can't you work the other way round, i.e. whenever you log something, access the current OpenTelemetry context?
We have at least several thousand separate log lines written by our Spring services. That does not include the logs written by the frameworks themselves which is code that we can't control. I'd suggest that's impractical, if not impossible, to change our logging in such a manner.
But you presumably only have one logger framework. Those usually allow you to hook into logging in such a way that you can capture context information when a log line is generated.
Corresponding issue in the java repo: https://github.com/open-telemetry/opentelemetry-java/issues/922
Our services use multiple logging frameworks, and we use slf4j to abstract away those differences. The slf4j library offers no way to intercept log lines being written, it would have to be done differently for each logging framework.
An OnSetToCurrent
span processor might be nice. Having that added when BeforeEnd
is added after GA would make sense, I think.
At first I didn't think it would be too useful in Erlang but it actually might be worth it so that the logger doesn't have to read it from the context on each call but instead can have it set to the logger's process metadata each time a different span becomes the current span in the process.
This would, if added, be in the Context layer. It would not be a Span-specific callback.
What are you trying to achieve?
I need to know whenever the "current" Span changes for a given thread so that I can apply the trace ID and span ID to the thread local context for the purposes of logging. It is a functional requirement that our logs and spans can be correlated to one another. I am currently achieving this by decorating the
Tracer
Java interface and intercepting thewithSpan
method. However, that method has been removed from the specification and will be removed in the next release of the Java OpenTelemetry API. With the new Context API being static and largely self-contained it doesn't seem like there is a way to intercept when a given Context is made current or when the resulting scope is closed.