Skip to content

Commit 0916dc3

Browse files
committed
move functionality to replay
1 parent 702a05d commit 0916dc3

File tree

25 files changed

+92
-76
lines changed

25 files changed

+92
-76
lines changed

packages/browser-integration-tests/suites/integrations/ExtendedNetworkBreadcrumbs/fetch/init.js

-11
This file was deleted.

packages/browser-integration-tests/suites/integrations/ExtendedNetworkBreadcrumbs/xhr/init.js

-11
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const xhr = new XMLHttpRequest();
2-
31
fetch('http://localhost:7654/foo', {
42
headers: {
53
Accept: 'application/json',
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@ import type { Event } from '@sentry/types';
33

44
import { sentryTest } from '../../../../../utils/fixtures';
55
import { getFirstSentryEnvelopeRequest } from '../../../../../utils/helpers';
6+
import { shouldSkipReplayTest } from '../../../../../utils/replayHelpers';
67

78
sentryTest('parses response_body_size from Content-Length header if available', async ({ getLocalTestPath, page }) => {
9+
if (shouldSkipReplayTest()) {
10+
sentryTest.skip();
11+
}
12+
813
const url = await getLocalTestPath({ testDir: __dirname });
914

1015
await page.route('**/foo', route => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import * as Sentry from '@sentry/browser';
2+
3+
window.Sentry = Sentry;
4+
window.Replay = new Sentry.Replay({
5+
flushMinDelay: 200,
6+
flushMaxDelay: 200,
7+
});
8+
9+
Sentry.init({
10+
dsn: 'https://[email protected]/1337',
11+
sampleRate: 1,
12+
// We ensure to sample for errors, so by default nothing is sent
13+
replaysSessionSampleRate: 0.0,
14+
replaysOnErrorSampleRate: 1.0,
15+
16+
integrations: [window.Replay],
17+
});
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const xhr = new XMLHttpRequest();
2-
31
fetch('http://localhost:7654/foo', {
42
headers: {
53
Accept: 'application/json',
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@ import type { Event } from '@sentry/types';
33

44
import { sentryTest } from '../../../../../utils/fixtures';
55
import { getFirstSentryEnvelopeRequest } from '../../../../../utils/helpers';
6+
import { shouldSkipReplayTest } from '../../../../../utils/replayHelpers';
67

78
sentryTest('does not capture response_body_size without Content-Length header', async ({ getLocalTestPath, page }) => {
9+
if (shouldSkipReplayTest()) {
10+
sentryTest.skip();
11+
}
12+
813
const url = await getLocalTestPath({ testDir: __dirname });
914

1015
await page.route('**/foo', route => {
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const xhr = new XMLHttpRequest();
2-
31
const blob = new Blob(['<html>Hello world!!</html>'], { type: 'text/html' });
42

53
fetch('http://localhost:7654/foo', {
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@ import type { Event } from '@sentry/types';
33

44
import { sentryTest } from '../../../../../utils/fixtures';
55
import { getFirstSentryEnvelopeRequest } from '../../../../../utils/helpers';
6+
import { shouldSkipReplayTest } from '../../../../../utils/replayHelpers';
67

78
sentryTest('calculates body sizes for non-string bodies', async ({ getLocalTestPath, page }) => {
9+
if (shouldSkipReplayTest()) {
10+
sentryTest.skip();
11+
}
12+
813
const url = await getLocalTestPath({ testDir: __dirname });
914

1015
await page.route('**/foo', async route => {
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const xhr = new XMLHttpRequest();
2-
31
fetch('http://localhost:7654/foo', {
42
method: 'POST',
53
headers: {
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@ import type { Event } from '@sentry/types';
33

44
import { sentryTest } from '../../../../../utils/fixtures';
55
import { getFirstSentryEnvelopeRequest } from '../../../../../utils/helpers';
6+
import { shouldSkipReplayTest } from '../../../../../utils/replayHelpers';
67

78
sentryTest('captures request_body_size when body is sent', async ({ getLocalTestPath, page }) => {
9+
if (shouldSkipReplayTest()) {
10+
sentryTest.skip();
11+
}
12+
813
const url = await getLocalTestPath({ testDir: __dirname });
914

1015
await page.route('**/foo', route => {
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@ import type { Event } from '@sentry/types';
33

44
import { sentryTest } from '../../../../../utils/fixtures';
55
import { getFirstSentryEnvelopeRequest } from '../../../../../utils/helpers';
6+
import { shouldSkipReplayTest } from '../../../../../utils/replayHelpers';
67

78
sentryTest('parses response_body_size from Content-Length header if available', async ({ getLocalTestPath, page }) => {
9+
if (shouldSkipReplayTest()) {
10+
sentryTest.skip();
11+
}
12+
813
const url = await getLocalTestPath({ testDir: __dirname });
914

1015
await page.route('**/foo', route => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import * as Sentry from '@sentry/browser';
2+
3+
window.Sentry = Sentry;
4+
window.Replay = new Sentry.Replay({
5+
flushMinDelay: 200,
6+
flushMaxDelay: 200,
7+
});
8+
9+
Sentry.init({
10+
dsn: 'https://[email protected]/1337',
11+
sampleRate: 1,
12+
// We ensure to sample for errors, so by default nothing is sent
13+
replaysSessionSampleRate: 0.0,
14+
replaysOnErrorSampleRate: 1.0,
15+
16+
integrations: [window.Replay],
17+
});
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@ import type { Event } from '@sentry/types';
33

44
import { sentryTest } from '../../../../../utils/fixtures';
55
import { getFirstSentryEnvelopeRequest } from '../../../../../utils/helpers';
6+
import { shouldSkipReplayTest } from '../../../../../utils/replayHelpers';
67

78
sentryTest('captures response_body_size without Content-Length header', async ({ getLocalTestPath, page }) => {
9+
if (shouldSkipReplayTest()) {
10+
sentryTest.skip();
11+
}
12+
813
const url = await getLocalTestPath({ testDir: __dirname });
914

1015
await page.route('**/foo', route => {
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@ import type { Event } from '@sentry/types';
33

44
import { sentryTest } from '../../../../../utils/fixtures';
55
import { getFirstSentryEnvelopeRequest } from '../../../../../utils/helpers';
6+
import { shouldSkipReplayTest } from '../../../../../utils/replayHelpers';
67

78
sentryTest('calculates body sizes for non-string bodies', async ({ getLocalTestPath, page }) => {
9+
if (shouldSkipReplayTest()) {
10+
sentryTest.skip();
11+
}
12+
813
const url = await getLocalTestPath({ testDir: __dirname });
914

1015
await page.route('**/foo', async route => {
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@ import type { Event } from '@sentry/types';
33

44
import { sentryTest } from '../../../../../utils/fixtures';
55
import { getFirstSentryEnvelopeRequest } from '../../../../../utils/helpers';
6+
import { shouldSkipReplayTest } from '../../../../../utils/replayHelpers';
67

78
sentryTest('captures request_body_size when body is sent', async ({ getLocalTestPath, page }) => {
9+
if (shouldSkipReplayTest()) {
10+
sentryTest.skip();
11+
}
12+
813
const url = await getLocalTestPath({ testDir: __dirname });
914

1015
await page.route('**/foo', route => {

packages/integrations/src/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,3 @@ export { RewriteFrames } from './rewriteframes';
99
export { SessionTiming } from './sessiontiming';
1010
export { Transaction } from './transaction';
1111
export { HttpClient } from './httpclient';
12-
export { ExtendedNetworkBreadcrumbs } from './extendednetworkbreadcrumbs';

packages/integrations/test/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
{
55
"extends": "../tsconfig.test.json",
66

7-
"include": ["./**/*"]
7+
"include": ["./**/*", "../../replay/test/unit/coreHandlers/extendednetworkbreadcrumbs.test.ts"]
88
}

packages/integrations/src/extendednetworkbreadcrumbs.ts renamed to packages/replay/src/coreHandlers/extendNetworkBreadcrumbs.ts

+12-38
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1+
import { getCurrentHub } from '@sentry/core';
12
import type {
23
Breadcrumb,
34
BreadcrumbHint,
4-
EventProcessor,
55
HandlerDataFetch,
6-
Hub,
7-
Integration,
86
SentryWrappedXMLHttpRequest,
97
TextEncoderInternal,
108
} from '@sentry/types';
@@ -17,53 +15,29 @@ interface ExtendedNetworkBreadcrumbsOptions {
1715
}
1816

1917
/**
20-
* Add this integration _in addition_ the the default Breadcrumbs integration,
21-
* to enrich the xhr/fetch breadcrumbs with additional information.
18+
* This will enrich the xhr/fetch breadcrumbs with additional information.
2219
*
2320
* This adds:
2421
* * request_body_size
2522
* * response_body_size
2623
*
27-
* To the breadcrumb data.
24+
* to the breadcrumb data.
2825
*/
29-
export class ExtendedNetworkBreadcrumbs implements Integration {
30-
/**
31-
* @inheritDoc
32-
*/
33-
public static id: string = 'ExtendedNetworkBreadcrumbs';
34-
35-
/**
36-
* @inheritDoc
37-
*/
38-
public name: string = ExtendedNetworkBreadcrumbs.id;
39-
40-
private _options: Partial<ExtendedNetworkBreadcrumbsOptions>;
41-
42-
/**
43-
* @inheritDoc
44-
*/
45-
public constructor(options?: Partial<ExtendedNetworkBreadcrumbsOptions>) {
46-
this._options = options || {};
47-
}
26+
export function extendNetworkBreadcrumbs(): void {
27+
const client = getCurrentHub().getClient();
4828

49-
/**
50-
* @inheritDoc
51-
*/
52-
public setupOnce(_: (callback: EventProcessor) => void, getCurrentHub: () => Hub): void {
53-
const client = getCurrentHub().getClient();
54-
55-
try {
56-
this._options.textEncoder = this._options.textEncoder || new TextEncoder();
57-
} catch (error) {
58-
__DEBUG_BUILD__ && logger.warn('No textEncoder available, skipping ExtendedNetworkBreadcrumbs');
59-
return;
60-
}
29+
try {
30+
const textEncoder = new TextEncoder();
6131

62-
const options = this._options as ExtendedNetworkBreadcrumbsOptions;
32+
const options: ExtendedNetworkBreadcrumbsOptions = {
33+
textEncoder,
34+
};
6335

6436
if (client && client.on) {
6537
client.on('beforeAddBreadcrumb', (breadcrumb, hint) => _beforeNetworkBreadcrumb(options, breadcrumb, hint));
6638
}
39+
} catch {
40+
// Do nothing
6741
}
6842
}
6943

packages/replay/src/util/addGlobalListeners.ts

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { addGlobalEventProcessor, getCurrentHub } from '@sentry/core';
22
import { addInstrumentationHandler } from '@sentry/utils';
33

4+
import { extendNetworkBreadcrumbs } from '../coreHandlers/extendNetworkBreadcrumbs';
45
import { handleDomListener } from '../coreHandlers/handleDom';
56
import { handleFetchSpanListener } from '../coreHandlers/handleFetch';
67
import { handleGlobalEventListener } from '../coreHandlers/handleGlobalEvent';
@@ -26,4 +27,6 @@ export function addGlobalListeners(replay: ReplayContainer): void {
2627
// Tag all (non replay) events that get sent to Sentry with the current
2728
// replay ID so that we can reference them later in the UI
2829
addGlobalEventProcessor(handleGlobalEventListener(replay));
30+
31+
extendNetworkBreadcrumbs();
2932
}

packages/integrations/test/extendednetworkbreadcrumbs.test.ts renamed to packages/replay/test/unit/coreHandlers/extendNetworkBreadcrumbs.test.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
/**
2-
* @jest-environment jsdom
3-
*/
4-
51
import { TextEncoder } from 'util';
62

7-
import { getBodySize, parseContentSizeHeader } from '../src/extendednetworkbreadcrumbs';
3+
import { getBodySize, parseContentSizeHeader } from '../../../src/coreHandlers/extendNetworkBreadcrumbs';
84

9-
describe('instrument', () => {
5+
describe('Unit | coreHandlers | extendNetworkBreadcrumbs', () => {
106
describe('parseContentSizeHeader()', () => {
117
it.each([
128
[undefined, undefined],

0 commit comments

Comments
 (0)