Skip to content

Commit 37124b1

Browse files
committed
ref: Refactor into ExtendedNetworkBreadcrumbs
1 parent ec41258 commit 37124b1

File tree

30 files changed

+267
-135
lines changed

30 files changed

+267
-135
lines changed

packages/browser/src/integrations/breadcrumbs.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
parseUrl,
1111
safeJoin,
1212
severityLevelFromString,
13-
dropUndefinedKeys,
1413
} from '@sentry/utils';
1514

1615
import { WINDOW } from '../helpers';
@@ -223,18 +222,16 @@ function _xhrBreadcrumb(handlerData: HandlerData & HandlerDataXhr): void {
223222
return;
224223
}
225224

226-
const { method, url, status_code, body, request_body_size, response_body_size } = handlerData.xhr.__sentry_xhr__;
225+
const { method, url, status_code, body } = handlerData.xhr.__sentry_xhr__;
227226

228227
getCurrentHub().addBreadcrumb(
229228
{
230229
category: 'xhr',
231-
data: dropUndefinedKeys({
230+
data: {
232231
method,
233232
url,
234233
status_code,
235-
request_body_size,
236-
response_body_size,
237-
}),
234+
},
238235
type: 'http',
239236
},
240237
{
@@ -262,7 +259,7 @@ function _fetchBreadcrumb(handlerData: HandlerData & HandlerDataFetch): void {
262259
getCurrentHub().addBreadcrumb(
263260
{
264261
category: 'fetch',
265-
data: dropUndefinedKeys(handlerData.fetchData),
262+
data: handlerData.fetchData,
266263
level: 'error',
267264
type: 'http',
268265
},
@@ -276,7 +273,7 @@ function _fetchBreadcrumb(handlerData: HandlerData & HandlerDataFetch): void {
276273
{
277274
category: 'fetch',
278275
data: {
279-
...dropUndefinedKeys(handlerData.fetchData),
276+
...handlerData.fetchData,
280277
status_code: handlerData.response && handlerData.response.status,
281278
},
282279
type: 'http',

packages/core/src/baseclient.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/* eslint-disable max-lines */
22
import type {
3+
Breadcrumb,
4+
BreadcrumbHint,
35
Client,
46
ClientOptions,
57
DataCategory,
@@ -363,6 +365,9 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
363365
/** @inheritdoc */
364366
public on(hook: 'beforeEnvelope', callback: (envelope: Envelope) => void): void;
365367

368+
/** @inheritdoc */
369+
public on(hook: 'beforeBreadcrumb', callback: (breadcrumb: Breadcrumb, hint?: BreadcrumbHint) => void): void;
370+
366371
/** @inheritdoc */
367372
public on(hook: string, callback: unknown): void {
368373
if (!this._hooks[hook]) {
@@ -379,6 +384,9 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
379384
/** @inheritdoc */
380385
public emit(hook: 'beforeEnvelope', envelope: Envelope): void;
381386

387+
/** @inheritdoc */
388+
public emit(hook: 'beforeBreadcrumb', breadcrumb: Breadcrumb, hint?: BreadcrumbHint): void;
389+
382390
/** @inheritdoc */
383391
public emit(hook: string, ...rest: unknown[]): void {
384392
if (this._hooks[hook]) {

packages/core/src/hub.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,10 @@ export class Hub implements HubInterface {
271271

272272
if (finalBreadcrumb === null) return;
273273

274+
if (client.emit) {
275+
client.emit('beforeBreadcrumb', finalBreadcrumb, hint);
276+
}
277+
274278
scope.addBreadcrumb(finalBreadcrumb, maxBreadcrumbs);
275279
}
276280

packages/integration-tests/suites/integrations/browser/breadcrumbs/fetch/contentLengthHeader/test.ts renamed to packages/integration-tests/suites/integrations/ExtendedNetworkBreadcrumbs/fetch/contentLengthHeader/test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { expect } from '@playwright/test';
22
import type { Event } from '@sentry/types';
33

4-
import { sentryTest } from '../../../../../../utils/fixtures';
5-
import { getFirstSentryEnvelopeRequest } from '../../../../../../utils/helpers';
4+
import { sentryTest } from '../../../../../utils/fixtures';
5+
import { getFirstSentryEnvelopeRequest } from '../../../../../utils/helpers';
66

77
sentryTest('parses response_body_size from Content-Length header if available', async ({ getLocalTestPath, page }) => {
88
const url = await getLocalTestPath({ testDir: __dirname });

packages/integration-tests/suites/integrations/browser/breadcrumbs/fetch/get/test.ts renamed to packages/integration-tests/suites/integrations/ExtendedNetworkBreadcrumbs/fetch/get/test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { expect } from '@playwright/test';
22
import type { Event } from '@sentry/types';
33

4-
import { sentryTest } from '../../../../../../utils/fixtures';
5-
import { getFirstSentryEnvelopeRequest } from '../../../../../../utils/helpers';
4+
import { sentryTest } from '../../../../../utils/fixtures';
5+
import { getFirstSentryEnvelopeRequest } from '../../../../../utils/helpers';
66

77
sentryTest('adds a breadcrumb for basic fetch GET request', async ({ getLocalTestPath, page }) => {
88
const url = await getLocalTestPath({ testDir: __dirname });
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import * as Sentry from '@sentry/browser';
2+
import { ExtendedNetworkBreadcrumbs } from '@sentry/integrations';
3+
4+
window.Sentry = Sentry;
5+
6+
Sentry.init({
7+
dsn: 'https://[email protected]/1337',
8+
defaultIntegrations: false,
9+
integrations: [new Sentry.Integrations.Breadcrumbs(), new ExtendedNetworkBreadcrumbs()],
10+
sampleRate: 1,
11+
});

packages/integration-tests/suites/integrations/browser/breadcrumbs/fetch/nonTextBody/test.ts renamed to packages/integration-tests/suites/integrations/ExtendedNetworkBreadcrumbs/fetch/nonTextBody/test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { expect } from '@playwright/test';
22
import type { Event } from '@sentry/types';
33

4-
import { sentryTest } from '../../../../../../utils/fixtures';
5-
import { getFirstSentryEnvelopeRequest } from '../../../../../../utils/helpers';
4+
import { sentryTest } from '../../../../../utils/fixtures';
5+
import { getFirstSentryEnvelopeRequest } from '../../../../../utils/helpers';
66

77
sentryTest('calculates body sizes for non-string bodies', async ({ getLocalTestPath, page }) => {
88
const url = await getLocalTestPath({ testDir: __dirname });

packages/integration-tests/suites/integrations/browser/breadcrumbs/fetch/post/test.ts renamed to packages/integration-tests/suites/integrations/ExtendedNetworkBreadcrumbs/fetch/post/test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { expect } from '@playwright/test';
22
import type { Event } from '@sentry/types';
33

4-
import { sentryTest } from '../../../../../../utils/fixtures';
5-
import { getFirstSentryEnvelopeRequest } from '../../../../../../utils/helpers';
4+
import { sentryTest } from '../../../../../utils/fixtures';
5+
import { getFirstSentryEnvelopeRequest } from '../../../../../utils/helpers';
66

77
sentryTest('adds a breadcrumb for basic fetch POST request', async ({ getLocalTestPath, page }) => {
88
const url = await getLocalTestPath({ testDir: __dirname });

packages/integration-tests/suites/integrations/browser/breadcrumbs/xhr/contentLengthHeader/test.ts renamed to packages/integration-tests/suites/integrations/ExtendedNetworkBreadcrumbs/xhr/contentLengthHeader/test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { expect } from '@playwright/test';
22
import type { Event } from '@sentry/types';
33

4-
import { sentryTest } from '../../../../../../utils/fixtures';
5-
import { getFirstSentryEnvelopeRequest } from '../../../../../../utils/helpers';
4+
import { sentryTest } from '../../../../../utils/fixtures';
5+
import { getFirstSentryEnvelopeRequest } from '../../../../../utils/helpers';
66

77
sentryTest('parses response_body_size from Content-Length header if available', async ({ getLocalTestPath, page }) => {
88
const url = await getLocalTestPath({ testDir: __dirname });

packages/integration-tests/suites/integrations/browser/breadcrumbs/xhr/get/test.ts renamed to packages/integration-tests/suites/integrations/ExtendedNetworkBreadcrumbs/xhr/get/test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { expect } from '@playwright/test';
22
import type { Event } from '@sentry/types';
33

4-
import { sentryTest } from '../../../../../../utils/fixtures';
5-
import { getFirstSentryEnvelopeRequest } from '../../../../../../utils/helpers';
4+
import { sentryTest } from '../../../../../utils/fixtures';
5+
import { getFirstSentryEnvelopeRequest } from '../../../../../utils/helpers';
66

77
sentryTest('adds a breadcrumb for basic XHR GET request', async ({ getLocalTestPath, page }) => {
88
const url = await getLocalTestPath({ testDir: __dirname });
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import * as Sentry from '@sentry/browser';
2+
import { ExtendedNetworkBreadcrumbs } from '@sentry/integrations';
3+
4+
window.Sentry = Sentry;
5+
6+
Sentry.init({
7+
dsn: 'https://[email protected]/1337',
8+
defaultIntegrations: false,
9+
integrations: [new Sentry.Integrations.Breadcrumbs(), new ExtendedNetworkBreadcrumbs()],
10+
sampleRate: 1,
11+
});

packages/integration-tests/suites/integrations/browser/breadcrumbs/xhr/nonTextBody/test.ts renamed to packages/integration-tests/suites/integrations/ExtendedNetworkBreadcrumbs/xhr/nonTextBody/test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { expect } from '@playwright/test';
22
import type { Event } from '@sentry/types';
33

4-
import { sentryTest } from '../../../../../../utils/fixtures';
5-
import { getFirstSentryEnvelopeRequest } from '../../../../../../utils/helpers';
4+
import { sentryTest } from '../../../../../utils/fixtures';
5+
import { getFirstSentryEnvelopeRequest } from '../../../../../utils/helpers';
66

77
sentryTest('calculates body sizes for non-string bodies', async ({ getLocalTestPath, page }) => {
88
const url = await getLocalTestPath({ testDir: __dirname });

packages/integration-tests/suites/integrations/browser/breadcrumbs/xhr/post/test.ts renamed to packages/integration-tests/suites/integrations/ExtendedNetworkBreadcrumbs/xhr/post/test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { expect } from '@playwright/test';
22
import type { Event } from '@sentry/types';
33

4-
import { sentryTest } from '../../../../../../utils/fixtures';
5-
import { getFirstSentryEnvelopeRequest } from '../../../../../../utils/helpers';
4+
import { sentryTest } from '../../../../../utils/fixtures';
5+
import { getFirstSentryEnvelopeRequest } from '../../../../../utils/helpers';
66

77
sentryTest('adds a breadcrumb for basic XHR POST request', async ({ getLocalTestPath, page }) => {
88
const url = await getLocalTestPath({ testDir: __dirname });

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

Lines changed: 0 additions & 10 deletions
This file was deleted.

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

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)