Skip to content

fix: normalize HTTP log fields#3

Merged
PANiXiDA merged 1 commit into
mainfrom
feature/normalize-http-log-fields
Jun 19, 2026
Merged

fix: normalize HTTP log fields#3
PANiXiDA merged 1 commit into
mainfrom
feature/normalize-http-log-fields

Conversation

@PANiXiDA

@PANiXiDA PANiXiDA commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

What changed

  • Normalized HTTP request and exception log attributes to OpenTelemetry semantic names: 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.
  • Kept ASP.NET Core endpoint display metadata as aspnetcore.endpoint.display_name instead of merging it into url.path.
  • Emit OpenTelemetry-style dotted keys through log scopes instead of message template placeholders, because ILogger placeholders only support letters, numbers, and underscores.
  • Removed manual TraceId, SpanId, and TraceIdentifier log fields from this middleware because OpenTelemetry already emits canonical trace_id and span_id for log/trace correlation.
  • Updated middleware unit tests for the normalized field contract.

Why

  • Avoid duplicate trace fields in VictoriaLogs and keep log-to-trace correlation on OpenTelemetry canonical fields.
  • Make HTTP log fields easier to query consistently across services.
  • Keep route template, concrete request path, and ASP.NET Core endpoint display name as separate concepts.
  • Avoid analyzer warnings from invalid structured log placeholder names.

How to verify locally

  • dotnet format --verify-no-changes
  • dotnet build --configuration Release
  • dotnet test --configuration Release

Migrations / contracts / config / breaking changes

  • No migrations.
  • No configuration changes.
  • Log field names change from the previous PascalCase middleware fields to OpenTelemetry-style names. Existing dashboards or log queries that reference the old field names should be updated.

@PANiXiDA PANiXiDA force-pushed the feature/normalize-http-log-fields branch from bd133d9 to d3951b5 Compare June 19, 2026 18:21
@PANiXiDA PANiXiDA force-pushed the feature/normalize-http-log-fields branch from d3951b5 to 7c7577f Compare June 19, 2026 18:28
@PANiXiDA PANiXiDA marked this pull request as ready for review June 19, 2026 18:31
@PANiXiDA PANiXiDA merged commit 5797f90 into main Jun 19, 2026
4 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +24 to +26
var route = endpoint is RouteEndpoint routeEndpoint
? routeEndpoint.RoutePattern.RawText
: null;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@PANiXiDA PANiXiDA deleted the feature/normalize-http-log-fields branch June 19, 2026 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants