Skip to content

feat(nextjs): Export server-side launchdarkly integration shims #16735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: develop
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions packages/integration-shims/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { feedbackIntegrationShim } from './Feedback';
export { replayIntegrationShim } from './Replay';
export { browserTracingIntegrationShim } from './BrowserTracing';
export { launchDarklyIntegrationShim, buildLaunchDarklyFlagUsedHandlerShim } from './launchDarkly';
38 changes: 38 additions & 0 deletions packages/integration-shims/src/launchDarkly.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { consoleSandbox, defineIntegration, isBrowser } from '@sentry/core';
import { FAKE_FUNCTION } from './common';

/**
* This is a shim for the LaunchDarkly integration.
* We need this in order to not throw runtime errors when accidentally importing this on the server through a meta framework like Next.js.
*/
export const launchDarklyIntegrationShim = defineIntegration((_options?: unknown) => {
if (!isBrowser()) {
consoleSandbox(() => {
// eslint-disable-next-line no-console
console.warn('The launchDarklyIntegration() can only be used in the browser.');
});
}

return {
name: 'LaunchDarkly',
};
});

/**
* This is a shim for the LaunchDarkly flag used handler.
*/
export function buildLaunchDarklyFlagUsedHandlerShim(): unknown {
if (!isBrowser()) {
consoleSandbox(() => {
// eslint-disable-next-line no-console
console.warn('The buildLaunchDarklyFlagUsedHandler() should only be used in the browser.');
});
}

return {
name: 'sentry-flag-auditor',
type: 'flag-used',
synchronous: true,
method: FAKE_FUNCTION,
};
}
1 change: 1 addition & 0 deletions packages/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
"devDependencies": {
"@types/resolve": "1.20.3",
"eslint-plugin-react": "^7.31.11",
"@sentry-internal/integration-shims": "9.32.0",
"next": "13.5.9"
},
"peerDependencies": {
Expand Down
3 changes: 3 additions & 0 deletions packages/nextjs/src/index.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,6 @@ export declare function wrapApiHandlerWithSentryVercelCrons<F extends (...args:
export declare function wrapPageComponentWithSentry<C>(WrappingTarget: C): C;

export { captureRequestError } from './common/captureRequestError';

export declare const launchDarklyIntegration: typeof clientSdk.launchDarklyIntegration;
export declare const buildLaunchDarklyFlagUsedHandler: typeof clientSdk.buildLaunchDarklyFlagUsedHandler;
5 changes: 5 additions & 0 deletions packages/nextjs/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,3 +389,8 @@ function sdkAlreadyInitialized(): boolean {
export * from '../common';

export { wrapApiHandlerWithSentry } from '../common/pages-router-instrumentation/wrapApiHandlerWithSentry';

export {
launchDarklyIntegrationShim as launchDarklyIntegration,
buildLaunchDarklyFlagUsedHandlerShim as buildLaunchDarklyFlagUsedHandler,
} from '@sentry-internal/integration-shims';
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -29248,7 +29248,7 @@ vite@^5.0.0, vite@^5.4.11, vite@^5.4.5:
optionalDependencies:
fsevents "~2.3.3"

vitefu@^0.2.2, vitefu@^0.2.4, vitefu@^0.2.5:
vitefu@^0.2.2, vitefu@^0.2.4:
version "0.2.5"
resolved "https://registry.yarnpkg.com/vitefu/-/vitefu-0.2.5.tgz#c1b93c377fbdd3e5ddd69840ea3aa70b40d90969"
integrity sha512-SgHtMLoqaeeGnd2evZ849ZbACbnwQCIwRH57t18FxcXoZop0uQu0uzlIhJBlF/eWVzuce0sHeqPcDo+evVcg8Q==
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy