Skip to content

Commit 6279d96

Browse files
authored
feat(svelte): Add Error and Performance Instrumentation from Browser SDK (#5543)
Add basic error and performance monitoring to the new Svelte SDK. For the moment, we only wrap the Browser SDK and overwrite its default config with the Svelte SDK metadata. Add a small unit test to ensure that SDK name and version are set correctly.
1 parent 11bb8ed commit 6279d96

File tree

4 files changed

+55
-2
lines changed

4 files changed

+55
-2
lines changed

packages/svelte/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"lint": "run-s lint:prettier lint:eslint",
4444
"lint:eslint": "eslint . --cache --cache-location '../../eslintcache/' --format stylish",
4545
"lint:prettier": "prettier --check \"{src,test,scripts}/**/*.ts\"",
46-
"test": "jest --passWithNoTests",
46+
"test": "jest",
4747
"test:watch": "jest --watch"
4848
},
4949
"volta": {

packages/svelte/src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
export default null;
1+
export * from '@sentry/browser';
2+
3+
export { init } from './sdk';

packages/svelte/src/sdk.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { BrowserOptions, init as browserInit, SDK_VERSION } from '@sentry/browser';
2+
3+
/**
4+
* Inits the Svelte SDK
5+
*/
6+
export function init(options: BrowserOptions): void {
7+
options._metadata = options._metadata || {};
8+
options._metadata.sdk = {
9+
name: 'sentry.javascript.svelte',
10+
packages: [
11+
{
12+
name: 'npm:@sentry/svelte',
13+
version: SDK_VERSION,
14+
},
15+
],
16+
version: SDK_VERSION,
17+
};
18+
19+
browserInit(options);
20+
}

packages/svelte/test/sdk.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { init as browserInitRaw, SDK_VERSION } from '@sentry/browser';
2+
3+
import { init as svelteInit } from '../src/sdk';
4+
5+
const browserInit = browserInitRaw as jest.Mock;
6+
jest.mock('@sentry/browser');
7+
8+
describe('Initialize Svelte SDk', () => {
9+
afterAll(() => {
10+
jest.clearAllMocks();
11+
});
12+
13+
it('has the correct metadata', () => {
14+
svelteInit({
15+
dsn: 'https://public@dsn.ingest.sentry.io/1337',
16+
});
17+
18+
const expectedMetadata = {
19+
_metadata: {
20+
sdk: {
21+
name: 'sentry.javascript.svelte',
22+
packages: [{ name: 'npm:@sentry/svelte', version: SDK_VERSION }],
23+
version: SDK_VERSION,
24+
},
25+
},
26+
};
27+
28+
expect(browserInit).toHaveBeenCalledTimes(1);
29+
expect(browserInit).toHaveBeenCalledWith(expect.objectContaining(expectedMetadata));
30+
});
31+
});

0 commit comments

Comments
 (0)