Improve logs: Extra payload and open telemetry integration - #3
Conversation
tekkamanendless
left a comment
There was a problem hiding this comment.
I see where you're going, but structurally, this isn't going to work right.
The general intent is that you would set up a single logrus logger in your application and then use a context.Context to drive exactly how it performs.
For example, each request will get its own context.Context via http.Request, but they'll all share the same global formatter. The context.Context carries the "context": logrus.WithContext(ctx).Infof("Some message") will have the appropriate information not because of the formatter, but because of the context.
Now, with that being said, you could restructure logEntry to be map[string]interface{} and add a couple more ContextKey constants (such as span, which I think is the only thing that you added that wasn't already there).
Probably you don't want to land this as such. But we improved your package with a few things, that might be breaking changes.
traceto get thetraceIDintegrate with OpenTelemetry and get it from the active Span (if any).logrus. At least for us, that we use them a lot was a problem as lots of extra data was lost. To do it, instead of using thestruct, it is using an intermediatemapto be able to Marshal any possible field.On the way I downgraded OpenTelemetry to 1.25 because the vendor we use still hasn't yet update to the latest and does not yet implement all the new interfaces.
Up to discuss if we can agree on common grounds to make this available for everyone