Skip to content

Commit db253bd

Browse files
committed
try shim in node
1 parent e17c7f2 commit db253bd

File tree

14 files changed

+79
-6
lines changed

14 files changed

+79
-6
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import * as Sentry from '@sentry/nextjs';
2+
3+
export const dynamic = 'force-dynamic';
4+
5+
export default async function FeatureFlagServerComponent() {
6+
Sentry.buildLaunchDarklyFlagUsedHandler();
7+
8+
return <div>FeatureFlagServerComponent</div>;
9+
}

dev-packages/e2e-tests/test-applications/nextjs-app-dir/tests/server-components.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,10 @@ test('Should capture an error and transaction for a app router page', async ({ p
133133
}),
134134
);
135135
});
136+
137+
test.only('Should not throw error on server component when importing shimmed feature flag function', async ({
138+
page,
139+
}) => {
140+
await page.goto('/server-component/featureFlag');
141+
await expect(page.locator('body')).toContainText('FeatureFlagServerComponent');
142+
});

packages/astro/src/index.types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,7 @@ export declare const Span: clientSdk.Span;
2929

3030
export declare const logger: typeof clientSdk.logger | typeof serverSdk.logger;
3131

32+
export declare const launchDarklyIntegration: typeof clientSdk.launchDarklyIntegration;
33+
export declare const buildLaunchDarklyFlagUsedHandler: typeof clientSdk.buildLaunchDarklyFlagUsedHandler;
34+
3235
export default sentryAstro;

packages/nextjs/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@
9494
"devDependencies": {
9595
"@types/resolve": "1.20.3",
9696
"eslint-plugin-react": "^7.31.11",
97-
"@sentry-internal/integration-shims": "9.32.0",
9897
"next": "13.5.9"
9998
},
10099
"peerDependencies": {

packages/nextjs/src/server/index.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,3 @@ function sdkAlreadyInitialized(): boolean {
389389
export * from '../common';
390390

391391
export { wrapApiHandlerWithSentry } from '../common/pages-router-instrumentation/wrapApiHandlerWithSentry';
392-
393-
export {
394-
launchDarklyIntegrationShim as launchDarklyIntegration,
395-
buildLaunchDarklyFlagUsedHandlerShim as buildLaunchDarklyFlagUsedHandler,
396-
} from '@sentry-internal/integration-shims';

packages/node/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export { amqplibIntegration } from './integrations/tracing/amqplib';
3636
export { vercelAIIntegration } from './integrations/tracing/vercelai';
3737
export { childProcessIntegration } from './integrations/childProcess';
3838
export { createSentryWinstonTransport } from './integrations/winston';
39+
export { launchDarklyIntegration, buildLaunchDarklyFlagUsedHandler } from './integrations/featureFlagShims';
3940

4041
export { SentryContextManager } from './otel/contextManager';
4142
export { generateInstrumentOnce } from './otel/instrument';
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export {
2+
launchDarklyIntegrationShim as launchDarklyIntegration,
3+
buildLaunchDarklyFlagUsedHandlerShim as buildLaunchDarklyFlagUsedHandler,
4+
} from './launchDarkly';
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { consoleSandbox, defineIntegration, isBrowser } from '@sentry/core';
2+
3+
/**
4+
* This is a shim for the LaunchDarkly integration.
5+
* We need this in order to not throw runtime errors when accidentally importing this on the server through a meta framework like Next.js.
6+
*/
7+
export const launchDarklyIntegrationShim = defineIntegration((_options?: unknown) => {
8+
if (!isBrowser()) {
9+
consoleSandbox(() => {
10+
// eslint-disable-next-line no-console
11+
console.warn('The launchDarklyIntegration() can only be used in the browser.');
12+
});
13+
}
14+
15+
return {
16+
name: 'LaunchDarkly',
17+
};
18+
});
19+
20+
/**
21+
* This is a shim for the LaunchDarkly flag used handler.
22+
*/
23+
export function buildLaunchDarklyFlagUsedHandlerShim(): unknown {
24+
if (!isBrowser()) {
25+
consoleSandbox(() => {
26+
// eslint-disable-next-line no-console
27+
console.warn('The buildLaunchDarklyFlagUsedHandler() can only be used in the browser.');
28+
});
29+
}
30+
31+
return {
32+
name: 'sentry-flag-auditor',
33+
type: 'flag-used',
34+
synchronous: true,
35+
method: () => null,
36+
};
37+
}

packages/nuxt/src/index.types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@ export declare const getDefaultIntegrations: (options: Options) => Integration[]
1818
export declare const defaultStackParser: StackParser;
1919

2020
export declare const logger: typeof clientSdk.logger | typeof serverSdk.logger;
21+
22+
export declare const launchDarklyIntegration: typeof clientSdk.launchDarklyIntegration;
23+
export declare const buildLaunchDarklyFlagUsedHandler: typeof clientSdk.buildLaunchDarklyFlagUsedHandler;

packages/react-router/src/index.types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@ export declare const defaultStackParser: StackParser;
1818
export declare const getDefaultIntegrations: (options: Options) => Integration[];
1919

2020
export declare const logger: typeof clientSdk.logger | typeof serverSdk.logger;
21+
22+
export declare const launchDarklyIntegration: typeof clientSdk.launchDarklyIntegration;
23+
export declare const buildLaunchDarklyFlagUsedHandler: typeof clientSdk.buildLaunchDarklyFlagUsedHandler;

packages/remix/src/index.types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,6 @@ declare const runtime: 'client' | 'server';
3232
export const close = runtime === 'client' ? clientSdk.close : serverSdk.close;
3333
export const flush = runtime === 'client' ? clientSdk.flush : serverSdk.flush;
3434
export const lastEventId = runtime === 'client' ? clientSdk.lastEventId : serverSdk.lastEventId;
35+
36+
export declare const launchDarklyIntegration: typeof clientSdk.launchDarklyIntegration;
37+
export declare const buildLaunchDarklyFlagUsedHandler: typeof clientSdk.buildLaunchDarklyFlagUsedHandler;

packages/solidstart/src/index.types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ export declare function flush(timeout?: number | undefined): PromiseLike<boolean
2525
export declare function lastEventId(): string | undefined;
2626

2727
export declare const logger: typeof clientSdk.logger | typeof serverSdk.logger;
28+
29+
export declare const launchDarklyIntegration: typeof clientSdk.launchDarklyIntegration;
30+
export declare const buildLaunchDarklyFlagUsedHandler: typeof clientSdk.buildLaunchDarklyFlagUsedHandler;

packages/sveltekit/src/index.types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,6 @@ export declare function lastEventId(): string | undefined;
5656
export declare function trackComponent(options: clientSdk.TrackingOptions): ReturnType<typeof clientSdk.trackComponent>;
5757

5858
export declare const logger: typeof clientSdk.logger | typeof serverSdk.logger;
59+
60+
export declare const launchDarklyIntegration: typeof clientSdk.launchDarklyIntegration;
61+
export declare const buildLaunchDarklyFlagUsedHandler: typeof clientSdk.buildLaunchDarklyFlagUsedHandler;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,6 @@ export declare const showReportDialog: typeof clientSdk.showReportDialog;
2828
export declare const withErrorBoundary: typeof clientSdk.withErrorBoundary;
2929

3030
export declare const logger: typeof clientSdk.logger | typeof serverSdk.logger;
31+
32+
export declare const launchDarklyIntegration: typeof clientSdk.launchDarklyIntegration;
33+
export declare const buildLaunchDarklyFlagUsedHandler: typeof clientSdk.buildLaunchDarklyFlagUsedHandler;

0 commit comments

Comments
 (0)