Repository navigation
feat(http_telemetry): add route, header and body fields to server telemetry - #987
Draft
Evgeny Fedorov (evgenyfedorov2) wants to merge 6 commits into
Draft
Evgeny Fedorov (evgenyfedorov2) wants to merge 6 commits into
Evgeny Fedorov (evgenyfedorov2) wants to merge 6 commits into
Conversation
Add the `RouteTable` trait and its `RouteHit` match result. A resolver lists the template and the parameter names of each route, and matches a request to the number of its route and the raw values of its parameters. `RawResolver` implements it, so a `DynBuilder` resolver does too.
Every resolver that `#[resolver]` generates implements `RouteTable`. The templates and the parameter names of its static routes are tables built into the program. `match_route` uses a second copy of the matching code of `resolve`, so both pick the same route. A snapshot test shows that the output of `Generator::generate()` does not change.
An `#[event]` struct can get fields whose names are known only at run time from a field marked `#[flatten]`. The type of that field implements the new `VisitFields` trait. `visit_fields` moves from `Event` and `DynEvent` to `VisitFields`, which both traits now extend. A hand-written `Event` or `DynEvent` must also implement `VisitFields`.
With a route resolver, the complete, error and abandoned events of the server have `http.route`, the template of the matched route, and `http.route.parameter.<name>` for each route parameter that has a data class. The layer matches the request again with the resolver, only when a processor wants the event. The events also have the configured request and response headers as `http.request.header.<name>` and `http.response.header.<name>`. Each value is redacted according to the data class of its header.
With `response_body_media_types`, the complete, error and abandoned events of the server have `http.response.body`, the start of the response body as text, when the `Content-Type` of the response matches one of the configured media types. A media type also covers its structured suffixes, so `application/json` covers `application/problem+json`. An entry that is not a media type returns `MediaTypeError`. `body_size_limit` sets how many bytes are logged, 32 KiB by default. Bytes that are not valid UTF-8 become the replacement character, and the body is logged unredacted.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #987 +/- ##
==========================================
Coverage 100.0% 100.0%
==========================================
Files 793 294 -499
Lines 67943 20901 -47042
==========================================
- Hits 67943 20901 -47042
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
With `request_body_media_types`, the complete, error and abandoned events of the server have `http.request.body`, the start of the request body as text. The middleware does not read a request body by itself. It copies the bytes of a streamed body while the handler reads them, as the HTTP logging middleware of ASP.NET Core does, so a body that the handler does not read logs an empty text. A body that is already in memory is copied when the request arrives. Both lists of media types now cover a `Content-Type` by the rule of `Microsoft.Extensions.Http.Diagnostics`: a type equal to one of the entries, any `text` type, and an `application` type whose subtype ends with `+json` or `+xml`. An empty list logs no body, and an entry whose type or subtype is `*` returns `MediaTypeError`. The workspace now needs `http-body-util` 0.1.4, which added `inspect_frame`.
Evgeny Fedorov (evgenyfedorov2)
force-pushed
the
u/efedorov/http-telemetry-pr2
branch
from
November 14, 2026 19:30
dc3d2ba to
37afc41
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds route, header and body fields to the server telemetry of
http_telemetry. The crate docs describe each field and option.route_resolver,http.routeholds the template of the route that matches the request, also as a metric dimension, andhttp.route.parameter.<name>holds each route parameter that has a data class.http.request.header.<name>andhttp.response.header.<name>hold the configured headers, redacted with their data classes.http.request.bodyandhttp.response.bodyhold the start of a body whoseContent-Typethe configured media types cover, as text, not redacted.body_size_limitsets how many bytes are logged: 32 KiB by default, 1.5 MiB at most.hyper_serverexample logs a route, a request header and JSON bodies.A follow-up PR adds client telemetry for
fetch.Changes in other crates
routerama: adds theRouteTabletrait, which lists the routes of a resolver and matches a request to one of them. Runtime resolvers and the resolvers that#[resolver]generates implement it.observed(breaking): an#[event]field marked#[flatten]adds fields whose names are known only at run time.visit_fieldsmoves fromEventandDynEventto the newVisitFieldstrait, which both extend, so a hand-writtenEventorDynEventmust also implementVisitFields.