fix: normalize HTTP log fields#3
Conversation
bd133d9 to
d3951b5
Compare
d3951b5 to
7c7577f
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7c7577f77b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| var route = endpoint is RouteEndpoint routeEndpoint | ||
| ? routeEndpoint.RoutePattern.RawText | ||
| : null; |
There was a problem hiding this comment.
Use the saved exception endpoint for route logs
When this handler is invoked through UseExceptionHandler, ASP.NET Core captures the original endpoint in IExceptionHandlerFeature.Endpoint and then clears HttpContext.Endpoint before calling IExceptionHandler.TryHandleAsync (see ExceptionHandlerMiddlewareImpl.ClearHttpContext: https://github.com/dotnet/aspnetcore/blob/main/src/Middleware/Diagnostics/src/ExceptionHandler/ExceptionHandlerMiddlewareImpl.cs). For real endpoint failures handled by this package's UseHttp pipeline, httpContext.GetEndpoint() is therefore null here, so the new http.route field and the endpoint display name are never populated; read the endpoint from the exception handler feature instead.
Useful? React with 👍 / 👎.
| { | ||
| ["http.request.method"] = httpContext.Request.Method, | ||
| ["url.path"] = httpContext.Request.Path.Value, | ||
| ["url.query"] = httpContext.Request.QueryString.Value, |
There was a problem hiding this comment.
Strip the leading delimiter from url.query
QueryString.Value includes the leading ?, but the OpenTelemetry url.query attribute is the URI query component itself, with examples such as q=OpenTelemetry rather than ?q=OpenTelemetry (https://opentelemetry.io/docs/specs/semconv/registry/attributes/url/). For exception requests with a query string, this emits a value that does not match other OTel instrumentation under the same key, so normalized log queries will split on two formats; strip the leading delimiter before assigning url.query.
Useful? React with 👍 / 👎.
What changed
http.request.method,url.path,url.query,http.route,http.response.status_code,http.server.request.duration_ms,client.address,user_agent.original,enduser.id.aspnetcore.endpoint.display_nameinstead of merging it intourl.path.ILoggerplaceholders only support letters, numbers, and underscores.TraceId,SpanId, andTraceIdentifierlog fields from this middleware because OpenTelemetry already emits canonicaltrace_idandspan_idfor log/trace correlation.Why
How to verify locally
dotnet format --verify-no-changesdotnet build --configuration Releasedotnet test --configuration ReleaseMigrations / contracts / config / breaking changes