Skip to content

Ensure browser traceId lifetime works as expected #11599

@Lms24

Description

@Lms24

Problem Statement

In v7, traces in browser SDKs had a bit of a weird lifetime and behavior:

  • We created new traces for pageload and navigation transactions as well as for custom (user-created) transactions by default.
  • Due to "Tracing w/o Performance" and the introduction of the propagation context, we'd attach traceIds to outgoing requests or non-transaction Sentry events that used a fallback traceId. This traceId would remain valid over the entire host application lifecycle (i.e. until a hard page reload and across browser navigations/URL changes/history changes). This resulted in "orphaned" traces where the fallback trace would potentially collect 100s of events that had nothing to do with each other.

With v8, we're changing the validity and lifetime of a single trace: It'll remain consistent and valid per route. This means:

  • on initial pageleoad, we create a new propagation context (i.e. traceId) and keep it valid, even when the pageload root span ended.
  • on subsequent browser-based navigations, we update the propagation context and keep it valid, even when the navigation root span ended.
  • All events happening within one route (i.e. URL state, browser history state, SPA route, etc) are associated with the trace from the propagation context. This means, the fallback trace from v7 should no longer exist and "orphaned" events/requests should always be associated with the last pageload or navigation trace.

Solution Brainstorm

We already did most of the work in #11377 but identified a lack of tests to cover scenarios. This issue tracks all scenarios we should test as well as potential issues we identify and fix along the way.

### Scenarios
- [x] multiple subsequent navigations have different traceIds (via https://github.com/getsentry/sentry-javascript/pull/11401)
- [x] pageload and subsequent navigation have different traceIds (via #11600)
- [x] error after pageload has pageload traceId (via #11600)
- [ ] https://github.com/getsentry/sentry-javascript/pull/11601
- [x] error during navigation has navigation traceId (https://github.com/getsentry/sentry-javascript/pull/11610)
- [x] error during pageload has pageload traceId (https://github.com/getsentry/sentry-javascript/pull/11610)
- [x] outgoing fetch requests have correct traceId (https://github.com/getsentry/sentry-javascript/pull/11614)
- [ ] https://github.com/getsentry/sentry-javascript/pull/11622
- [x] outgiong xhr requests have correct traceid (https://github.com/getsentry/sentry-javascript/pull/11624)
- [ ] https://github.com/getsentry/sentry-javascript/pull/11636
- [ ] https://github.com/getsentry/sentry-javascript/pull/11660
- [x] [BLOCKED] feedback events have correct traceId (https://github.com/getsentry/sentry-javascript/pull/11626)
### Fixes
- [ ] https://github.com/getsentry/sentry-javascript/pull/11600
- [ ] https://github.com/getsentry/sentry-javascript/pull/11631
- [ ] https://github.com/getsentry/sentry-javascript/pull/11679

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions