Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ export const getRouter = () => {
Sentry.init({
environment: 'qa', // dynamic sampling bias to keep transactions
dsn: 'https://public@dsn.ingest.sentry.io/1337',
integrations: [Sentry.tanstackRouterBrowserTracingIntegration(router)],
// We recommend adjusting this value in production, or using tracesSampler
// for finer control
tracesSampleRate: 1.0,
router: router,
release: 'e2e-test',
tunnel: 'http://localhost:3031/', // proxy server
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { expect, test } from '@playwright/test';
import { waitForTransaction } from '@sentry-internal/test-utils';

// we have more thorough tests for tanstack-router in a separate e2e test
// so here we just do a basic check to verify that the integration is automatically enabled if tracing is enabled
test('sends a pageload transaction', async ({ page }) => {
const transactionPromise = waitForTransaction('tanstackstart-react', async transactionEvent => {
return !!transactionEvent?.transaction && transactionEvent.contexts?.trace?.op === 'pageload';
});

await page.goto(`/`);

const rootSpan = await transactionPromise;

expect(rootSpan).toMatchObject({
contexts: {
trace: {
data: {
'sentry.source': 'route',
'sentry.origin': 'auto.pageload.react.tanstack_router',
'sentry.op': 'pageload',
},
op: 'pageload',
origin: 'auto.pageload.react.tanstack_router',
},
},
transaction: '/',
transaction_info: {
source: 'route',
},
});
});
1 change: 1 addition & 0 deletions packages/tanstackstart-react/src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
export * from '@sentry/react';

export { init } from './sdk';
export type { TanStackStartBrowserOptions as BrowserOptions } from './sdk';
36 changes: 31 additions & 5 deletions packages/tanstackstart-react/src/client/sdk.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,46 @@
import type { Client } from '@sentry/core';
import type { Client, Integration } 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';
import {
getDefaultIntegrations as getReactDefaultIntegrations,
init as initReactSDK,
tanstackRouterBrowserTracingIntegration,
} from '@sentry/react';

// Treeshakable guard to remove all code related to tracing
declare const __SENTRY_TRACING__: boolean;

export type TanStackStartBrowserOptions = ReactBrowserOptions & {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
router?: any;
};

/**
* 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)],
export function init(options: TanStackStartBrowserOptions): Client | undefined {
const sentryOptions: TanStackStartBrowserOptions = {
defaultIntegrations: getDefaultIntegrations(options),
...options,
};

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

return initReactSDK(sentryOptions);
}

function getDefaultIntegrations(options: TanStackStartBrowserOptions): Integration[] {
const integrations = getReactDefaultIntegrations(options);

// This evaluates to true unless __SENTRY_TRACING__ is text-replaced with "false",
// in which case everything inside will get tree-shaken away
if (typeof __SENTRY_TRACING__ === 'undefined' || __SENTRY_TRACING__) {
if (options.router) {
integrations.push(tanstackRouterBrowserTracingIntegration(options.router));
}
}

return integrations;
}