Skip to content

Commit 836da3a

Browse files
authored
Merge branch 'develop' into develop
2 parents 022186b + b59ce07 commit 836da3a

File tree

31 files changed

+627
-394
lines changed

31 files changed

+627
-394
lines changed

.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

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(

packages/core/src/baseclient.ts

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,22 @@ import type {
3232
} from '@sentry/types';
3333

3434
import { getEnvelopeEndpointWithUrlEncodedAuth } from './api';
35-
import { getIsolationScope } from './currentScopes';
35+
import { getCurrentScope, getIsolationScope, getTraceContextFromScope } from './currentScopes';
3636
import { DEBUG_BUILD } from './debug-build';
3737
import { createEventEnvelope, createSessionEnvelope } from './envelope';
3838
import type { IntegrationIndex } from './integration';
3939
import { afterSetupIntegrations } from './integration';
4040
import { setupIntegration, setupIntegrations } from './integration';
4141
import type { Scope } from './scope';
4242
import { updateSession } from './session';
43-
import { getDynamicSamplingContextFromClient } from './tracing/dynamicSamplingContext';
43+
import { getDynamicSamplingContextFromScope } from './tracing/dynamicSamplingContext';
4444
import { createClientReportEnvelope } from './utils-hoist/clientreport';
4545
import { dsnToString, makeDsn } from './utils-hoist/dsn';
4646
import { addItemToEnvelope, createAttachmentEnvelopeItem } from './utils-hoist/envelope';
4747
import { SentryError } from './utils-hoist/error';
4848
import { isParameterizedString, isPlainObject, isPrimitive, isThenable } from './utils-hoist/is';
4949
import { consoleSandbox, logger } from './utils-hoist/logger';
5050
import { checkOrSetAlreadyCaught, uuid4 } from './utils-hoist/misc';
51-
import { dropUndefinedKeys } from './utils-hoist/object';
5251
import { SyncPromise, rejectedSyncPromise, resolvedSyncPromise } from './utils-hoist/syncpromise';
5352
import { parseSampleRate } from './utils/parseSampleRate';
5453
import { prepareEvent } from './utils/prepareEvent';
@@ -672,7 +671,7 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
672671
protected _prepareEvent(
673672
event: Event,
674673
hint: EventHint,
675-
currentScope?: Scope,
674+
currentScope = getCurrentScope(),
676675
isolationScope = getIsolationScope(),
677676
): PromiseLike<Event | null> {
678677
const options = this.getOptions();
@@ -692,30 +691,18 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
692691
return evt;
693692
}
694693

695-
const propagationContext = {
696-
...isolationScope.getPropagationContext(),
697-
...(currentScope ? currentScope.getPropagationContext() : undefined),
694+
evt.contexts = {
695+
trace: getTraceContextFromScope(currentScope),
696+
...evt.contexts,
698697
};
699698

700-
const trace = evt.contexts && evt.contexts.trace;
701-
if (!trace && propagationContext) {
702-
const { traceId: trace_id, spanId, parentSpanId, dsc } = propagationContext;
703-
evt.contexts = {
704-
trace: dropUndefinedKeys({
705-
trace_id,
706-
span_id: spanId,
707-
parent_span_id: parentSpanId,
708-
}),
709-
...evt.contexts,
710-
};
699+
const dynamicSamplingContext = getDynamicSamplingContextFromScope(this, currentScope);
711700

712-
const dynamicSamplingContext = dsc ? dsc : getDynamicSamplingContextFromClient(trace_id, this);
701+
evt.sdkProcessingMetadata = {
702+
dynamicSamplingContext,
703+
...evt.sdkProcessingMetadata,
704+
};
713705

714-
evt.sdkProcessingMetadata = {
715-
dynamicSamplingContext,
716-
...evt.sdkProcessingMetadata,
717-
};
718-
}
719706
return evt;
720707
});
721708
}

0 commit comments

Comments
 (0)