Skip to content

Conversation

logaretm
Copy link
Collaborator

@logaretm logaretm commented Oct 7, 2025

This PR aims to address #9643 partially by introducing a onRequestSpanEnd hook to the browser integration. These changes make it easier for users to enrich tracing spans with response header data.

Example

import * as Sentry from '@sentry/browser';

Sentry.init({
  // ...
  integrations: [
    Sentry.browserTracingIntegration({
      onRequestSpanEnd(span, responseInformation) {
        span.setAttributes({
          response_type: 'JSON',
        });
      },
    }),
  ],
});

Tracing Integration and API Improvements

  • Added onRequestSpanEnd callback to BrowserTracingOptions and RequestInstrumentationOptions, allowing users to access response headers when a request span ends. This enables custom span annotation based on response data.
  • Updated internal request instrumentation logic to call onRequestSpanEnd for both Fetch and XHR requests, passing parsed response headers to the callback.

Utility and Refactoring

  • Centralized header parsing and filtering utilities (parseXhrResponseHeaders, getFetchResponseHeaders, filterAllowedHeaders) in networkUtils.ts, and exported them for reuse across packages.
  • Moved helper functions for baggage header checking, URL resolution, performance timing checks, and safe header creation to a new utils.ts file to avoid failing the file size limit lint rule.

I was hesitant to hoist up those replay utils initially but a few of them were needed to expose them on the hook callback.

Type and API Consistency

  • Introduced new types RequestHookInfo and ResponseHookInfo to standardize the information passed to request span hooks, and exported them from the core package for use in integrations.

I also added the necessary tests to test out the new hook.

Copy link

linear bot commented Oct 7, 2025

Copy link
Contributor

github-actions bot commented Oct 7, 2025

size-limit report 📦

Path Size % Change Change
@sentry/browser 24.26 kB - -
@sentry/browser - with treeshaking flags 22.77 kB - -
@sentry/browser (incl. Tracing) 40.59 kB +0.37% +149 B 🔺
@sentry/browser (incl. Tracing, Replay) 78.91 kB +0.12% +87 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 68.55 kB +0.12% +78 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 83.61 kB +0.13% +108 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 95.77 kB +0.09% +77 B 🔺
@sentry/browser (incl. Feedback) 40.97 kB - -
@sentry/browser (incl. sendFeedback) 28.91 kB - -
@sentry/browser (incl. FeedbackAsync) 33.84 kB -0.01% -1 B 🔽
@sentry/react 25.98 kB - -
@sentry/react (incl. Tracing) 42.56 kB +0.35% +146 B 🔺
@sentry/vue 28.77 kB - -
@sentry/vue (incl. Tracing) 42.41 kB +0.36% +151 B 🔺
@sentry/svelte 24.29 kB - -
CDN Bundle 25.77 kB - -
CDN Bundle (incl. Tracing) 40.45 kB +0.29% +113 B 🔺
CDN Bundle (incl. Tracing, Replay) 76.65 kB +0.09% +66 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 82.17 kB +0.11% +89 B 🔺
CDN Bundle - uncompressed 75.35 kB - -
CDN Bundle (incl. Tracing) - uncompressed 119.79 kB +0.37% +433 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 234.82 kB +0.13% +298 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 247.58 kB +0.13% +298 B 🔺
@sentry/nextjs (client) 44.58 kB +0.35% +153 B 🔺
@sentry/sveltekit (client) 41.02 kB +0.38% +152 B 🔺
@sentry/node-core 50.56 kB - -
@sentry/node 154.19 kB +0.01% +1 B 🔺
@sentry/node - without tracing 92.42 kB +0.01% +1 B 🔺
@sentry/aws-serverless 106.14 kB +0.01% +1 B 🔺

View base workflow run

Copy link
Contributor

github-actions bot commented Oct 7, 2025

node-overhead report 🧳

Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.

Scenario Requests/s % of Baseline Prev. Requests/s Change %
GET Baseline 8,833 - 8,994 -2%
GET With Sentry 1,317 15% 1,430 -8%
GET With Sentry (error only) 6,017 68% 6,248 -4%
POST Baseline 1,183 - 1,205 -2%
POST With Sentry 513 43% 555 -8%
POST With Sentry (error only) 1,044 88% 1,068 -2%
MYSQL Baseline 3,293 - 3,329 -1%
MYSQL With Sentry 434 13% 505 -14%
MYSQL With Sentry (error only) 2,702 82% 2,716 -1%

View base workflow run

@logaretm logaretm marked this pull request as ready for review October 8, 2025 10:30
@logaretm logaretm requested a review from a team as a code owner October 8, 2025 10:30
@logaretm logaretm requested a review from Lms24 October 8, 2025 10:30
cursor[bot]

This comment was marked as outdated.

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.

1 participant