10000 feat(gatsby): Remove `@sentry/tracing` dependency from Gatsby SDK (#7… · GingerAdonis/sentry-javascript@f38ad39 · GitHub
[go: up one dir, main page]

Skip to content

Commit f38ad39

Browse files
authored
feat(gatsby): Remove @sentry/tracing dependency from Gatsby SDK (getsentry#7578)
1 parent 98b6a1c commit f38ad39

File tree

6 files changed

+30
-67
lines changed

6 files changed

+30
-67
lines changed

packages/gatsby/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
"dependencies": {
2323
"@sentry/core": "7.44.2",
2424
"@sentry/react": "7.44.2",
25-
"@sentry/tracing": "7.44.2",
2625
"@sentry/types": "7.44.2",
2726
"@sentry/utils": "7.44.2",
2827
"@sentry/webpack-plugin": "1.19.0"

packages/gatsby/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
export * from '@sentry/react';
2-
export { Integrations } from '@sentry/tracing';
32

43
export { init } from './sdk';

packages/gatsby/src/utils/integrations.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { hasTracingEnabled } from '@sentry/core';
2-
import * as Tracing from '@sentry/tracing';
2+
import { BrowserTracing } from '@sentry/react';
33
import type { Integration } from '@sentry/types';
44

55
import type { GatsbyOptions } from './types';
@@ -31,11 +31,8 @@ export function getIntegrationsFromOptions(options: GatsbyOptions): UserIntegrat
3131
* @param isTracingEnabled Whether the user has enabled tracing.
3232
*/
3333
function getIntegrationsFromArray(userIntegrations: Integration[], isTracingEnabled: boolean): Integration[] {
34-
if (
35-
isTracingEnabled &&
36-
!userIntegrations.some(integration => integration.name === Tracing.Integrations.BrowserTracing.name)
37-
) {
38-
userIntegrations.push(new Tracing.Integrations.BrowserTracing());
34+
if (isTracingEnabled && !userIntegrations.some(integration => integration.name === BrowserTracing.name)) {
35+
userIntegrations.push(new BrowserTracing());
3936
}
4037
return userIntegrations;
4138
}

packages/gatsby/test/gatsby-browser.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/* eslint-disable @typescript-eslint/no-explicit-any */
33

44
import { onClientEntry } from '../gatsby-browser';
5+
import { BrowserTracing } from '../src/index';
56

67
(global as any).__SENTRY_RELEASE__ = '683f3a6ab819d47d23abfca9a914c81f0524d35b';
78
(global as any).__SENTRY_DSN__ = 'https://examplePublicKey@o0.ingest.sentry.io/0';
@@ -20,11 +21,11 @@ global.console.warn = jest.fn();
2021
global.console.error = jest.fn();
2122

2223
let tracingAddExtensionMethods = jest.fn();
23-
jest.mock('@sentry/tracing', () => {
24-
const original = jest.requireActual('@sentry/tracing');
24+
jest.mock('@sentry/core', () => {
25+
const original = jest.requireActual('@sentry/core');
2526
return {
2627
...original,
27-
addExtensionMethods: (...args: any[]) => {
28+
addTracingExtensions: (...args: any[]) => {
2829
tracingAddExtensionMethods(...args);
2930
},
3031
};
@@ -140,8 +141,7 @@ describe('onClientEntry', () => {
140141
});
141142

142143
it('only defines a single `BrowserTracing` integration', () => {
143-
const Tracing = jest.requireActual('@sentry/tracing');
144-
const integrations = [new Tracing.Integrations.BrowserTracing()];
144+
const integrations = [new BrowserTracing()];
145145
onClientEntry(undefined, { tracesSampleRate: 0.5, integrations });
146146

147147
expect(sentryInit).toHaveBeenLastCalledWith(

packages/gatsby/test/sdk.test.ts

Lines changed: 21 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { init, SDK_VERSION } from '@sentry/react';
2-
import { Integrations } from '@sentry/tracing';
1+
import { BrowserTracing, init, SDK_VERSION } from '@sentry/react';
32
import type { Integration } from '@sentry/types';
43

54
import { init as gatsbyInit } from '../src/sdk';
@@ -58,79 +57,48 @@ describe('Initialize React SDK', () => {
5857
});
5958
});
6059

60+
type TestArgs = [string, Integration[], GatsbyOptions, string[]];
61+
6162
describe('Integrations from options', () => {
6263
afterEach(() => reactInit.mockClear());
6364

6465
test.each([
6566
['tracing disabled, no integrations', [], {}, []],
6667
['tracing enabled, no integrations', [], { tracesSampleRate: 1 }, ['BrowserTracing']],
6768
[
68-
'tracing disabled, with Integrations.BrowserTracing as an array',
69+
'tracing disabled, with BrowserTracing as an array',
6970
[],
70-
{ integrations: [new Integrations.BrowserTracing()] },
71+
{ integrations: [new BrowserTracing()] },
7172
['BrowserTracing'],
7273
],
7374
[
74-
'tracing disabled, with Integrations.BrowserTracing as a function',
75+
'tracing disabled, with BrowserTracing as a function',
7576
[],
7677
{
77-
integrations: () => [new Integrations.BrowserTracing()],
78+
integrations: () => [new BrowserTracing()],
7879
},
7980
['BrowserTracing'],
8081
],
8182
[
82-
'tracing enabled, with Integrations.BrowserTracing as an array',
83+
'tracing enabled, with BrowserTracing as an array',
8384
[],
84-
{ tracesSampleRate: 1, integrations: [new Integrations.BrowserTracing()] },
85+
{ tracesSampleRate: 1, integrations: [new BrowserTracing()] },
8586
['BrowserTracing'],
8687
],
8788
[
88-
'tracing enabled, with Integrations.BrowserTracing as a function',
89+
'tracing enabled, with BrowserTracing as a function',
8990
[],
90-
{ tracesSampleRate: 1, integrations: () => [new Integrations.BrowserTracing()] },
91+
{ tracesSampleRate: 1, integrations: () => [new BrowserTracing()] },
9192
['BrowserTracing'],
9293
],
93-
[
94-
'tracing enabled, with another integration as an array',
95-
[],
96-
{ tracesSampleRate: 1, integrations: [new Integrations.Express()] },
97-
['Express', 'BrowserTracing'],
98-
],
99-
[
100-
'tracing enabled, with another integration as a function',
101-
[],
102-
{ tracesSampleRate: 1, integrations: () => [new Integrations.Express()] },
103-
['Express', 'BrowserTracing'],
104-
],
105-
[
106-
'tracing disabled, with another integration as an array',
107-
[],
108-
{ integrations: [new Integrations.Express()] },
109-
['Express'],
110-
],
111-
[
112-
'tracing disabled, with another integration as a function',
113-
[],
114-
{ integrations: () => [new Integrations.Express()] },
115-
['Express'],
116-
],
117-
[
118-
'merges integrations with user integrations as a function',
119-
[new Integrations.Mongo()],
120-
{
121-
tracesSampleRate: 1,
122-
integrations: (defaultIntegrations: Integration[]): Integration[] => [
123-
...defaultIntegrations,
124-
new Integrations.Express(),
125-
],
126-
},
127-
['Mongo', 'Express', 'BrowserTracing'],
128-
],
129-
])('%s', (_testName, defaultIntegrations: Integration[], options: GatsbyOptions, expectedIntNames: string[]) => {
130-
gatsbyInit(options);
131-
const integrations: UserIntegrations = reactInit.mock.calls[0][0].integrations;
132-
const arrIntegrations = Array.isArray(integrations) ? integrations : integrations(defaultIntegrations);
133-
expect(arrIntegrations).toHaveLength(expectedIntNames.length);
134-
arrIntegrations.map((integration, idx) => expect(integration.name).toStrictEqual(expectedIntNames[idx]));
135-
});
94+
] as TestArgs[])(
95+
'%s',
96+
(_testName, defaultIntegrations: Integration[], options: GatsbyOptions, expectedIntNames: string[]) => {
97+
gatsbyInit(options);
98+
const integrations: UserIntegrations = reactInit.mock.calls[0][0].integrations;
99+
const arrIntegrations = Array.isArray(integrations) ? integrations : integrations(defaultIntegrations);
100+
expect(arrIntegrations).toHaveLength(expectedIntNames.length);
101+
arrIntegrations.map((integration, idx) => expect(integration.name).toStrictEqual(expectedIntNames[idx]));
102+
},
103+
);
136104
});

packages/node/test/handlers.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as sentryCore from '@sentry/core';
2-
import { Transaction } from '@sentry/tracing';
2+
import { Transaction } from '@sentry/core';
33
import type { Event } from '@sentry/types';
44
import { SentryError } from '@sentry/utils';
55
import * as http from 'http';

0 commit comments

Comments
 (0)
0