Skip to content

Commit 7dc13b3

Browse files
committed
export launchdarkly integration shims in nextjs
1 parent 9659275 commit 7dc13b3

File tree

6 files changed

+50
-12
lines changed

6 files changed

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

packages/nextjs/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@
9494
"devDependencies": {
9595
"@types/resolve": "1.20.3",
9696
"eslint-plugin-react": "^7.31.11",
97-
"next": "13.2.0"
97+
"next": "13.2.0",
98+
"@sentry-internal/integration-shims": "9.31.0"
9899
},
99100
"peerDependencies": {
100101
"next": "^13.2.0 || ^14.0 || ^15.0.0-rc.0"

packages/nextjs/src/index.types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,6 @@ export declare function wrapApiHandlerWithSentryVercelCrons<F extends (...args:
138138
export declare function wrapPageComponentWithSentry<C>(WrappingTarget: C): C;
139139

140140
export { captureRequestError } from './common/captureRequestError';
141+
142+
export declare const launchDarklyIntegration: typeof clientSdk.launchDarklyIntegration;
143+
export declare const buildLaunchDarklyFlagUsedHandler: typeof clientSdk.buildLaunchDarklyFlagUsedHandler;

packages/nextjs/src/server/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,3 +389,8 @@ 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';

yarn.lock

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24560,16 +24560,6 @@ quick-format-unescaped@^4.0.3:
2456024560
resolved "https://registry.yarnpkg.com/quick-format-unescaped/-/quick-format-unescaped-4.0.4.tgz#93ef6dd8d3453cbc7970dd614fad4c5954d6b5a7"
2456124561
integrity sha512-tYC1Q1hgyRuHgloV/YXs2w15unPVh8qfu/qCTfhTYamaw7fyhumKa2yGpdSo87vY32rIclj+4fWYQXUMs9EHvg==
2456224562

24563-
quick-format-unescaped@^4.0.3:
24564-
version "4.0.4"
24565-
resolved "https://registry.yarnpkg.com/quick-format-unescaped/-/quick-format-unescaped-4.0.4.tgz#93ef6dd8d3453cbc7970dd614fad4c5954d6b5a7"
24566-
integrity sha512-tYC1Q1hgyRuHgloV/YXs2w15unPVh8qfu/qCTfhTYamaw7fyhumKa2yGpdSo87vY32rIclj+4fWYQXUMs9EHvg==
24567-
24568-
quick-format-unescaped@^4.0.3:
24569-
version "4.0.4"
24570-
resolved "https://registry.yarnpkg.com/quick-format-unescaped/-/quick-format-unescaped-4.0.4.tgz#93ef6dd8d3453cbc7970dd614fad4c5954d6b5a7"
24571-
integrity sha512-tYC1Q1hgyRuHgloV/YXs2w15unPVh8qfu/qCTfhTYamaw7fyhumKa2yGpdSo87vY32rIclj+4fWYQXUMs9EHvg==
24572-
2457324563
quick-lru@^4.0.1:
2457424564
version "4.0.1"
2457524565
resolved "https://registry.yarnpkg.com/quick-lru/-/quick-lru-4.0.1.tgz#5b8878f113a58217848c6482026c73e1ba57727f"
@@ -29289,7 +29279,7 @@ vite@^5.0.0, vite@^5.4.11, vite@^5.4.5:
2928929279
optionalDependencies:
2929029280
fsevents "~2.3.3"
2929129281

29292-
vitefu@^0.2.2, vitefu@^0.2.4, vitefu@^0.2.5:
29282+
vitefu@^0.2.2, vitefu@^0.2.4:
2929329283
version "0.2.5"
2929429284
resolved "https://registry.yarnpkg.com/vitefu/-/vitefu-0.2.5.tgz#c1b93c377fbdd3e5ddd69840ea3aa70b40d90969"
2929529285
integrity sha512-SgHtMLoqaeeGnd2evZ849ZbACbnwQCIwRH57t18FxcXoZop0uQu0uzlIhJBlF/eWVzuce0sHeqPcDo+evVcg8Q==

0 commit comments

Comments
 (0)