-
-
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 33 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
1 change: 0 additions & 1 deletion
1
dev-packages/browser-integration-tests/suites/integrations/featureFlags/constants.ts
This file was deleted.
Oops, something went wrong.
10 changes: 7 additions & 3 deletions
10
...s/featureFlags/featureFlags/basic/test.ts → ...eFlags/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
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 6 additions & 2 deletions
8
...atureFlags/featureFlags/withScope/test.ts → ...gs/featureFlags/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
13 changes: 13 additions & 0 deletions
13
...es/browser-integration-tests/suites/integrations/featureFlags/featureFlags/onSpan/init.js
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 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
|
||
window.Sentry = Sentry; | ||
|
||
Sentry.init({ | ||
dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
sampleRate: 1.0, | ||
tracesSampleRate: 1.0, | ||
integrations: [ | ||
Sentry.browserTracingIntegration({ instrumentNavigation: false, instrumentPageLoad: false }), | ||
Sentry.featureFlagsIntegration(), | ||
], | ||
}); |
16 changes: 16 additions & 0 deletions
16
...browser-integration-tests/suites/integrations/featureFlags/featureFlags/onSpan/subject.js
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 @@ | ||
const btnStartSpan = document.getElementById('btnStartSpan'); | ||
const btnEndSpan = document.getElementById('btnEndSpan'); | ||
const btnStartNestedSpan = document.getElementById('btnStartNestedSpan'); | ||
const btnEndNestedSpan = document.getElementById('btnEndNestedSpan'); | ||
|
||
window.withNestedSpans = callback => { | ||
window.Sentry.startSpan({ name: 'test-root-span' }, rootSpan => { | ||
window.traceId = rootSpan.spanContext().traceId; | ||
|
||
window.Sentry.startSpan({ name: 'test-span' }, _span => { | ||
window.Sentry.startSpan({ name: 'test-nested-span' }, _nestedSpan => { | ||
callback(); | ||
}); | ||
}); | ||
}); | ||
}; |
12 changes: 12 additions & 0 deletions
12
...wser-integration-tests/suites/integrations/featureFlags/featureFlags/onSpan/template.html
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,12 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
</head> | ||
<body> | ||
<button id="btnStartSpan">Start Span</button> | ||
<button id="btnEndSpan">End Span</button> | ||
<button id="btnStartNestedSpan">Start Nested Span</button> | ||
<button id="btnEndNestedSpan">End Nested Span</button> | ||
</body> | ||
</html> |
66 changes: 66 additions & 0 deletions
66
...es/browser-integration-tests/suites/integrations/featureFlags/featureFlags/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,66 @@ | ||
import { expect } from '@playwright/test'; | ||
import { _INTERNAL_MAX_FLAGS_PER_SPAN as MAX_FLAGS_PER_SPAN } from '@sentry/core'; | ||
import { sentryTest } from '../../../../../utils/fixtures'; | ||
import { | ||
type EventAndTraceHeader, | ||
eventAndTraceHeaderRequestParser, | ||
getMultipleSentryEnvelopeRequests, | ||
shouldSkipFeatureFlagsTest, | ||
shouldSkipTracingTest, | ||
} from '../../../../../utils/helpers'; | ||
|
||
sentryTest("Feature flags are added to active span's attributes on span end.", async ({ getLocalTestUrl, page }) => { | ||
if (shouldSkipFeatureFlagsTest() || shouldSkipTracingTest()) { | ||
sentryTest.skip(); | ||
} | ||
|
||
await page.route('https://dsn.ingest.sentry.io/**/*', route => { | ||
return route.fulfill({ | ||
status: 200, | ||
contentType: 'application/json', | ||
body: JSON.stringify({}), | ||
}); | ||
}); | ||
|
||
const url = await getLocalTestUrl({ testDir: __dirname, skipDsnRouteHandler: true }); | ||
await page.goto(url); | ||
|
||
const envelopeRequestPromise = getMultipleSentryEnvelopeRequests<EventAndTraceHeader>( | ||
page, | ||
1, | ||
{}, | ||
eventAndTraceHeaderRequestParser, | ||
); | ||
|
||
// withNestedSpans is a util used to start 3 nested spans: root-span (not recorded in transaction_event.spans), span, and nested-span. | ||
await page.evaluate(maxFlags => { | ||
(window as any).withNestedSpans(() => { | ||
const flagsIntegration = (window as any).Sentry.getClient().getIntegrationByName('FeatureFlags'); | ||
for (let i = 1; i <= maxFlags; i++) { | ||
flagsIntegration.addFeatureFlag(`feat${i}`, false); | ||
} | ||
flagsIntegration.addFeatureFlag(`feat${maxFlags + 1}`, true); // dropped flag | ||
flagsIntegration.addFeatureFlag('feat3', true); // update | ||
}); | ||
return true; | ||
}, MAX_FLAGS_PER_SPAN); | ||
|
||
const event = (await envelopeRequestPromise)[0][0]; | ||
const innerSpan = event.spans?.[0]; | ||
const outerSpan = event.spans?.[1]; | ||
const outerSpanFlags = Object.entries(outerSpan?.data ?? {}).filter(([key, _val]) => | ||
key.startsWith('flag.evaluation'), | ||
); | ||
const innerSpanFlags = Object.entries(innerSpan?.data ?? {}).filter(([key, _val]) => | ||
key.startsWith('flag.evaluation'), | ||
); | ||
|
||
expect(innerSpanFlags).toEqual([]); | ||
|
||
const expectedOuterSpanFlags = []; | ||
for (let i = 1; i <= MAX_FLAGS_PER_SPAN; i++) { | ||
expectedOuterSpanFlags.push([`flag.evaluation.feat${i}`, i === 3]); | ||
} | ||
// Order agnostic (attribute dict is unordered). | ||
expect(outerSpanFlags.sort()).toEqual(expectedOuterSpanFlags.sort()); | ||
}); |
10 changes: 7 additions & 3 deletions
10
...s/featureFlags/launchdarkly/basic/test.ts → ...eFlags/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
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 6 additions & 2 deletions
8
...atureFlags/launchdarkly/withScope/test.ts → ...gs/launchdarkly/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
39 changes: 39 additions & 0 deletions
39
...es/browser-integration-tests/suites/integrations/featureFlags/launchdarkly/onSpan/init.js
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,39 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
|
||
window.Sentry = Sentry; | ||
window.sentryLDIntegration = Sentry.launchDarklyIntegration(); | ||
|
||
Sentry.init({ | ||
dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
sampleRate: 1.0, | ||
tracesSampleRate: 1.0, | ||
integrations: [ | ||
Sentry.browserTracingIntegration({ instrumentNavigation: false, instrumentPageLoad: false }), | ||
window.sentryLDIntegration, | ||
], | ||
}); | ||
|
||
// Manually mocking this because LD only has mock test utils for the React SDK. | ||
// Also, no SDK has mock utils for FlagUsedHandler's. | ||
const MockLaunchDarkly = { | ||
initialize(_clientId, context, options) { | ||
const flagUsedHandler = options.inspectors ? options.inspectors[0].method : undefined; | ||
|
||
return { | ||
variation(key, defaultValue) { | ||
if (flagUsedHandler) { | ||
flagUsedHandler(key, { value: defaultValue }, context); | ||
} | ||
return defaultValue; | ||
}, | ||
}; | ||
}, | ||
}; | ||
|
||
window.initializeLD = () => { | ||
return MockLaunchDarkly.initialize( | ||
'example-client-id', | ||
{ kind: 'user', key: 'example-context-key' }, | ||
{ inspectors: [Sentry.buildLaunchDarklyFlagUsedHandler()] }, | ||
); | ||
}; |
16 changes: 16 additions & 0 deletions
16
...browser-integration-tests/suites/integrations/featureFlags/launchdarkly/onSpan/subject.js
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 @@ | ||
const btnStartSpan = document.getElementById('btnStartSpan'); | ||
const btnEndSpan = document.getElementById('btnEndSpan'); | ||
const btnStartNestedSpan = document.getElementById('btnStartNestedSpan'); | ||
const btnEndNestedSpan = document.getElementById('btnEndNestedSpan'); | ||
|
||
window.withNestedSpans = callback => { | ||
window.Sentry.startSpan({ name: 'test-root-span' }, rootSpan => { | ||
window.traceId = rootSpan.spanContext().traceId; | ||
|
||
window.Sentry.startSpan({ name: 'test-span' }, _span => { | ||
window.Sentry.startSpan({ name: 'test-nested-span' }, _nestedSpan => { | ||
callback(); | ||
}); | ||
}); | ||
}); | ||
}; |
12 changes: 12 additions & 0 deletions
12
...wser-integration-tests/suites/integrations/featureFlags/launchdarkly/onSpan/template.html
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,12 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
</head> | ||
<body> | ||
<button id="btnStartSpan">Start Span</button> | ||
<button id="btnEndSpan">End Span</button> | ||
<button id="btnStartNestedSpan">Start Nested Span</button> | ||
<button id="btnEndNestedSpan">End Nested Span</button> | ||
</body> | ||
</html> |
66 changes: 66 additions & 0 deletions
66
...es/browser-integration-tests/suites/integrations/featureFlags/launchdarkly/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,66 @@ | ||
import { expect } from '@playwright/test'; | ||
import { _INTERNAL_MAX_FLAGS_PER_SPAN as MAX_FLAGS_PER_SPAN } from '@sentry/core'; | ||
import { sentryTest } from '../../../../../utils/fixtures'; | ||
import { | ||
type EventAndTraceHeader, | ||
eventAndTraceHeaderRequestParser, | ||
getMultipleSentryEnvelopeRequests, | ||
shouldSkipFeatureFlagsTest, | ||
shouldSkipTracingTest, | ||
} from '../../../../../utils/helpers'; | ||
|
||
sentryTest("Feature flags are added to active span's attributes on span end.", async ({ getLocalTestUrl, page }) => { | ||
if (shouldSkipFeatureFlagsTest() || shouldSkipTracingTest()) { | ||
sentryTest.skip(); | ||
} | ||
|
||
await page.route('https://dsn.ingest.sentry.io/**/*', route => { | ||
return route.fulfill({ | ||
status: 200, | ||
contentType: 'application/json', | ||
body: JSON.stringify({}), | ||
}); | ||
}); | ||
|
||
const url = await getLocalTestUrl({ testDir: __dirname, skipDsnRouteHandler: true }); | ||
await page.goto(url); | ||
|
||
const envelopeRequestPromise = getMultipleSentryEnvelopeRequests<EventAndTraceHeader>( | ||
page, | ||
1, | ||
{}, | ||
eventAndTraceHeaderRequestParser, | ||
); | ||
|
||
// withNestedSpans is a util used to start 3 nested spans: root-span (not recorded in transaction_event.spans), span, and nested-span. | ||
await page.evaluate(maxFlags => { | ||
(window as any).withNestedSpans(() => { | ||
const ldClient = (window as any).initializeLD(); | ||
for (let i = 1; i <= maxFlags; i++) { | ||
ldClient.variation(`feat${i}`, false); | ||
} | ||
ldClient.variation(`feat${maxFlags + 1}`, true); // dropped | ||
ldClient.variation('feat3', true); // update | ||
}); | ||
return true; | ||
}, MAX_FLAGS_PER_SPAN); | ||
|
||
const event = (await envelopeRequestPromise)[0][0]; | ||
const innerSpan = event.spans?.[0]; | ||
const outerSpan = event.spans?.[1]; | ||
const outerSpanFlags = Object.entries(outerSpan?.data ?? {}).filter(([key, _val]) => | ||
key.startsWith('flag.evaluation'), | ||
); | ||
const innerSpanFlags = Object.entries(innerSpan?.data ?? {}).filter(([key, _val]) => | ||
key.startsWith('flag.evaluation'), | ||
); | ||
|
||
expect(innerSpanFlags).toEqual([]); | ||
|
||
const expectedOuterSpanFlags = []; | ||
for (let i = 1; i <= MAX_FLAGS_PER_SPAN; i++) { | ||
expectedOuterSpanFlags.push([`flag.evaluation.feat${i}`, i === 3]); | ||
} | ||
// Order agnostic (attribute dict is unordered). | ||
expect(outerSpanFlags.sort()).toEqual(expectedOuterSpanFlags.sort()); | ||
}); |
10 changes: 7 additions & 3 deletions
10
...ns/featureFlags/openfeature/basic/test.ts → ...reFlags/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
File renamed without changes.
10 changes: 7 additions & 3 deletions
10
...eatureFlags/openfeature/errorHook/test.ts → ...ags/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
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 6 additions & 2 deletions
8
...eatureFlags/openfeature/withScope/test.ts → ...ags/openfeature/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
24 changes: 24 additions & 0 deletions
24
...ges/browser-integration-tests/suites/integrations/featureFlags/openfeature/onSpan/init.js
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,24 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
|
||
window.Sentry = Sentry; | ||
window.sentryOpenFeatureIntegration = Sentry.openFeatureIntegration(); | ||
|
||
Sentry.init({ | ||
dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
sampleRate: 1.0, | ||
tracesSampleRate: 1.0, | ||
integrations: [ | ||
window.sentryOpenFeatureIntegration, | ||
Sentry.browserTracingIntegration({ instrumentNavigation: false, instrumentPageLoad: false }), | ||
], | ||
}); | ||
|
||
window.initialize = () => { | ||
return { | ||
getBooleanValue(flag, value) { | ||
let hook = new Sentry.OpenFeatureIntegrationHook(); | ||
hook.after(null, { flagKey: flag, value: value }); | ||
return value; | ||
}, | ||
}; | ||
}; |
16 changes: 16 additions & 0 deletions
16
.../browser-integration-tests/suites/integrations/featureFlags/openfeature/onSpan/subject.js
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 @@ | ||
const btnStartSpan = document.getElementById('btnStartSpan'); | ||
const btnEndSpan = document.getElementById('btnEndSpan'); | ||
const btnStartNestedSpan = document.getElementById('btnStartNestedSpan'); | ||
const btnEndNestedSpan = document.getElementById('btnEndNestedSpan'); | ||
|
||
window.withNestedSpans = callback => { | ||
window.Sentry.startSpan({ name: 'test-root-span' }, rootSpan => { | ||
window.traceId = rootSpan.spanContext().traceId; | ||
|
||
window.Sentry.startSpan({ name: 'test-span' }, _span => { | ||
window.Sentry.startSpan({ name: 'test-nested-span' }, _nestedSpan => { | ||
callback(); | ||
}); | ||
}); | ||
}); | ||
}; |
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 😢)