Skip to content

Conversation

@Lms24
Copy link
Member

@Lms24 Lms24 commented Sep 9, 2025

This PR adds the http.request.time_to_first_byte attribute.

This attribute is derived from the browser'S PerformanceResourceTiming.responseStart attribute. In contrast to the the
http.request.response_start attribute, which also uses responseStart but converts the value to an absolute time stamp, this attribute keeps the time stamp relative but only converts it to seconds. The relative timestamp can be interpreted as TTFB for resource requests.

This attribute will be collected from to the browser JS SDK once getsentry/sentry-javascript#17562 is merged.

(decided to keep this separate from #130 since we might still change the value of this attribute)

@Lms24 Lms24 self-assigned this Sep 9, 2025
@lcian lcian merged commit f0f1ace into main Sep 11, 2025
5 checks passed
@lcian lcian deleted the lms/feat-http.request.ttfb branch September 11, 2025 14:57
Lms24 added a commit to getsentry/sentry-javascript that referenced this pull request Sep 12, 2025
…17562)

Adds a few attributes to `resource.*` spans for request timing
and status information. Most importantly:

- `http.request.time_to_first_byte` [from
`responseStart`](https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming/responseStart)
which can be [interpreted as
TTFB](https://web.dev/articles/ttfb#measure-resource-requests) for
resource requests. This was requested via via
getsentry/sentry#63739.
- `http.response.status_code` the status code of the resource request.
Requested in #16805 and #10995

To get these attributes, I adjusted the already existing
`resourceTimingToSpanAttributes` a bit:
- Moved it from browser to browser-utils because resource spans logic is
located in browser-utils (this is safe, it never was exported from
browser)
- Changed the signature to return an object instead of an array of
attributes. This is more ergonomical to use in both callsites and should
reduce bundle size slightly
- Added `http.request.redirect_end`, `http.request.worker_start`
attributes which are stable timing values available on
`PerformanceResourceTiming` but were previously missing
- Also added to conventions:
getsentry/sentry-conventions#130
- Added `http.request.time_to_first_byte`. Decided to add this attribute
because `http.request.response_start` cannot be directly used as TTFB as
its value is an absolute time stamp of `responseStart`. Instead the TTFB
attribute is the relative response start attribute converted to seconds
(happy to change to ms if reviewers prefer).
- Also added to conventions:
getsentry/sentry-conventions#131

Other consequences:
- `http.client` spans now also have the three additional attributes

Remarks:
- Not super happy about us always defaulting to `0` in case a value is
not present. But decided to leave this as-is to avoid any behaviour
change for http.client spans.
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.

4 participants