Conversation
Co-authored-by: gaby <835733+gaby@users.noreply.github.com>
Co-authored-by: gaby <835733+gaby@users.noreply.github.com>
Co-authored-by: gaby <835733+gaby@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds OpenTelemetry logging support to the v3/otel Fiber middleware by allowing a configurable LoggerProvider and emitting a correlated log record per request.
Changes:
- Add
LoggerProviderto middleware config +WithLoggerProvider(...)option (defaults to global provider when unset). - Emit one structured log record per request with severity derived from HTTP status and standard HTTP/url attributes.
- Add unit tests for log emission/severity/Next-skip behavior; update docs and module dependencies.
Reviewed changes
Copilot reviewed 6 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| v3/otel/config.go | Adds LoggerProvider field and WithLoggerProvider option. |
| v3/otel/fiber.go | Initializes OTel logger and emits a per-request log record with severity + attributes. |
| v3/otel/otel_test/fiber_test.go | Adds in-memory log processor + tests validating emission and severity mapping. |
| v3/otel/README.md | Documents WithLoggerProvider and adds a usage example. |
| v3/otel/go.mod | Adds go.opentelemetry.io/otel/log and go.opentelemetry.io/otel/sdk/log deps. |
| v3/otel/go.sum | Updates sums for new OTel log dependencies. |
| v3/otel/example/go.mod | Pulls in otel/log as an indirect dependency for the example module. |
| v3/otel/example/go.sum | Updates sums for the example module’s new indirect dependency. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| logSeverity := severityFromHTTPStatusCode(c.Response().StatusCode()) | ||
| if logger.Enabled(ctx, otellog.EnabledParameters{Severity: logSeverity}) { | ||
| var logRecord otellog.Record |
There was a problem hiding this comment.
The log record uses the captured ctx variable for logger.Enabled/logger.Emit. Since downstream handlers can mutate the request context via c.SetContext(...), consider using c.Context() here (like the outbound propagator injection does) so emitted logs include any user-added values/baggage and reflect the final active context for the request.
| logRecord.SetTimestamp(start) | ||
| logRecord.SetObservedTimestamp(time.Now()) |
There was a problem hiding this comment.
logRecord.SetTimestamp(start) sets the log timestamp to the beginning of the request even though the record is emitted after the response is processed. This can skew log ordering and make the record appear to occur before the response status is known; consider setting the timestamp to the emit time (and optionally recording the start time/duration as attributes if needed).
| logRecord.SetTimestamp(start) | |
| logRecord.SetObservedTimestamp(time.Now()) | |
| emitTime := time.Now() | |
| logRecord.SetTimestamp(emitTime) | |
| logRecord.SetObservedTimestamp(emitTime) |
OpenTelemetry defines a
LoggerProviderinterface but otelfiber had no support for it. This addsWithLoggerProviderconfig option and automatic per-request log record emission correlated with the active trace.Changes
config.go: AddedLoggerProvider otellog.LoggerProviderfield +WithLoggerProvider(otellog.LoggerProvider) Option. Falls back to global logger provider when unset (consistent with tracer/meter behavior).fiber.go: Creates a logger at middleware init; emits one structured log record per request after response processing. Severity is derived from HTTP status:Info(2xx/3xx),Warn(4xx),Error(5xx). Log record attributes:http.request.method,http.route,http.response.status_code,url.path.otel_test/fiber_test.go: Tests for record emission, severity mapping (4xx/5xx), and skip-via-Nextbehavior using an in-memorysdklog.Processor.README.md: DocumentsWithLoggerProviderin the config table and adds a usage example.go.mod: Addsgo.opentelemetry.io/otel/log v0.17.0(runtime) andgo.opentelemetry.io/otel/sdk/log v0.17.0(test).Usage
Each request emits a log record such as:
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.