Skip to content

Commit 81f9424

Browse files
authored
chore(tanstackstart-react): Export custom inits from tanstackstart-react (#18369)
Export custom inits to send correct metadata with data sent from the SDK. Closes #18366
1 parent 05f78b4 commit 81f9424

File tree

7 files changed

+128
-7
lines changed

7 files changed

+128
-7
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
export * from '@sentry/react';
2+
3+
export { init } from './sdk';
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import type { Client } from '@sentry/core';
2+
import { applySdkMetadata } from '@sentry/core';
3+
import type { BrowserOptions as ReactBrowserOptions } from '@sentry/react';
4+
import { getDefaultIntegrations as getReactDefaultIntegrations, init as initReactSDK } from '@sentry/react';
5+
6+
/**
7+
* Initializes the TanStack Start React SDK
8+
*
9+
* @param options Configuration options for the SDK.
10+
*/
11+
export function init(options: ReactBrowserOptions): Client | undefined {
12+
const sentryOptions: ReactBrowserOptions = {
13+
defaultIntegrations: [...getReactDefaultIntegrations(options)],
14+
...options,
15+
};
16+
17+
applySdkMetadata(sentryOptions, 'tanstackstart-react', ['tanstackstart-react', 'react']);
18+
19+
return initReactSDK(sentryOptions);
20+
}

packages/tanstackstart-react/src/server/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
export * from '@sentry/node';
22

3+
export { init } from './sdk';
4+
35
/**
46
* A passthrough error boundary for the server that doesn't depend on any react. Error boundaries don't catch SSR errors
57
* so they should simply be a passthrough.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { applySdkMetadata } from '@sentry/core';
2+
import type { NodeClient, NodeOptions } from '@sentry/node';
3+
import { getDefaultIntegrations as getDefaultNodeIntegrations, init as initNodeSdk } from '@sentry/node';
4+
5+
/**
6+
* Initializes the server side of the TanStack Start React SDK
7+
*/
8+
export function init(options: NodeOptions): NodeClient | undefined {
9+
const sentryOptions: NodeOptions = {
10+
defaultIntegrations: [...getDefaultNodeIntegrations(options)],
11+
...options,
12+
};
13+
14+
applySdkMetadata(sentryOptions, 'tanstackstart-react', ['tanstackstart-react', 'node']);
15+
16+
return initNodeSdk(sentryOptions);
17+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import * as SentryReact from '@sentry/react';
2+
import { SDK_VERSION } from '@sentry/react';
3+
import { beforeEach, describe, expect, it, vi } from 'vitest';
4+
import { init } from '../../src/client';
5+
6+
const reactInit = vi.spyOn(SentryReact, 'init');
7+
8+
describe('TanStack Start React Client SDK', () => {
9+
describe('init', () => {
10+
beforeEach(() => {
11+
vi.clearAllMocks();
12+
});
13+
14+
it('Adds TanStack Start React client metadata to the SDK options', () => {
15+
expect(reactInit).not.toHaveBeenCalled();
16+
17+
init({
18+
dsn: 'https://public@dsn.ingest.sentry.io/1337',
19+
});
20+
21+
const expectedMetadata = {
22+
_metadata: {
23+
sdk: {
24+
name: 'sentry.javascript.tanstackstart-react',
25+
version: SDK_VERSION,
26+
packages: [
27+
{ name: 'npm:@sentry/tanstackstart-react', version: SDK_VERSION },
28+
{ name: 'npm:@sentry/react', version: SDK_VERSION },
29+
],
30+
settings: {
31+
infer_ip: 'never',
32+
},
33+
},
34+
},
35+
};
36+
37+
expect(reactInit).toHaveBeenCalledTimes(1);
38+
expect(reactInit).toHaveBeenLastCalledWith(expect.objectContaining(expectedMetadata));
39+
});
40+
41+
it('returns client from init', () => {
42+
expect(init({})).not.toBeUndefined();
43+
});
44+
});
45+
});
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import * as SentryNode from '@sentry/node';
2+
import { SDK_VERSION } from '@sentry/node';
3+
import { beforeEach, describe, expect, it, vi } from 'vitest';
4+
import { init } from '../../src/server';
5+
6+
const nodeInit = vi.spyOn(SentryNode, 'init');
7+
8+
describe('TanStack Start React Server SDK', () => {
9+
describe('init', () => {
10+
beforeEach(() => {
11+
vi.clearAllMocks();
12+
});
13+
14+
it('Adds TanStack Start React server metadata to the SDK options', () => {
15+
expect(nodeInit).not.toHaveBeenCalled();
16+
17+
init({
18+
dsn: 'https://public@dsn.ingest.sentry.io/1337',
19+
});
20+
21+
const expectedMetadata = {
22+
_metadata: {
23+
sdk: {
24+
name: 'sentry.javascript.tanstackstart-react',
25+
version: SDK_VERSION,
26+
packages: [
27+
{ name: 'npm:@sentry/tanstackstart-react', version: SDK_VERSION },
28+
{ name: 'npm:@sentry/node', version: SDK_VERSION },
29+
],
30+
},
31+
},
32+
};
33+
34+
expect(nodeInit).toHaveBeenCalledTimes(1);
35+
expect(nodeInit).toHaveBeenLastCalledWith(expect.objectContaining(expectedMetadata));
36+
});
37+
38+
it('returns client from init', () => {
39+
expect(init({})).not.toBeUndefined();
40+
});
41+
});
42+
});

packages/tanstackstart-react/test/temp.test.ts

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

0 commit comments

Comments
 (0)