samber / slog-fiber

🚨 Fiber middleware for slog logger
https://pkg.go.dev/github.com/samber/slog-fiber
MIT License
57 stars 9 forks source link

Missing trace_id + span_id when using with otelfiber #27

Closed scorpionknifes closed 2 months ago

scorpionknifes commented 2 months ago

I'm trying to use the official otelfiber and this library to log trace_id and user_id

app.Use(otelfiber.Middleware())
app.Use(slogfiber.NewWithConfig(logger, slogfiber.Config{
    WithSpanID:  true,
    WithTraceID: true,
}))

I noticed the otelfiber library uses c.UserContext() https://github.com/gofiber/contrib/blob/c62abb213b0a82b35be9ecf39237760e0ee84c84/otelfiber/fiber.go#L119-L120

And this library uses c.Context() which trace doesn't exist. https://github.com/samber/slog-fiber/blob/7bd189e1a50676fb442b911788788584d14a9311/middleware.go#L181-L182

I'm not sure if i'm implementing this wrong or the library is deliberately using the fasthttp context?

scorpionknifes commented 2 months ago

Side note I think trace id and span id need to be trace_id instead of trace-id https://opentelemetry.io/docs/specs/otel/compatibility/logging_trace_context

samber commented 2 months ago

i made a fix, thanks for the feedback