-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(flags): add node support for generic featureFlagsIntegration and move utils to core #16585
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
Merged
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
3f840b4
Buffer with global weakmap and save on spanEnd
aliu39 af6fa72
Update docstrs
aliu39 5453c1f
Attribute prefix const
aliu39 bc183e6
Handle dup evals of same flag
aliu39 bc439c8
Update docstrs. Todo: update util unit tests
aliu39 403a02b
Nest existing tests under onError folders
aliu39 ffe9bcd
Fix imports
aliu39 7c2c161
Fix global type, add unit tests, add generic ffs test
aliu39 e6da588
Add ld test
aliu39 2459a11
Add of, stat, unleash tests
aliu39 3c13997
fmt
aliu39 70ccac1
Dup integration and utils to core, todos in index and integration
aliu39 8085ee8
Reset unrelated otel test
aliu39 6381f91
Import utils from core with _INTERNAL_ prefix
aliu39 a93b0e0
Delete old browser utils and integration and yarn fix
aliu39 4366e5a
Keep browser in docstr example
aliu39 868cd71
Export from same pkgs as zodErrorsIntegration, except remix, solidsta…
aliu39 535932c
Merge branch 'develop' into aliu/span-flags-v2
aliu39 2b9a867
Merge branch 'aliu/span-flags-v2' into aliu/move-ffs-to-core
aliu39 1611330
Add on error node tests. TODO export/import buffer sizes as _INTERNAL
aliu39 8124a40
Merge branch 'aliu/move-ffs-to-core' of https://github.com/getsentry/…
aliu39 9cce949
Add flags to attrs directly on eval
aliu39 52385ee
Rename util
aliu39 90d9289
Move FF type to core utils file
aliu39 bca65dd
Export buffer sizes from core as _INTERNAL_
aliu39 db2fa33
Remove allowEviction
aliu39 2b385a4
Set attr directly on eval instead of in hook
aliu39 44324cc
Remove allowEviction
aliu39 ea6872a
Fix
aliu39 a323c38
Merge branch 'develop' into aliu/span-flags-v2
aliu39 b3d746b
Merge branch 'develop' of https://github.com/getsentry/sentry-javascr…
aliu39 0f4e2f6
Merge branch 'aliu/span-flags-v2' of https://github.com/getsentry/sen…
aliu39 2ace2ae
Fix merge
aliu39 979600c
Merge branch 'develop' of https://github.com/getsentry/sentry-javascr…
aliu39 60f713b
Redel deleted files after merge, import buf sizes in node tests
aliu39 d695910
Lint
aliu39 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
3 changes: 0 additions & 3 deletions
3
dev-packages/browser-integration-tests/suites/integrations/featureFlags/constants.ts
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...ser-integration-tests/suites/integrations/featureFlags/featureFlags/onError/basic/test.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
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
2 changes: 1 addition & 1 deletion
2
...ser-integration-tests/suites/integrations/featureFlags/launchdarkly/onError/basic/test.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
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
2 changes: 1 addition & 1 deletion
2
...wser-integration-tests/suites/integrations/featureFlags/openfeature/onError/basic/test.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
2 changes: 1 addition & 1 deletion
2
...-integration-tests/suites/integrations/featureFlags/openfeature/onError/errorHook/test.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
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
2 changes: 1 addition & 1 deletion
2
.../browser-integration-tests/suites/integrations/featureFlags/statsig/onError/basic/test.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
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
2 changes: 1 addition & 1 deletion
2
.../browser-integration-tests/suites/integrations/featureFlags/unleash/onError/basic/test.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
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
19 changes: 19 additions & 0 deletions
19
...e-integration-tests/suites/featureFlags/featureFlagsIntegration/onError/basic/scenario.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,19 @@ | ||
import { _INTERNAL_FLAG_BUFFER_SIZE as FLAG_BUFFER_SIZE } from '@sentry/core'; | ||
import * as Sentry from '@sentry/node'; | ||
import { loggingTransport } from '@sentry-internal/node-integration-tests'; | ||
|
||
Sentry.init({ | ||
dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
sampleRate: 1.0, | ||
transport: loggingTransport, | ||
integrations: [Sentry.featureFlagsIntegration()], | ||
}); | ||
|
||
const flagsIntegration = Sentry.getClient()?.getIntegrationByName<Sentry.FeatureFlagsIntegration>('FeatureFlags'); | ||
for (let i = 1; i <= FLAG_BUFFER_SIZE; i++) { | ||
flagsIntegration?.addFeatureFlag(`feat${i}`, false); | ||
} | ||
flagsIntegration?.addFeatureFlag(`feat${FLAG_BUFFER_SIZE + 1}`, true); // eviction | ||
flagsIntegration?.addFeatureFlag('feat3', true); // update | ||
|
||
throw new Error('Test error'); |
31 changes: 31 additions & 0 deletions
31
.../node-integration-tests/suites/featureFlags/featureFlagsIntegration/onError/basic/test.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,31 @@ | ||
import { _INTERNAL_FLAG_BUFFER_SIZE as FLAG_BUFFER_SIZE } from '@sentry/core'; | ||
import { afterAll, test } from 'vitest'; | ||
import { cleanupChildProcesses, createRunner } from '../../../../../utils/runner'; | ||
|
||
afterAll(() => { | ||
cleanupChildProcesses(); | ||
}); | ||
|
||
test('Flags captured on error with eviction, update, and no async tasks', async () => { | ||
// Based on scenario.ts. | ||
const expectedFlags = [{ flag: 'feat2', result: false }]; | ||
for (let i = 4; i <= FLAG_BUFFER_SIZE; i++) { | ||
expectedFlags.push({ flag: `feat${i}`, result: false }); | ||
} | ||
expectedFlags.push({ flag: `feat${FLAG_BUFFER_SIZE + 1}`, result: true }); | ||
expectedFlags.push({ flag: 'feat3', result: true }); | ||
|
||
await createRunner(__dirname, 'scenario.ts') | ||
.expect({ | ||
event: { | ||
exception: { values: [{ type: 'Error', value: 'Test error' }] }, | ||
contexts: { | ||
flags: { | ||
values: expectedFlags, | ||
}, | ||
}, | ||
}, | ||
}) | ||
.start() | ||
.completed(); | ||
}); |
22 changes: 22 additions & 0 deletions
22
...tegration-tests/suites/featureFlags/featureFlagsIntegration/onError/withScope/scenario.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,22 @@ | ||
import type { Scope } from '@sentry/node'; | ||
import * as Sentry from '@sentry/node'; | ||
import { loggingTransport } from '@sentry-internal/node-integration-tests'; | ||
|
||
Sentry.init({ | ||
dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
sampleRate: 1.0, | ||
transport: loggingTransport, | ||
integrations: [Sentry.featureFlagsIntegration()], | ||
}); | ||
|
||
const flagsIntegration = Sentry.getClient()?.getIntegrationByName<Sentry.FeatureFlagsIntegration>('FeatureFlags'); | ||
flagsIntegration?.addFeatureFlag('shared', true); | ||
|
||
Sentry.withScope((_scope: Scope) => { | ||
flagsIntegration?.addFeatureFlag('forked', true); | ||
flagsIntegration?.addFeatureFlag('shared', false); | ||
Sentry.captureException(new Error('Error in forked scope')); | ||
}); | ||
|
||
flagsIntegration?.addFeatureFlag('main', true); | ||
throw new Error('Error in main scope'); |
38 changes: 38 additions & 0 deletions
38
...e-integration-tests/suites/featureFlags/featureFlagsIntegration/onError/withScope/test.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,38 @@ | ||
import { afterAll, test } from 'vitest'; | ||
import { cleanupChildProcesses, createRunner } from '../../../../../utils/runner'; | ||
|
||
afterAll(() => { | ||
cleanupChildProcesses(); | ||
}); | ||
|
||
test('Flags captured on error are isolated by current scope', async () => { | ||
await createRunner(__dirname, 'scenario.ts') | ||
.expect({ | ||
event: { | ||
exception: { values: [{ type: 'Error', value: 'Error in forked scope' }] }, | ||
contexts: { | ||
flags: { | ||
values: [ | ||
{ flag: 'forked', result: true }, | ||
{ flag: 'shared', result: false }, | ||
], | ||
}, | ||
}, | ||
}, | ||
}) | ||
.expect({ | ||
event: { | ||
exception: { values: [{ type: 'Error', value: 'Error in main scope' }] }, | ||
contexts: { | ||
flags: { | ||
values: [ | ||
{ flag: 'shared', result: true }, | ||
{ flag: 'main', result: true }, | ||
], | ||
}, | ||
}, | ||
}, | ||
}) | ||
.start() | ||
.completed(); | ||
}); |
25 changes: 25 additions & 0 deletions
25
...ges/node-integration-tests/suites/featureFlags/featureFlagsIntegration/onSpan/scenario.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,25 @@ | ||
import { _INTERNAL_MAX_FLAGS_PER_SPAN as MAX_FLAGS_PER_SPAN } from '@sentry/core'; | ||
import * as Sentry from '@sentry/node'; | ||
import { loggingTransport } from '@sentry-internal/node-integration-tests'; | ||
|
||
Sentry.init({ | ||
dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
sampleRate: 1.0, | ||
tracesSampleRate: 1.0, | ||
transport: loggingTransport, | ||
integrations: [Sentry.featureFlagsIntegration()], | ||
}); | ||
|
||
const flagsIntegration = Sentry.getClient()?.getIntegrationByName<Sentry.FeatureFlagsIntegration>('FeatureFlags'); | ||
|
||
Sentry.startSpan({ name: 'test-root-span' }, () => { | ||
Sentry.startSpan({ name: 'test-span' }, () => { | ||
Sentry.startSpan({ name: 'test-nested-span' }, () => { | ||
for (let i = 1; i <= MAX_FLAGS_PER_SPAN; i++) { | ||
flagsIntegration?.addFeatureFlag(`feat${i}`, false); | ||
} | ||
flagsIntegration?.addFeatureFlag(`feat${MAX_FLAGS_PER_SPAN + 1}`, true); // dropped flag | ||
flagsIntegration?.addFeatureFlag('feat3', true); // update | ||
}); | ||
}); | ||
}); |
33 changes: 33 additions & 0 deletions
33
...ackages/node-integration-tests/suites/featureFlags/featureFlagsIntegration/onSpan/test.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,33 @@ | ||
import { _INTERNAL_MAX_FLAGS_PER_SPAN as MAX_FLAGS_PER_SPAN } from '@sentry/core'; | ||
import { afterAll, expect, test } from 'vitest'; | ||
import { cleanupChildProcesses, createRunner } from '../../../../utils/runner'; | ||
|
||
afterAll(() => { | ||
cleanupChildProcesses(); | ||
}); | ||
|
||
test('Flags captured on span attributes with max limit', async () => { | ||
// Based on scenario.ts. | ||
const expectedFlags: Record<string, boolean> = {}; | ||
for (let i = 1; i <= MAX_FLAGS_PER_SPAN; i++) { | ||
expectedFlags[`flag.evaluation.feat${i}`] = i === 3; | ||
} | ||
|
||
await createRunner(__dirname, 'scenario.ts') | ||
.expect({ | ||
transaction: { | ||
spans: [ | ||
expect.objectContaining({ | ||
description: 'test-span', | ||
data: expect.objectContaining({}), | ||
}), | ||
expect.objectContaining({ | ||
description: 'test-nested-span', | ||
data: expect.objectContaining(expectedFlags), | ||
}), | ||
], | ||
}, | ||
}) | ||
.start() | ||
.completed(); | ||
}); |
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this
_INTERNAL
pattern common in the codebase?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is starting with logs - we don't really have a better way to do this because of the way
@sentry/core
is structured atm.We could do subpath exports, but that breaks horribly for some bundlers (esbuild 😢)