Skip to content

Commit 362cec5

Browse files
committed
ref(replay): Hide internal request tracing behind experiments flag
1 parent b8598c0 commit 362cec5

File tree

5 files changed

+34
-33
lines changed

5 files changed

+34
-33
lines changed

packages/replay/src/coreHandlers/handleFetch.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { ReplayPerformanceEntry } from '../createPerformanceEntry';
22
import type { ReplayContainer } from '../types';
33
import { createPerformanceSpans } from '../util/createPerformanceSpans';
4-
import { isIngestHost } from '../util/isIngestHost';
4+
import { shouldFilterRequest } from '../util/shouldFilterRequest';
55

66
interface FetchHandlerData {
77
args: Parameters<typeof fetch>;
@@ -28,11 +28,6 @@ export function handleFetch(handlerData: FetchHandlerData): null | ReplayPerform
2828

2929
const { startTimestamp, endTimestamp, fetchData, response } = handlerData;
3030

31-
// Do not capture fetches to Sentry ingestion endpoint
32-
if (isIngestHost(fetchData.url)) {
33-
return null;
34-
}
35-
3631
return {
3732
type: 'resource.fetch',
3833
start: startTimestamp / 1000,
@@ -60,6 +55,10 @@ export function handleFetchSpanListener(replay: ReplayContainer): (handlerData:
6055
return;
6156
}
6257

58+
if (shouldFilterRequest(replay, result.name)) {
59+
return;
60+
}
61+
6362
replay.addUpdate(() => {
6463
createPerformanceSpans(replay, [result]);
6564
// Returning true will cause `addUpdate` to not flush

packages/replay/src/coreHandlers/handleXhr.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ReplayPerformanceEntry } from '../createPerformanceEntry';
22
import type { ReplayContainer } from '../types';
33
import { createPerformanceSpans } from '../util/createPerformanceSpans';
4-
import { isIngestHost } from '../util/isIngestHost';
4+
import { shouldFilterRequest } from '../util/shouldFilterRequest';
55

66
// From sentry-javascript
77
// e.g. https://github.com/getsentry/sentry-javascript/blob/c7fc025bf9fa8c073fdb56351808ce53909fbe45/packages/utils/src/instrument.ts#L180
@@ -47,8 +47,7 @@ function handleXhr(handlerData: XhrHandlerData): ReplayPerformanceEntry | null {
4747

4848
const { method, url, status_code: statusCode } = handlerData.xhr.__sentry_xhr__ || {};
4949

50-
// Do not capture fetches to Sentry ingestion endpoint
51-
if (url === undefined || isIngestHost(url)) {
50+
if (url === undefined) {
5251
return null;
5352
}
5453

@@ -79,6 +78,10 @@ export function handleXhrSpanListener(replay: ReplayContainer): (handlerData: Xh
7978
return;
8079
}
8180

81+
if (shouldFilterRequest(replay, result.name)) {
82+
return;
83+
}
84+
8285
replay.addUpdate(() => {
8386
createPerformanceSpans(replay, [result]);
8487
// Returning true will cause `addUpdate` to not flush

packages/replay/src/createPerformanceEntry.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { record } from 'rrweb';
33

44
import { WINDOW } from './constants';
55
import type { AllPerformanceEntry, PerformanceNavigationTiming, PerformancePaintTiming } from './types';
6-
import { isIngestHost } from './util/isIngestHost';
76

87
export interface ReplayPerformanceEntry {
98
/**
@@ -110,11 +109,6 @@ function createNavigationEntry(entry: PerformanceNavigationTiming) {
110109
function createResourceEntry(entry: PerformanceResourceTiming) {
111110
const { entryType, initiatorType, name, responseEnd, startTime, encodedBodySize, transferSize } = entry;
112111

113-
// Do not capture fetches to Sentry ingestion endpoint
114-
if (isIngestHost(name)) {
115-
return null;
116-
}
117-
118112
// Core SDK handles these
119113
if (['fetch', 'xmlhttprequest'].includes(initiatorType)) {
120114
return null;

packages/replay/src/util/isIngestHost.ts

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { getCurrentHub } from '@sentry/core';
2+
3+
import type { ReplayContainer } from '../types';
4+
5+
/**
6+
* Check whether a given request URL should be filtered out.
7+
*/
8+
export function shouldFilterRequest(replay: ReplayContainer, url: string): boolean {
9+
// If we enabled the `traceInternals` experiment, we want to trace everything
10+
if (__DEBUG_BUILD__ && replay.getOptions()._experiments?.traceInternals) {
11+
return false;
12+
}
13+
14+
return !_isSentryRequest(url);
15+
}
16+
17+
/**
18+
* Checks wether a given URL belongs to the configured Sentry DSN.
19+
*/
20+
function _isSentryRequest(url: string): boolean {
21+
const dsn = getCurrentHub().getClient()?.getDsn();
22+
return dsn ? url.includes(dsn.host) : false;
23+
}

0 commit comments

Comments
 (0)