Skip to content

Commit 0496899

Browse files
authored
Merge branch 'develop' into timfish/feat/getExecutionContext
2 parents 9600d66 + 23e3783 commit 0496899

File tree

36 files changed

+637
-405
lines changed

36 files changed

+637
-405
lines changed
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
fail-on-severity: 'high'
22
allow-ghsas:
33
# dependency review does not allow specific file exclusions
4-
# we use an older version of NextJS in our tests and thus need to
4+
# we use an older version of NextJS in our tests and thus need to
55
# exclude this
66
# once our minimum supported version is over 14.1.1 this can be removed
77
- GHSA-fr5h-rqp8-mj6g
8+
# we need this for an E2E test for the minimum required version of Nuxt 3.7.0
9+
- GHSA-v784-fjjh-f8r4

.size-limit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ module.exports = [
132132
path: 'packages/vue/build/esm/index.js',
133133
import: createImport('init'),
134134
gzip: true,
135-
limit: '28 KB',
135+
limit: '29 KB',
136136
},
137137
{
138138
name: '@sentry/vue (incl. Tracing)',

dev-packages/browser-integration-tests/suites/integrations/ContextLines/noAddedLines/test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ sentryTest('should not add source context lines to errors from script files', as
77
const url = await getLocalTestUrl({ testDir: __dirname });
88

99
const eventReqPromise = waitForErrorRequestOnUrl(page, url);
10+
await page.waitForFunction('window.Sentry');
1011

1112
const clickPromise = page.locator('#script-error-btn').click();
1213

dev-packages/e2e-tests/test-applications/nuxt-3-min/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nuxt-3-min",
3-
"description": "E2E test app for the minimum nuxt 3 version our nuxt SDK supports.",
3+
"description": "E2E test app for the minimum Nuxt 3 version our Nuxt SDK supports.",
44
"private": true,
55
"type": "module",
66
"scripts": {
@@ -16,15 +16,15 @@
1616
},
1717
"dependencies": {
1818
"@sentry/nuxt": "latest || *",
19-
"nuxt": "3.13.2"
19+
"nuxt": "3.7.0"
2020
},
2121
"devDependencies": {
2222
"@nuxt/test-utils": "^3.14.1",
2323
"@playwright/test": "^1.44.1",
2424
"@sentry-internal/test-utils": "link:../../../test-utils"
2525
},
2626
"overrides": {
27-
"nitropack": "2.9.7",
28-
"@vercel/nft": "^0.27.4"
27+
"nitropack": "2.10.0",
28+
"ofetch": "1.4.0"
2929
}
3030
}

dev-packages/e2e-tests/test-applications/nuxt-3/package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,11 @@
1515
},
1616
"dependencies": {
1717
"@sentry/nuxt": "latest || *",
18-
"nuxt": "^3.13.1"
18+
"nuxt": "^3.14.0"
1919
},
2020
"devDependencies": {
2121
"@nuxt/test-utils": "^3.14.1",
2222
"@playwright/test": "^1.44.1",
2323
"@sentry-internal/test-utils": "link:../../../test-utils"
24-
},
25-
"overrides": {
26-
"@vercel/nft": "0.27.4"
2724
}
2825
}

docs/migration/draft-v9-migration-guide.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,20 @@
44

55
## General
66

7+
- **Returning `null` from `beforeSendSpan` span is deprecated.**
78
- **Passing `undefined` to `tracesSampleRate` / `tracesSampler` / `enableTracing` will be handled differently in v9**
89

9-
In v8, a setup like the following:
10+
In v8, a setup like the following:
1011

11-
```ts
12-
Sentry.init({
13-
tracesSampleRate: undefined,
14-
});
15-
```
12+
```ts
13+
Sentry.init({
14+
tracesSampleRate: undefined,
15+
});
16+
```
1617

17-
Will result in tracing being _enabled_, although no spans will be generated.
18-
In v9, we will streamline this behavior so that passing `undefined` will result in tracing being disabled, the same as not passing the option at all.
19-
If you are relying on `undefined` being passed in and having tracing enabled because of this, you should update your config to set e.g. `tracesSampleRate: 0` instead, which will also enable tracing in v9.
18+
Will result in tracing being _enabled_, although no spans will be generated.
19+
In v9, we will streamline this behavior so that passing `undefined` will result in tracing being disabled, the same as not passing the option at all.
20+
If you are relying on `undefined` being passed in and having tracing enabled because of this, you should update your config to set e.g. `tracesSampleRate: 0` instead, which will also enable tracing in v9.
2021

2122
## `@sentry/utils`
2223

@@ -31,6 +32,7 @@ If you are relying on `undefined` being passed in and having tracing enabled bec
3132
- Deprecated `extractRequestData`. Instead manually extract relevant data off request.
3233
- Deprecated `arrayify`. No replacements.
3334
- Deprecated `memoBuilder`. No replacements.
35+
- Deprecated `getNumberOfUrlSegments`. No replacements.
3436
- Deprecated `BAGGAGE_HEADER_NAME`. No replacements.
3537
- Deprecated `makeFifoCache`. No replacements.
3638
- Deprecated `flatten`. No replacements.
@@ -40,6 +42,7 @@ If you are relying on `undefined` being passed in and having tracing enabled bec
4042
- Deprecated `transactionNamingScheme` option in `requestDataIntegration`.
4143
- Deprecated `debugIntegration`. To log outgoing events, use [Hook Options](https://docs.sentry.io/platforms/javascript/configuration/options/#hooks) (`beforeSend`, `beforeSendTransaction`, ...).
4244
- Deprecated `sessionTimingIntegration`. To capture session durations alongside events, use [Context](https://docs.sentry.io/platforms/javascript/enriching-events/context/) (`Sentry.setContext()`).
45+
- Deprecated `addTracingHeadersToFetchRequest` method - this was only meant for internal use and is not needed anymore.
4346

4447
## `@sentry/nestjs`
4548

packages/browser-utils/src/metrics/browserMetrics.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
/* eslint-disable max-lines */
22
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, getActiveSpan } from '@sentry/core';
33
import { setMeasurement } from '@sentry/core';
4-
import { browserPerformanceTimeOrigin, getComponentName, htmlTreeAsString, logger, parseUrl } from '@sentry/core';
4+
import { browserPerformanceTimeOrigin, getComponentName, htmlTreeAsString, parseUrl } from '@sentry/core';
55
import type { Measurements, Span, SpanAttributes, StartSpanOptions } from '@sentry/types';
66

77
import { spanToJSON } from '@sentry/core';
8-
import { DEBUG_BUILD } from '../debug-build';
98
import { WINDOW } from '../types';
109
import { trackClsAsStandaloneSpan } from './cls';
1110
import {
@@ -241,7 +240,6 @@ function _trackCLS(): () => void {
241240
if (!entry) {
242241
return;
243242
}
244-
DEBUG_BUILD && logger.log(`[Measurements] Adding CLS ${metric.value}`);
245243
_measurements['cls'] = { value: metric.value, unit: '' };
246244
_clsEntry = entry;
247245
}, true);
@@ -255,7 +253,6 @@ function _trackLCP(): () => void {
255253
return;
256254
}
257255

258-
DEBUG_BUILD && logger.log('[Measurements] Adding LCP');
259256
_measurements['lcp'] = { value: metric.value, unit: 'millisecond' };
260257
_lcpEntry = entry as LargestContentfulPaint;
261258
}, true);
@@ -271,7 +268,6 @@ function _trackFID(): () => void {
271268

272269
const timeOrigin = msToSec(browserPerformanceTimeOrigin as number);
273270
const startTime = msToSec(entry.startTime);
274-
DEBUG_BUILD && logger.log('[Measurements] Adding FID');
275271
_measurements['fid'] = { value: metric.value, unit: 'millisecond' };
276272
_measurements['mark.fid'] = { value: timeOrigin + startTime, unit: 'second' };
277273
});
@@ -284,7 +280,6 @@ function _trackTtfb(): () => void {
284280
return;
285281
}
286282

287-
DEBUG_BUILD && logger.log('[Measurements] Adding TTFB');
288283
_measurements['ttfb'] = { value: metric.value, unit: 'millisecond' };
289284
});
290285
}
@@ -305,7 +300,6 @@ export function addPerformanceEntries(span: Span, options: AddPerformanceEntries
305300
return;
306301
}
307302

308-
DEBUG_BUILD && logger.log('[Tracing] Adding & adjusting spans using Performance API');
309303
const timeOrigin = msToSec(browserPerformanceTimeOrigin);
310304

311305
const performanceEntries = performance.getEntries();
@@ -343,11 +337,9 @@ export function addPerformanceEntries(span: Span, options: AddPerformanceEntries
343337
const shouldRecord = entry.startTime < firstHidden.firstHiddenTime;
344338

345339
if (entry.name === 'first-paint' && shouldRecord) {
346-
DEBUG_BUILD && logger.log('[Measurements] Adding FP');
347340
_measurements['fp'] = { value: entry.startTime, unit: 'millisecond' };
348341
}
349342
if (entry.name === 'first-contentful-paint' && shouldRecord) {
350-
DEBUG_BUILD && logger.log('[Measurements] Adding FCP');
351343
_measurements['fcp'] = { value: entry.startTime, unit: 'millisecond' };
352344
}
353345
break;
@@ -618,8 +610,6 @@ function _trackNavigator(span: Span): void {
618610
/** Add LCP / CLS data to span to allow debugging */
619611
function _setWebVitalAttributes(span: Span): void {
620612
if (_lcpEntry) {
621-
DEBUG_BUILD && logger.log('[Measurements] Adding LCP Data');
622-
623613
// Capture Properties of the LCP element that contributes to the LCP.
624614

625615
if (_lcpEntry.element) {
@@ -652,7 +642,6 @@ function _setWebVitalAttributes(span: Span): void {
652642

653643
// See: https://developer.mozilla.org/en-US/docs/Web/API/LayoutShift
654644
if (_clsEntry && _clsEntry.sources) {
655-
DEBUG_BUILD && logger.log('[Measurements] Adding CLS Data');
656645
_clsEntry.sources.forEach((source, index) =>
657646
span.setAttribute(`cls.source.${index + 1}`, htmlTreeAsString(source.node)),
658647
);
@@ -685,7 +674,6 @@ function _addTtfbRequestTimeToMeasurements(_measurements: Measurements): void {
685674
const { responseStart, requestStart } = navEntry;
686675

687676
if (requestStart <= responseStart) {
688-
DEBUG_BUILD && logger.log('[Measurements] Adding TTFB Request Time');
689677
_measurements['ttfb.requestTime'] = {
690678
value: responseStart - requestStart,
691679
unit: 'millisecond',

packages/browser/src/integrations/httpclient.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ function _parseCookieHeaders(
108108
if (cookieString) {
109109
cookies = _parseCookieString(cookieString);
110110
}
111-
} catch (e) {
112-
DEBUG_BUILD && logger.log(`Could not extract cookies from header ${cookieHeader}`);
111+
} catch {
112+
// ignore it if parsing fails
113113
}
114114

115115
return [headers, cookies];
@@ -138,14 +138,14 @@ function _xhrResponseHandler(
138138
if (cookieString) {
139139
responseCookies = _parseCookieString(cookieString);
140140
}
141-
} catch (e) {
142-
DEBUG_BUILD && logger.log('Could not extract cookies from response headers');
141+
} catch {
142+
// ignore it if parsing fails
143143
}
144144

145145
try {
146146
responseHeaders = _getXHRResponseHeaders(xhr);
147-
} catch (e) {
148-
DEBUG_BUILD && logger.log('Could not extract headers from response');
147+
} catch {
148+
// ignore it if parsing fails
149149
}
150150

151151
requestHeaders = headers;

packages/browser/src/tracing/browserTracingIntegration.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -299,16 +299,20 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
299299
let activeSpan: Span | undefined;
300300
let startingUrl: string | undefined = WINDOW.location && WINDOW.location.href;
301301

302+
function maybeEndActiveSpan(): void {
303+
if (activeSpan && !spanToJSON(activeSpan).timestamp) {
304+
DEBUG_BUILD && logger.log(`[Tracing] Finishing current active span with op: ${spanToJSON(activeSpan).op}`);
305+
// If there's an open active span, we need to finish it before creating an new one.
306+
activeSpan.end();
307+
}
308+
}
309+
302310
client.on('startNavigationSpan', startSpanOptions => {
303311
if (getClient() !== client) {
304312
return;
305313
}
306314

307-
if (activeSpan && !spanToJSON(activeSpan).timestamp) {
308-
DEBUG_BUILD && logger.log(`[Tracing] Finishing current root span with op: ${spanToJSON(activeSpan).op}`);
309-
// If there's an open transaction on the scope, we need to finish it before creating an new one.
310-
activeSpan.end();
311-
}
315+
maybeEndActiveSpan();
312316

313317
activeSpan = _createRouteSpan(client, {
314318
op: 'navigation',
@@ -320,12 +324,7 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
320324
if (getClient() !== client) {
321325
return;
322326
}
323-
324-
if (activeSpan && !spanToJSON(activeSpan).timestamp) {
325-
DEBUG_BUILD && logger.log(`[Tracing] Finishing current root span with op: ${spanToJSON(activeSpan).op}`);
326-
// If there's an open transaction on the scope, we need to finish it before creating an new one.
327-
activeSpan.end();
328-
}
327+
maybeEndActiveSpan();
329328

330329
const sentryTrace = traceOptions.sentryTrace || getMetaContent('sentry-trace');
331330
const baggage = traceOptions.baggage || getMetaContent('baggage');

packages/browser/src/tracing/request.ts

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,17 @@ import {
99
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
1010
SentryNonRecordingSpan,
1111
getActiveSpan,
12-
getClient,
13-
getCurrentScope,
14-
getDynamicSamplingContextFromClient,
15-
getDynamicSamplingContextFromSpan,
16-
getIsolationScope,
12+
getTraceData,
1713
hasTracingEnabled,
1814
instrumentFetchRequest,
1915
setHttpStatus,
2016
spanToJSON,
21-
spanToTraceHeader,
2217
startInactiveSpan,
2318
} from '@sentry/core';
2419
import {
2520
addFetchEndInstrumentationHandler,
2621
addFetchInstrumentationHandler,
2722
browserPerformanceTimeOrigin,
28-
dynamicSamplingContextToSentryBaggageHeader,
29-
generateSentryTraceHeader,
3023
parseUrl,
3124
stringMatchesSomePattern,
3225
} from '@sentry/core';
@@ -76,15 +69,17 @@ export interface RequestInstrumentationOptions {
7669
*
7770
* Default: true
7871
*/
79-
traceXHR: boolean /**
72+
traceXHR: boolean;
73+
74+
/**
8075
* Flag to disable tracking of long-lived streams, like server-sent events (SSE) via fetch.
8176
* Do not enable this in case you have live streams or very long running streams.
8277
*
8378
* Disabled by default since it can lead to issues with streams using the `cancel()` api
8479
* (https://github.com/getsentry/sentry-javascript/issues/13950)
8580
*
8681
* Default: false
87-
*/;
82+
*/
8883
trackFetchStreamPerformance: boolean;
8984

9085
/**
@@ -401,12 +396,9 @@ export function xhrCallback(
401396
xhr.__sentry_xhr_span_id__ = span.spanContext().spanId;
402397
spans[xhr.__sentry_xhr_span_id__] = span;
403398

404-
const client = getClient();
405-
406-
if (xhr.setRequestHeader && shouldAttachHeaders(sentryXhrData.url) && client) {
399+
if (shouldAttachHeaders(sentryXhrData.url)) {
407400
addTracingHeadersToXhrRequest(
408401
xhr,
409-
client,
410402
// If performance is disabled (TWP) or there's no active root span (pageload/navigation/interaction),
411403
// we do not want to use the span as base for the trace headers,
412404
// which means that the headers will be generated from the scope and the sampling decision is deferred
@@ -417,22 +409,12 @@ export function xhrCallback(
417409
return span;
418410
}
419411

420-
function addTracingHeadersToXhrRequest(xhr: SentryWrappedXMLHttpRequest, client: Client, span?: Span): void {
421-
const scope = getCurrentScope();
422-
const isolationScope = getIsolationScope();
423-
const { traceId, spanId, sampled, dsc } = {
424-
...isolationScope.getPropagationContext(),
425-
...scope.getPropagationContext(),
426-
};
412+
function addTracingHeadersToXhrRequest(xhr: SentryWrappedXMLHttpRequest, span?: Span): void {
413+
const { 'sentry-trace': sentryTrace, baggage } = getTraceData({ span });
427414

428-
const sentryTraceHeader =
429-
span && hasTracingEnabled() ? spanToTraceHeader(span) : generateSentryTraceHeader(traceId, spanId, sampled);
430-
431-
const sentryBaggageHeader = dynamicSamplingContextToSentryBaggageHeader(
432-
dsc || (span ? getDynamicSamplingContextFromSpan(span) : getDynamicSamplingContextFromClient(traceId, client)),
433-
);
434-
435-
setHeaderOnXhr(xhr, sentryTraceHeader, sentryBaggageHeader);
415+
if (sentryTrace) {
416+
setHeaderOnXhr(xhr, sentryTrace, baggage);
417+
}
436418
}
437419

438420
function setHeaderOnXhr(

0 commit comments

Comments
 (0)