Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make spans for fetch() more accurate #12640

Closed
lforst opened this issue Jun 25, 2024 · 5 comments · Fixed by #12723
Closed

Make spans for fetch() more accurate #12640

lforst opened this issue Jun 25, 2024 · 5 comments · Fixed by #12723
Assignees
Labels
Feature: Spans Meta: Good First Issue Package: browser Issues related to the Sentry Browser SDK

Comments

@lforst
Copy link
Member

lforst commented Jun 25, 2024

Problem

In JS fetch() basically runs through 3 stages:

  1. fetch() is called and started
  2. fetch() resolves - generally meaning status code and response headers are returned
  3. The response body streams in (either one chunk or multiple chunks over time)

As of today, the spans we record for fetch calls only entail 1 and 2. Since the web is moving more and more towards streaming (LLMs, React Server Components, Server-Sent Events, ...), it would be quite important to also entail the response streams (3).

Solution Brainstorm

There different approaches we can take:

  • Simply extend the spans to also wait for the response body.
  • Extend the span to wait for the response body, but attach a child span that tracks the duration until the first byte (entailing 1 and 2). (see comment)
@lforst lforst added Feature: Spans Package: browser Issues related to the Sentry Browser SDK Meta: Good First Issue labels Jun 25, 2024
@lforst
Copy link
Member Author

lforst commented Jun 25, 2024

@AbhiPrasad would love to hear your thoughts on having 2 spans, one for total duration, one for time to first byte (not the web vital lol). Would this have downstream implications? I remember the the Java SDK does something similar tracking things like tcp handshake and so on.

@chargome chargome self-assigned this Jun 25, 2024
@AbhiPrasad
Copy link
Member

two spans seems fine to me!

only thing that comes to mind with two spans is which span should the sentry-trace header be generated from? We also should double check the trace view to make sure that thing render properly when you have distributed traces (fetch span is parent of a http.server span). We can fix things as need in the product, just need to ping perf team folks.

@cleptric
Copy link
Member

Could span attributes be an alternative to emitting more spans?

@lforst
Copy link
Member Author

lforst commented Jun 27, 2024

Could span attributes be an alternative to emitting more spans?

Yes that makes absolute sense. We should do it like this.

@stefanosiano
Copy link
Member

Leaving here the Java PR for reference, in case there are keys we can align on: getsentry/sentry-java#3556
tldr: we added the duration of http operations (expressed in milliseconds) as span attributes to the http.client span

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature: Spans Meta: Good First Issue Package: browser Issues related to the Sentry Browser SDK
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants