-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tracing): Expose
BrowserTracing
in non-tracing bundles (#7479)
- Loading branch information
Showing
27 changed files
with
287 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
packages/browser-integration-tests/suites/tracing/browserTracingIntegrationShim/init.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
|
||
window.Sentry = Sentry; | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
sampleRate: 1, | ||
integrations: [new Sentry.Integrations.BrowserTracing()], | ||
}); | ||
|
||
// This should not fail | ||
Sentry.addTracingExtensions(); |
9 changes: 9 additions & 0 deletions
9
...ages/browser-integration-tests/suites/tracing/browserTracingIntegrationShim/template.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
</head> | ||
<body> | ||
<button onclick="console.log('Test log')">Click me</button> | ||
</body> | ||
</html> |
37 changes: 37 additions & 0 deletions
37
packages/browser-integration-tests/suites/tracing/browserTracingIntegrationShim/test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { expect } from '@playwright/test'; | ||
|
||
import { sentryTest } from '../../../utils/fixtures'; | ||
|
||
sentryTest( | ||
'exports a shim Integrations.BrowserTracing integration for non-tracing bundles', | ||
async ({ getLocalTestPath, page }) => { | ||
const bundle = process.env.PW_BUNDLE; | ||
const tracingOnly = Boolean(process.env.PW_TRACING_ONLY); | ||
|
||
if (!bundle || !bundle.startsWith('bundle_') || tracingOnly) { | ||
sentryTest.skip(); | ||
} | ||
|
||
const consoleMessages: string[] = []; | ||
page.on('console', msg => consoleMessages.push(msg.text())); | ||
|
||
let requestCount = 0; | ||
await page.route('https://dsn.ingest.sentry.io/**/*', route => { | ||
requestCount++; | ||
return route.fulfill({ | ||
status: 200, | ||
contentType: 'application/json', | ||
body: JSON.stringify({ id: 'test-id' }), | ||
}); | ||
}); | ||
|
||
const url = await getLocalTestPath({ testDir: __dirname }); | ||
|
||
await page.goto(url); | ||
|
||
expect(requestCount).toBe(0); | ||
expect(consoleMessages).toEqual([ | ||
'You are using new BrowserTracing() even though this bundle does not include tracing.', | ||
]); | ||
}, | ||
); |
12 changes: 12 additions & 0 deletions
12
packages/browser-integration-tests/suites/tracing/browserTracingShim/init.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
|
||
window.Sentry = Sentry; | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
sampleRate: 1, | ||
integrations: [new Sentry.BrowserTracing()], | ||
}); | ||
|
||
// This should not fail | ||
Sentry.addTracingExtensions(); |
9 changes: 9 additions & 0 deletions
9
packages/browser-integration-tests/suites/tracing/browserTracingShim/template.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
</head> | ||
<body> | ||
<button onclick="console.log('Test log')">Click me</button> | ||
</body> | ||
</html> |
34 changes: 34 additions & 0 deletions
34
packages/browser-integration-tests/suites/tracing/browserTracingShim/test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { expect } from '@playwright/test'; | ||
|
||
import { sentryTest } from '../../../utils/fixtures'; | ||
|
||
sentryTest('exports a shim BrowserTracing integration for non-tracing bundles', async ({ getLocalTestPath, page }) => { | ||
const bundle = process.env.PW_BUNDLE; | ||
const tracingOnly = Boolean(process.env.PW_TRACING_ONLY); | ||
|
||
if (!bundle || !bundle.startsWith('bundle_') || tracingOnly) { | ||
sentryTest.skip(); | ||
} | ||
|
||
const consoleMessages: string[] = []; | ||
page.on('console', msg => consoleMessages.push(msg.text())); | ||
|
||
let requestCount = 0; | ||
await page.route('https://dsn.ingest.sentry.io/**/*', route => { | ||
requestCount++; | ||
return route.fulfill({ | ||
status: 200, | ||
contentType: 'application/json', | ||
body: JSON.stringify({ id: 'test-id' }), | ||
}); | ||
}); | ||
|
||
const url = await getLocalTestPath({ testDir: __dirname }); | ||
|
||
await page.goto(url); | ||
|
||
expect(requestCount).toBe(0); | ||
expect(consoleMessages).toEqual([ | ||
'You are using new BrowserTracing() even though this bundle does not include tracing.', | ||
]); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
export * from './exports'; | ||
|
||
import { Integrations as CoreIntegrations } from '@sentry/core'; | ||
import type { Integration } from '@sentry/types'; | ||
|
||
import { WINDOW } from './helpers'; | ||
import * as BrowserIntegrations from './integrations'; | ||
|
||
let windowIntegrations = {}; | ||
|
||
// This block is needed to add compatibility with the integrations packages when used with a CDN | ||
if (WINDOW.Sentry && WINDOW.Sentry.Integrations) { | ||
windowIntegrations = WINDOW.Sentry.Integrations; | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const INTEGRATIONS: Record<string, new (...args: any[]) => Integration> = { | ||
...windowIntegrations, | ||
...CoreIntegrations, | ||
...BrowserIntegrations, | ||
}; | ||
|
||
export { INTEGRATIONS as Integrations }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// This is exported so the loader does not fail when switching off Replay/Tracing | ||
import { addTracingExtensions, BrowserTracing } from '@sentry-internal/integration-shims'; | ||
import { Replay } from '@sentry/replay'; | ||
|
||
import * as Sentry from './index.bundle.base'; | ||
|
||
// TODO (v8): Remove this as it was only needed for backwards compatibility | ||
Sentry.Integrations.Replay = Replay; | ||
|
||
Sentry.Integrations.BrowserTracing = BrowserTracing; | ||
|
||
export * from './index.bundle.base'; | ||
export { BrowserTracing, addTracingExtensions, Replay }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// This is exported so the loader does not fail when switching off Replay/Tracing | ||
import { addTracingExtensions, BrowserTracing, Replay } from '@sentry-internal/integration-shims'; | ||
|
||
import * as Sentry from './index.bundle.base'; | ||
|
||
// TODO (v8): Remove this as it was only needed for backwards compatibility | ||
Sentry.Integrations.Replay = Replay; | ||
|
||
Sentry.Integrations.BrowserTracing = BrowserTracing; | ||
|
||
export * from './index.bundle.base'; | ||
export { BrowserTracing, addTracingExtensions, Replay }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { BrowserTracing as BrowserTracingShim } from '@sentry-internal/integration-shims'; | ||
import { Replay } from '@sentry/browser'; | ||
|
||
import * as TracingReplayBundle from '../../src/index.bundle.replay'; | ||
|
||
describe('index.bundle.replay', () => { | ||
it('has correct exports', () => { | ||
Object.keys(TracingReplayBundle.Integrations).forEach(key => { | ||
// Skip BrowserTracing because it doesn't have a static id field. | ||
if (key === 'BrowserTracing') { | ||
return; | ||
} | ||
|
||
expect((TracingReplayBundle.Integrations[key] as any).id).toStrictEqual(expect.any(String)); | ||
}); | ||
|
||
expect(TracingReplayBundle.Integrations.Replay).toBe(Replay); | ||
expect(TracingReplayBundle.Replay).toBe(Replay); | ||
|
||
expect(TracingReplayBundle.Integrations.BrowserTracing).toBe(BrowserTracingShim); | ||
expect(TracingReplayBundle.BrowserTracing).toBe(BrowserTracingShim); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { BrowserTracing as BrowserTracingShim, Replay as ReplayShim } from '@sentry-internal/integration-shims'; | ||
|
||
import * as TracingBundle from '../../src/index.bundle'; | ||
|
||
describe('index.bundle', () => { | ||
it('has correct exports', () => { | ||
Object.keys(TracingBundle.Integrations).forEach(key => { | ||
// Skip BrowserTracing because it doesn't have a static id field. | ||
if (key === 'BrowserTracing') { | ||
return; | ||
} | ||
|
||
expect((TracingBundle.Integrations[key] as any).id).toStrictEqual(expect.any(String)); | ||
}); | ||
|
||
expect(TracingBundle.Integrations.Replay).toBe(ReplayShim); | ||
expect(TracingBundle.Replay).toBe(ReplayShim); | ||
|
||
expect(TracingBundle.Integrations.BrowserTracing).toBe(BrowserTracingShim); | ||
expect(TracingBundle.BrowserTracing).toBe(BrowserTracingShim); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import type { Integration } from '@sentry/types'; | ||
|
||
/** | ||
* This is a shim for the BrowserTracing integration. | ||
* It is needed in order for the CDN bundles to continue working when users add/remove tracing | ||
* from it, without changing their config. This is necessary for the loader mechanism. | ||
*/ | ||
class BrowserTracingShim implements Integration { | ||
/** | ||
* @inheritDoc | ||
*/ | ||
public static id: string = 'BrowserTracing'; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public name: string = BrowserTracingShim.id; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
public constructor(_options: any) { | ||
// eslint-disable-next-line no-console | ||
console.error('You are using new BrowserTracing() even though this bundle does not include tracing.'); | ||
} | ||
|
||
/** jsdoc */ | ||
public setupOnce(): void { | ||
// noop | ||
} | ||
} | ||
|
||
export { BrowserTracingShim as BrowserTracing }; | ||
|
||
/** Shim function */ | ||
export function addTracingExtensions(): void { | ||
// noop | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './Replay'; | ||
export { Replay } from './Replay'; | ||
export { BrowserTracing, addTracingExtensions } from './BrowserTracing'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
import { Replay } from '@sentry/browser'; | ||
|
||
import * as Sentry from './index.bundle'; | ||
import * as Sentry from './index.bundle.base'; | ||
|
||
// TODO (v8): Remove this as it was only needed for backwards compatibility | ||
// We want replay to be available under Sentry.Replay, to be consistent | ||
// with the NPM package version. | ||
Sentry.Integrations.Replay = Replay; | ||
|
||
export { Replay }; | ||
|
||
export * from './index.bundle.base'; |
Oops, something went wrong.