Skip to content

Commit 8530703

Browse files
author
Luca Forstner
authored
Merge branch 'develop' into lforst-backfill-v9-migration-items
2 parents 4710bdf + 91a4985 commit 8530703

File tree

21 files changed

+300
-71
lines changed

21 files changed

+300
-71
lines changed

.size-limit.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ module.exports = [
4040
path: 'packages/browser/build/npm/esm/index.js',
4141
import: createImport('init', 'browserTracingIntegration'),
4242
gzip: true,
43-
limit: '36.5 KB',
43+
limit: '37.5 KB',
4444
},
4545
{
4646
name: '@sentry/browser (incl. Tracing, Replay)',
@@ -124,7 +124,7 @@ module.exports = [
124124
import: createImport('init', 'ErrorBoundary', 'reactRouterV6BrowserTracingIntegration'),
125125
ignore: ['react/jsx-runtime'],
126126
gzip: true,
127-
limit: '39.5 KB',
127+
limit: '40.5 KB',
128128
},
129129
// Vue SDK (ESM)
130130
{
@@ -139,7 +139,7 @@ module.exports = [
139139
path: 'packages/vue/build/esm/index.js',
140140
import: createImport('init', 'browserTracingIntegration'),
141141
gzip: true,
142-
limit: '38.5 KB',
142+
limit: '39.5 KB',
143143
},
144144
// Svelte SDK (ESM)
145145
{
@@ -219,7 +219,7 @@ module.exports = [
219219
import: createImport('init'),
220220
ignore: ['$app/stores'],
221221
gzip: true,
222-
limit: '37 KB',
222+
limit: '38 KB',
223223
},
224224
// Node SDK (ESM)
225225
{

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,20 @@
44

55
## General
66

7-
- Returning `null` from `beforeSendSpan` span is deprecated.
7+
- **Returning `null` from `beforeSendSpan` span is deprecated.**
8+
- **Passing `undefined` to `tracesSampleRate` / `tracesSampler` / `enableTracing` will be handled differently in v9**
9+
10+
In v8, a setup like the following:
11+
12+
```ts
13+
Sentry.init({
14+
tracesSampleRate: undefined,
15+
});
16+
```
17+
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.
821

922
## `@sentry/utils`
1023

@@ -19,6 +32,7 @@
1932
- Deprecated `extractRequestData`. Instead manually extract relevant data off request.
2033
- Deprecated `arrayify`. No replacements.
2134
- Deprecated `memoBuilder`. No replacements.
35+
- Deprecated `getNumberOfUrlSegments`. No replacements.
2236
- Deprecated `BAGGAGE_HEADER_NAME`. No replacements.
2337
- Deprecated `makeFifoCache`. No replacements.
2438
- Deprecated `flatten`. No replacements.

packages/browser-utils/.eslintrc.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ module.exports = {
66
overrides: [
77
{
88
files: ['src/**'],
9-
rules: {
10-
'@sentry-internal/sdk/no-optional-chaining': 'off',
11-
},
9+
rules: {},
1210
},
1311
{
1412
files: ['src/metrics/**'],

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-utils/src/metrics/cls.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ export function trackClsAsStandaloneSpan(): void {
6767
setTimeout(() => {
6868
const client = getClient();
6969

70-
const unsubscribeStartNavigation = client?.on('startNavigationSpan', () => {
70+
if (!client) {
71+
return;
72+
}
73+
74+
const unsubscribeStartNavigation = client.on('startNavigationSpan', () => {
7175
_collectClsOnce();
7276
unsubscribeStartNavigation && unsubscribeStartNavigation();
7377
});
@@ -84,15 +88,15 @@ export function trackClsAsStandaloneSpan(): void {
8488
function sendStandaloneClsSpan(clsValue: number, entry: LayoutShift | undefined, pageloadSpanId: string) {
8589
DEBUG_BUILD && logger.log(`Sending CLS span (${clsValue})`);
8690

87-
const startTime = msToSec((browserPerformanceTimeOrigin || 0) + (entry?.startTime || 0));
91+
const startTime = msToSec((browserPerformanceTimeOrigin || 0) + ((entry && entry.startTime) || 0));
8892
const routeName = getCurrentScope().getScopeData().transactionName;
8993

90-
const name = entry ? htmlTreeAsString(entry.sources[0]?.node) : 'Layout shift';
94+
const name = entry ? htmlTreeAsString(entry.sources[0] && entry.sources[0].node) : 'Layout shift';
9195

9296
const attributes: SpanAttributes = dropUndefinedKeys({
9397
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.browser.cls',
9498
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'ui.webvital.cls',
95-
[SEMANTIC_ATTRIBUTE_EXCLUSIVE_TIME]: entry?.duration || 0,
99+
[SEMANTIC_ATTRIBUTE_EXCLUSIVE_TIME]: (entry && entry.duration) || 0,
96100
// attach the pageload span id to the CLS span so that we can link them in the UI
97101
'sentry.pageload.span_id': pageloadSpanId,
98102
});
@@ -104,19 +108,21 @@ function sendStandaloneClsSpan(clsValue: number, entry: LayoutShift | undefined,
104108
startTime,
105109
});
106110

107-
span?.addEvent('cls', {
108-
[SEMANTIC_ATTRIBUTE_SENTRY_MEASUREMENT_UNIT]: '',
109-
[SEMANTIC_ATTRIBUTE_SENTRY_MEASUREMENT_VALUE]: clsValue,
110-
});
111+
if (span) {
112+
span.addEvent('cls', {
113+
[SEMANTIC_ATTRIBUTE_SENTRY_MEASUREMENT_UNIT]: '',
114+
[SEMANTIC_ATTRIBUTE_SENTRY_MEASUREMENT_VALUE]: clsValue,
115+
});
111116

112-
// LayoutShift performance entries always have a duration of 0, so we don't need to add `entry.duration` here
113-
// see: https://developer.mozilla.org/en-US/docs/Web/API/PerformanceEntry/duration
114-
span?.end(startTime);
117+
// LayoutShift performance entries always have a duration of 0, so we don't need to add `entry.duration` here
118+
// see: https://developer.mozilla.org/en-US/docs/Web/API/PerformanceEntry/duration
119+
span.end(startTime);
120+
}
115121
}
116122

117123
function supportsLayoutShift(): boolean {
118124
try {
119-
return PerformanceObserver.supportedEntryTypes?.includes('layout-shift');
125+
return PerformanceObserver.supportedEntryTypes.includes('layout-shift');
120126
} catch {
121127
return false;
122128
}

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,14 @@ function _trackINP(): () => void {
112112
startTime,
113113
});
114114

115-
span?.addEvent('inp', {
116-
[SEMANTIC_ATTRIBUTE_SENTRY_MEASUREMENT_UNIT]: 'millisecond',
117-
[SEMANTIC_ATTRIBUTE_SENTRY_MEASUREMENT_VALUE]: metric.value,
118-
});
115+
if (span) {
116+
span.addEvent('inp', {
117+
[SEMANTIC_ATTRIBUTE_SENTRY_MEASUREMENT_UNIT]: 'millisecond',
118+
[SEMANTIC_ATTRIBUTE_SENTRY_MEASUREMENT_VALUE]: metric.value,
119+
});
119120

120-
span?.end(startTime + duration);
121+
span.end(startTime + duration);
122+
}
121123
});
122124
}
123125

packages/browser-utils/src/metrics/web-vitals/getINP.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ const processEntry = (entry: PerformanceEventTiming) => {
6666
// The least-long of the 10 longest interactions.
6767
const minLongestInteraction = longestInteractionList[longestInteractionList.length - 1];
6868

69-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
7069
const existingInteraction = longestInteractionMap[entry.interactionId!];
7170

7271
// Only process the entry if it's possibly one of the ten longest,
@@ -82,7 +81,6 @@ const processEntry = (entry: PerformanceEventTiming) => {
8281
existingInteraction.latency = Math.max(existingInteraction.latency, entry.duration);
8382
} else {
8483
const interaction = {
85-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
8684
id: entry.interactionId!,
8785
latency: entry.duration,
8886
entries: [entry],

packages/browser-utils/test/utils/TestClient.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@ export class TestClient extends BaseClient<TestClientOptions> {
2020
exception: {
2121
values: [
2222
{
23-
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
2423
type: exception.name,
2524
value: exception.message,
26-
/* eslint-enable @typescript-eslint/no-unsafe-member-access */
2725
},
2826
],
2927
},

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');

0 commit comments

Comments
 (0)