Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/tanstackstart-react/src/client/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export * from '@sentry/react';

export { init } from './sdk';
20 changes: 20 additions & 0 deletions packages/tanstackstart-react/src/client/sdk.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { Client } from '@sentry/core';
import { applySdkMetadata } from '@sentry/core';
import type { BrowserOptions as ReactBrowserOptions } from '@sentry/react';
import { getDefaultIntegrations as getReactDefaultIntegrations, init as initReactSDK } from '@sentry/react';

/**
* Initializes the TanStack Start React SDK
*
* @param options Configuration options for the SDK.
*/
export function init(options: ReactBrowserOptions): Client | undefined {
const sentryOptions: ReactBrowserOptions = {
defaultIntegrations: [...getReactDefaultIntegrations(options)],
...options,
};

applySdkMetadata(sentryOptions, 'tanstackstart-react', ['tanstackstart-react', 'react']);

return initReactSDK(sentryOptions);
}
2 changes: 2 additions & 0 deletions packages/tanstackstart-react/src/server/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export * from '@sentry/node';

export { init } from './sdk';

/**
* A passthrough error boundary for the server that doesn't depend on any react. Error boundaries don't catch SSR errors
* so they should simply be a passthrough.
Expand Down
17 changes: 17 additions & 0 deletions packages/tanstackstart-react/src/server/sdk.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { applySdkMetadata } from '@sentry/core';
import type { NodeClient, NodeOptions } from '@sentry/node';
import { getDefaultIntegrations as getDefaultNodeIntegrations, init as initNodeSdk } from '@sentry/node';

/**
* Initializes the server side of the TanStack Start React SDK
*/
export function init(options: NodeOptions): NodeClient | undefined {
const sentryOptions: NodeOptions = {
defaultIntegrations: [...getDefaultNodeIntegrations(options)],
...options,
};

applySdkMetadata(sentryOptions, 'tanstackstart-react', ['tanstackstart-react', 'node']);

return initNodeSdk(sentryOptions);
}
45 changes: 45 additions & 0 deletions packages/tanstackstart-react/test/client/sdk.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import * as SentryReact from '@sentry/react';
import { SDK_VERSION } from '@sentry/react';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { init } from '../../src/client';

const reactInit = vi.spyOn(SentryReact, 'init');

describe('TanStack Start React Client SDK', () => {
describe('init', () => {
beforeEach(() => {
vi.clearAllMocks();
});

it('Adds TanStack Start React client metadata to the SDK options', () => {
expect(reactInit).not.toHaveBeenCalled();

init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
});

const expectedMetadata = {
_metadata: {
sdk: {
name: 'sentry.javascript.tanstackstart-react',
version: SDK_VERSION,
packages: [
{ name: 'npm:@sentry/tanstackstart-react', version: SDK_VERSION },
{ name: 'npm:@sentry/react', version: SDK_VERSION },
],
settings: {
infer_ip: 'never',
},
},
},
};

expect(reactInit).toHaveBeenCalledTimes(1);
expect(reactInit).toHaveBeenLastCalledWith(expect.objectContaining(expectedMetadata));
});

it('returns client from init', () => {
expect(init({})).not.toBeUndefined();
});
});
});
42 changes: 42 additions & 0 deletions packages/tanstackstart-react/test/server/sdk.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import * as SentryNode from '@sentry/node';
import { SDK_VERSION } from '@sentry/node';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { init } from '../../src/server';

const nodeInit = vi.spyOn(SentryNode, 'init');

describe('TanStack Start React Server SDK', () => {
describe('init', () => {
beforeEach(() => {
vi.clearAllMocks();
});

it('Adds TanStack Start React server metadata to the SDK options', () => {
expect(nodeInit).not.toHaveBeenCalled();

init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
});

const expectedMetadata = {
_metadata: {
sdk: {
name: 'sentry.javascript.tanstackstart-react',
version: SDK_VERSION,
packages: [
{ name: 'npm:@sentry/tanstackstart-react', version: SDK_VERSION },
{ name: 'npm:@sentry/node', version: SDK_VERSION },
],
},
},
};

expect(nodeInit).toHaveBeenCalledTimes(1);
expect(nodeInit).toHaveBeenLastCalledWith(expect.objectContaining(expectedMetadata));
});

it('returns client from init', () => {
expect(init({})).not.toBeUndefined();
});
});
});
7 changes: 0 additions & 7 deletions packages/tanstackstart-react/test/temp.test.ts

This file was deleted.