-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(node): Export server-side feature flag 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
Merged
+284
−0
Merged
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
7dc13b3
export launchdarkly integration shims in nextjs
chargome 2ae52ae
Merge branch 'develop' into cg-ff-shim
chargome c1d9b8a
.
chargome 45efe99
oh lord
chargome e17c7f2
Merge branch 'develop' into cg-ff-shim
chargome db253bd
try shim in node
chargome 8b229f0
.
chargome 35d682c
add missing node exports
chargome f2e0be1
Merge branch 'develop' into cg-ff-shim
chargome 2b7f708
add all integrations
chargome 7f83080
ts-ignore the args
chargome d566ee7
beep
chargome 5e55bef
Update packages/integration-shims/src/launchDarkly.ts
chargome File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
...ages/e2e-tests/test-applications/nextjs-app-dir/app/server-component/featureFlag/page.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import * as Sentry from '@sentry/nextjs'; | ||
|
||
export const dynamic = 'force-dynamic'; | ||
|
||
export default async function FeatureFlagServerComponent() { | ||
Sentry.buildLaunchDarklyFlagUsedHandler(); | ||
Sentry.launchDarklyIntegration(); | ||
Sentry.openFeatureIntegration(); | ||
new Sentry.OpenFeatureIntegrationHook(); | ||
// @ts-ignore - we just want to test that the statsigIntegration is imported | ||
Sentry.statsigIntegration(); | ||
// @ts-ignore - we just want to test that the unleashIntegration is imported | ||
Sentry.unleashIntegration(); | ||
|
||
return <div>FeatureFlagServerComponent</div>; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export { | ||
launchDarklyIntegrationShim as launchDarklyIntegration, | ||
buildLaunchDarklyFlagUsedHandlerShim as buildLaunchDarklyFlagUsedHandler, | ||
} from './launchDarkly'; | ||
|
||
export { | ||
openFeatureIntegrationShim as openFeatureIntegration, | ||
OpenFeatureIntegrationHookShim as OpenFeatureIntegrationHook, | ||
} from './openFeature'; | ||
|
||
export { statsigIntegrationShim as statsigIntegration } from './statsig'; | ||
|
||
export { unleashIntegrationShim as unleashIntegration } from './unleash'; |
37 changes: 37 additions & 0 deletions
37
packages/node/src/integrations/featureFlagShims/launchDarkly.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { consoleSandbox, defineIntegration, isBrowser } from '@sentry/core'; | ||
|
||
/** | ||
* 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() can only be used in the browser.'); | ||
}); | ||
} | ||
|
||
return { | ||
name: 'sentry-flag-auditor', | ||
type: 'flag-used', | ||
synchronous: true, | ||
method: () => null, | ||
}; | ||
} |
49 changes: 49 additions & 0 deletions
49
packages/node/src/integrations/featureFlagShims/openFeature.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { consoleSandbox, defineIntegration, isBrowser } from '@sentry/core'; | ||
|
||
/** | ||
* This is a shim for the OpenFeature 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 openFeatureIntegrationShim = defineIntegration((_options?: unknown) => { | ||
if (!isBrowser()) { | ||
consoleSandbox(() => { | ||
// eslint-disable-next-line no-console | ||
console.warn('The openFeatureIntegration() can only be used in the browser.'); | ||
}); | ||
} | ||
|
||
return { | ||
name: 'OpenFeature', | ||
}; | ||
}); | ||
|
||
/** | ||
* This is a shim for the OpenFeature integration hook. | ||
*/ | ||
export class OpenFeatureIntegrationHookShim { | ||
/** | ||
* | ||
*/ | ||
public constructor() { | ||
if (!isBrowser()) { | ||
consoleSandbox(() => { | ||
// eslint-disable-next-line no-console | ||
console.warn('The OpenFeatureIntegrationHook can only be used in the browser.'); | ||
}); | ||
} | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
public after(): void { | ||
// No-op | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
public error(): void { | ||
// No-op | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
packages/node/src/integrations/featureFlagShims/statsig.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { consoleSandbox, defineIntegration, isBrowser } from '@sentry/core'; | ||
|
||
/** | ||
* This is a shim for the Statsig 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 statsigIntegrationShim = defineIntegration((_options?: unknown) => { | ||
if (!isBrowser()) { | ||
consoleSandbox(() => { | ||
// eslint-disable-next-line no-console | ||
console.warn('The statsigIntegration() can only be used in the browser.'); | ||
}); | ||
} | ||
|
||
return { | ||
name: 'Statsig', | ||
}; | ||
}); |
18 changes: 18 additions & 0 deletions
18
packages/node/src/integrations/featureFlagShims/unleash.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { consoleSandbox, defineIntegration, isBrowser } from '@sentry/core'; | ||
|
||
/** | ||
* This is a shim for the Unleash 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 unleashIntegrationShim = defineIntegration((_options?: unknown) => { | ||
if (!isBrowser()) { | ||
consoleSandbox(() => { | ||
// eslint-disable-next-line no-console | ||
console.warn('The unleashIntegration() can only be used in the browser.'); | ||
}); | ||
} | ||
|
||
return { | ||
name: 'Unleash', | ||
}; | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.