Skip to content

Commit c68c653

Browse files
committed
Merge remote-tracking branch 'origin/develop'
2 parents 49b0ce0 + 250b6d3 commit c68c653

File tree

59 files changed

+317
-119
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+317
-119
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
window.sentryOnLoad = function () {
2+
Sentry.init({});
3+
4+
window.__sentryLoaded = true;
5+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Sentry.forceLoad();
2+
3+
Sentry.captureException('Test exception');
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<script>
6+
window.Sentry = {_customThingOnSentry: 'customThingOnSentry' };
7+
</script>
8+
</head>
9+
<body></body>
10+
</html>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { expect } from '@playwright/test';
2+
3+
import { sentryTest } from '../../../../utils/fixtures';
4+
import { envelopeRequestParser, waitForErrorRequestOnUrl } from '../../../../utils/helpers';
5+
6+
sentryTest('keeps data on window.Sentry intact', async ({ getLocalTestUrl, page }) => {
7+
await page.route('https://dsn.ingest.sentry.io/**/*', route => {
8+
return route.fulfill({
9+
status: 200,
10+
contentType: 'application/json',
11+
body: JSON.stringify({ id: 'test-id' }),
12+
});
13+
});
14+
15+
const url = await getLocalTestUrl({ testDir: __dirname });
16+
const req = await waitForErrorRequestOnUrl(page, url);
17+
18+
const eventData = envelopeRequestParser(req);
19+
20+
expect(eventData.message).toBe('Test exception');
21+
22+
const customThingy = await page.evaluate('window.Sentry._customThingOnSentry');
23+
expect(customThingy).toBe('customThingOnSentry');
24+
});

dev-packages/e2e-tests/test-applications/nextjs-app-dir/assert-build.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as fs from 'fs';
2+
import * as path from 'path';
23
import * as assert from 'assert/strict';
34

45
const packageJson = require('./package.json');
@@ -20,4 +21,11 @@ assert.match(buildStdout, /(λ|ƒ) \/server-component/);
2021
assert.match(buildStdout, /(λ|ƒ) \/server-component\/parameter\/\[\.\.\.parameters\]/);
2122
assert.match(buildStdout, /(λ|ƒ) \/server-component\/parameter\/\[parameter\]/);
2223

24+
// Read the contents of the directory
25+
const files = fs.readdirSync(path.join(process.cwd(), '.next', 'server'));
26+
const mapFiles = files.filter(file => path.extname(file) === '.map');
27+
if (mapFiles.length > 0) {
28+
throw new Error('.map files found even though `sourcemaps.deleteSourcemapsAfterUpload` option is set!');
29+
}
30+
2331
export {};

dev-packages/e2e-tests/test-applications/nextjs-app-dir/next.config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,8 @@ const nextConfig = {
99
};
1010

1111
module.exports = withSentryConfig(nextConfig, {
12-
silent: true,
12+
debug: true,
13+
sourcemaps: {
14+
deleteSourcemapsAfterUpload: true,
15+
},
1316
});

dev-packages/rollup-utils/bundleHelpers.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ export function makeBaseBundleConfig(options) {
4848
output: {
4949
format: 'iife',
5050
name: 'Sentry',
51+
intro: () => {
52+
return 'exports = window.Sentry || {};';
53+
},
5154
},
5255
context: 'window',
5356
plugins: [rrwebBuildPlugin, markAsBrowserBuildPlugin],

docs/commit-issue-pr-guidelines.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ and committed as such onto `develop`.
2929
- Make sure to rebase the branch on `develop` before squashing it
3030
- Make sure to update the commit message of the squashed branch to follow the commit guidelines - including the PR
3131
number
32+
- If you are a Sentry employee, assign yourself to the PR
3233

3334
Please note that we cannot _enforce_ Squash Merge due to the usage of Gitflow (see below). Github remembers the last
3435
used merge method, so you'll need to make sure to double check that you are using "Squash and Merge" correctly.

packages/angular/src/sdk.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
functionToStringIntegration,
1414
inboundFiltersIntegration,
1515
} from '@sentry/core';
16-
import type { Integration } from '@sentry/types';
16+
import type { Client, Integration } from '@sentry/types';
1717
import { logger } from '@sentry/utils';
1818

1919
import { IS_DEBUG_BUILD } from './flags';
@@ -44,7 +44,7 @@ export function getDefaultIntegrations(): Integration[] {
4444
/**
4545
* Inits the Angular SDK
4646
*/
47-
export function init(options: BrowserOptions): void {
47+
export function init(options: BrowserOptions): Client | undefined {
4848
const opts = {
4949
defaultIntegrations: getDefaultIntegrations(),
5050
...options,
@@ -53,7 +53,7 @@ export function init(options: BrowserOptions): void {
5353
applySdkMetadata(opts, 'angular');
5454

5555
checkAndSetAngularVersion();
56-
browserInit(opts);
56+
return browserInit(opts);
5757
}
5858

5959
function checkAndSetAngularVersion(): void {

packages/angular/test/sdk.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,8 @@ describe('init', () => {
2626

2727
expect(angularDefaultIntegrations).toEqual(browserDefaultIntegrationsWithoutBrowserApiErrors);
2828
});
29+
30+
it('returns client from init', () => {
31+
expect(init({})).not.toBeUndefined();
32+
});
2933
});

packages/astro/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"@sentry/node": "8.11.0",
6767
"@sentry/types": "8.11.0",
6868
"@sentry/utils": "8.11.0",
69-
"@sentry/vite-plugin": "^2.18.0"
69+
"@sentry/vite-plugin": "^2.19.0"
7070
},
7171
"devDependencies": {
7272
"astro": "^3.5.0",

packages/astro/src/client/sdk.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
setTag,
77
} from '@sentry/browser';
88
import { applySdkMetadata, hasTracingEnabled } from '@sentry/core';
9-
import type { Integration } from '@sentry/types';
9+
import type { Client, Integration } from '@sentry/types';
1010

1111
// Tree-shakable guard to remove all code related to tracing
1212
declare const __SENTRY_TRACING__: boolean;
@@ -16,17 +16,19 @@ declare const __SENTRY_TRACING__: boolean;
1616
*
1717
* @param options Configuration options for the SDK.
1818
*/
19-
export function init(options: BrowserOptions): void {
19+
export function init(options: BrowserOptions): Client | undefined {
2020
const opts = {
2121
defaultIntegrations: getDefaultIntegrations(options),
2222
...options,
2323
};
2424

2525
applySdkMetadata(opts, 'astro', ['astro', 'browser']);
2626

27-
initBrowserSdk(opts);
27+
const client = initBrowserSdk(opts);
2828

2929
setTag('runtime', 'browser');
30+
31+
return client;
3032
}
3133

3234
function getDefaultIntegrations(options: BrowserOptions): Integration[] | undefined {

packages/astro/src/server/sdk.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
import { applySdkMetadata } from '@sentry/core';
2-
import type { NodeOptions } from '@sentry/node';
2+
import type { NodeClient, NodeOptions } from '@sentry/node';
33
import { init as initNodeSdk, setTag } from '@sentry/node';
44

55
/**
66
*
77
* @param options
88
*/
9-
export function init(options: NodeOptions): void {
9+
export function init(options: NodeOptions): NodeClient | undefined {
1010
const opts = {
1111
...options,
1212
};
1313

1414
applySdkMetadata(opts, 'astro', ['astro', 'node']);
1515

16-
initNodeSdk(opts);
16+
const client = initNodeSdk(opts);
1717

1818
setTag('runtime', 'node');
19+
20+
return client;
1921
}

packages/astro/test/client/sdk.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,5 +122,9 @@ describe('Sentry client SDK', () => {
122122
expect(getActiveSpan()).toBeUndefined();
123123
});
124124
});
125+
126+
it('returns client from init', () => {
127+
expect(init({})).not.toBeUndefined();
128+
});
125129
});
126130
});

packages/astro/test/server/sdk.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,9 @@ describe('Sentry server SDK', () => {
4646

4747
expect(SentryNode.getIsolationScope().getScopeData().tags).toEqual({ runtime: 'node' });
4848
});
49+
50+
it('returns client from init', () => {
51+
expect(init({})).not.toBeUndefined();
52+
});
4953
});
5054
});

packages/aws-serverless/src/sdk.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { existsSync } from 'fs';
22
import { hostname } from 'os';
33
import { basename, resolve } from 'path';
44
import { types } from 'util';
5-
import type { NodeOptions } from '@sentry/node';
5+
import type { NodeClient, NodeOptions } from '@sentry/node';
66
import {
77
SDK_VERSION,
88
captureException,
@@ -74,7 +74,7 @@ export function getDefaultIntegrations(_options: Options): Integration[] {
7474
*
7575
* @param options Configuration options for the SDK, @see {@link AWSLambdaOptions}.
7676
*/
77-
export function init(options: NodeOptions = {}): void {
77+
export function init(options: NodeOptions = {}): NodeClient | undefined {
7878
const opts = {
7979
_metadata: {} as SdkMetadata,
8080
defaultIntegrations: getDefaultIntegrations(options),
@@ -93,7 +93,7 @@ export function init(options: NodeOptions = {}): void {
9393
version: SDK_VERSION,
9494
};
9595

96-
initWithoutDefaultIntegrations(opts);
96+
return initWithoutDefaultIntegrations(opts);
9797
}
9898

9999
/** */

packages/browser/src/sdk.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
lastEventId,
1010
startSession,
1111
} from '@sentry/core';
12-
import type { DsnLike, Integration, Options, UserFeedback } from '@sentry/types';
12+
import type { Client, DsnLike, Integration, Options, UserFeedback } from '@sentry/types';
1313
import { consoleSandbox, logger, stackParserFromStackParserOptions, supportsFetch } from '@sentry/utils';
1414

1515
import { addHistoryInstrumentationHandler } from '@sentry-internal/browser-utils';
@@ -139,7 +139,7 @@ declare const __SENTRY_RELEASE__: string | undefined;
139139
*
140140
* @see {@link BrowserOptions} for documentation on configuration options.
141141
*/
142-
export function init(browserOptions: BrowserOptions = {}): void {
142+
export function init(browserOptions: BrowserOptions = {}): Client | undefined {
143143
const options = applyDefaultOptions(browserOptions);
144144

145145
if (shouldShowBrowserExtensionError()) {
@@ -166,11 +166,13 @@ export function init(browserOptions: BrowserOptions = {}): void {
166166
transport: options.transport || makeFetchTransport,
167167
};
168168

169-
initAndBind(BrowserClient, clientOptions);
169+
const client = initAndBind(BrowserClient, clientOptions);
170170

171171
if (options.autoSessionTracking) {
172172
startSessionTracking();
173173
}
174+
175+
return client;
174176
}
175177

176178
/**

packages/browser/test/unit/sdk.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,5 +209,25 @@ describe('init', () => {
209209

210210
consoleErrorSpy.mockRestore();
211211
});
212+
213+
it("doesn't return a client on initialization error", () => {
214+
const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
215+
216+
Object.defineProperty(WINDOW, 'chrome', {
217+
value: { runtime: { id: 'mock-extension-id' } },
218+
writable: true,
219+
});
220+
221+
const client = init(options);
222+
223+
expect(client).toBeUndefined();
224+
225+
consoleErrorSpy.mockRestore();
226+
});
227+
});
228+
229+
it('returns a client from init', () => {
230+
const client = init();
231+
expect(client).not.toBeUndefined();
212232
});
213233
});

packages/bun/src/sdk.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
linkedErrorsIntegration,
55
requestDataIntegration,
66
} from '@sentry/core';
7+
import type { NodeClient } from '@sentry/node';
78
import {
89
consoleIntegration,
910
contextLinesIntegration,
@@ -91,13 +92,13 @@ export function getDefaultIntegrations(_options: Options): Integration[] {
9192
*
9293
* @see {@link BunOptions} for documentation on configuration options.
9394
*/
94-
export function init(options: BunOptions = {}): void {
95+
export function init(options: BunOptions = {}): NodeClient | undefined {
9596
options.clientClass = BunClient;
9697
options.transport = options.transport || makeFetchTransport;
9798

9899
if (options.defaultIntegrations === undefined) {
99100
options.defaultIntegrations = getDefaultIntegrations(options);
100101
}
101102

102-
initNode(options);
103+
return initNode(options);
103104
}

packages/bun/test/sdk.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@ test("calling init shouldn't fail", () => {
88
});
99
expect(true).toBe(true);
1010
});
11+
12+
test('shuold return client from init', () => {
13+
expect(init({})).not.toBeUndefined();
14+
});

packages/core/src/exports.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export function captureException(
4141
/**
4242
* Captures a message event and sends it to Sentry.
4343
*
44-
* @param exception The exception to capture.
44+
* @param message The message to send to Sentry.
4545
* @param captureContext Define the level of the message or pass in additional data to attach to the message.
4646
* @returns the id of the captured message.
4747
*/
@@ -56,7 +56,7 @@ export function captureMessage(message: string, captureContext?: CaptureContext
5656
/**
5757
* Captures a manually created event and sends it to Sentry.
5858
*
59-
* @param exception The event to send to Sentry.
59+
* @param event The event to send to Sentry.
6060
* @param hint Optional additional data to attach to the Sentry event.
6161
* @returns the id of the captured event.
6262
*/

packages/core/src/sdk.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export type ClientClass<F extends Client, O extends ClientOptions> = new (option
1717
export function initAndBind<F extends Client, O extends ClientOptions>(
1818
clientClass: ClientClass<F, O>,
1919
options: O,
20-
): void {
20+
): Client {
2121
if (options.debug === true) {
2222
if (DEBUG_BUILD) {
2323
logger.enable();
@@ -35,6 +35,7 @@ export function initAndBind<F extends Client, O extends ClientOptions>(
3535
const client = new clientClass(options);
3636
setCurrentClient(client);
3737
client.init();
38+
return client;
3839
}
3940

4041
/**

packages/core/test/lib/sdk.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ describe('SDK', () => {
8282
'afterAllSetup2',
8383
]);
8484
});
85+
86+
test('returns client from init', () => {
87+
const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN });
88+
const client = initAndBind(TestClient, options);
89+
expect(client).not.toBeUndefined();
90+
});
8591
});
8692
});
8793

0 commit comments

Comments
 (0)