Skip to content

Commit b28bc63

Browse files
committed
Revert "Move api to top-level, rename addFlag"
This reverts commit 94c120e.
1 parent 94c120e commit b28bc63

File tree

7 files changed

+37
-37
lines changed

7 files changed

+37
-37
lines changed

dev-packages/browser-integration-tests/suites/integrations/featureFlags/featureFlags/basic/test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ sentryTest('Basic test with eviction, update, and no async tasks', async ({ getL
2323
await page.goto(url);
2424

2525
await page.evaluate(bufferSize => {
26-
const Sentry = (window as any).Sentry;
26+
const flagsIntegration = (window as any).Sentry.getClient().getIntegrationByName('FeatureFlags');
2727
for (let i = 1; i <= bufferSize; i++) {
28-
Sentry.addFlag(`feat${i}`, false);
28+
flagsIntegration.setFlag(`feat${i}`, false);
2929
}
30-
Sentry.addFlag(`feat${bufferSize + 1}`, true); // eviction
31-
Sentry.addFlag('feat3', true); // update
30+
flagsIntegration.setFlag(`feat${bufferSize + 1}`, true); // eviction
31+
flagsIntegration.setFlag('feat3', true); // update
3232
return true;
3333
}, FLAG_BUFFER_SIZE);
3434

dev-packages/browser-integration-tests/suites/integrations/featureFlags/featureFlags/init.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import * as Sentry from '@sentry/browser';
22

33
window.Sentry = Sentry;
44

5+
// Not using this as we want to test the getIntegrationByName() approach
6+
// window.sentryFeatureFlagsIntegration = Sentry.featureFlagsIntegration();
7+
58
Sentry.init({
69
dsn: 'https://[email protected]/1337',
710
sampleRate: 1.0,

dev-packages/browser-integration-tests/suites/integrations/featureFlags/featureFlags/withScope/test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,20 @@ sentryTest('Flag evaluations in forked scopes are stored separately.', async ({
2828
await page.evaluate(() => {
2929
const Sentry = (window as any).Sentry;
3030
const errorButton = document.querySelector('#error') as HTMLButtonElement;
31+
const flagsIntegration = (window as any).Sentry.getClient().getIntegrationByName('FeatureFlags');
3132

32-
Sentry.addFlag('shared', true);
33+
flagsIntegration.setFlag('shared', true);
3334

3435
Sentry.withScope((scope: Scope) => {
35-
Sentry.addFlag('forked', true);
36-
Sentry.addFlag('shared', false);
36+
flagsIntegration.setFlag('forked', true);
37+
flagsIntegration.setFlag('shared', false);
3738
scope.setTag('isForked', true);
3839
if (errorButton) {
3940
errorButton.click();
4041
}
4142
});
4243

43-
Sentry.addFlag('main', true);
44+
flagsIntegration.setFlag('main', true);
4445
Sentry.getCurrentScope().setTag('isForked', false);
4546
errorButton.click();
4647
return true;

packages/browser/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export { spotlightBrowserIntegration } from './integrations/spotlight';
7171
export { browserSessionIntegration } from './integrations/browsersession';
7272
export {
7373
featureFlagsIntegration,
74-
addFlag,
74+
type FeatureFlagsIntegration,
7575
} from './integrations/featureFlags';
7676
export { launchDarklyIntegration, buildLaunchDarklyFlagUsedHandler } from './integrations/featureFlags/launchdarkly';
7777
export { openFeatureIntegration, OpenFeatureIntegrationHook } from './integrations/featureFlags/openfeature';
Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
import type { Client, Event, EventHint, IntegrationFn } from '@sentry/core';
1+
import type { Client, Event, EventHint, Integration, IntegrationFn } from '@sentry/core';
22

3-
import { defineIntegration, getClient, logger } from '@sentry/core';
3+
import { defineIntegration } from '@sentry/core';
44
import { copyFlagsFromScopeToEvent, insertFlagToScope } from '../../utils/featureFlags';
5-
import { DEBUG_BUILD } from '../../debug-build';
5+
6+
export interface FeatureFlagsIntegration extends Integration {
7+
setFlag: (name: string, value: unknown) => void;
8+
}
69

710
/**
811
* Sentry integration for buffering feature flags manually with an API, and
@@ -14,11 +17,19 @@ import { DEBUG_BUILD } from '../../debug-build';
1417
* @example
1518
* ```
1619
* import * as Sentry from '@sentry/browser';
20+
* import { type FeatureFlagsIntegration } from '@sentry/browser';
1721
*
18-
* Sentry.init(..., integrations: [Sentry.featureFlagsIntegration()]);
22+
* // Setup
23+
* Sentry.init(..., integrations: [Sentry.featureFlagsIntegration()])
1924
*
20-
* Sentry.addFlag('my-flag', true);
21-
* Sentry.captureException(Exception('broke')); // 'my-flag' should be captured on this Sentry event.
25+
* // Verify
26+
* const flagsIntegration = Sentry.getClient()?.getIntegrationByName<FeatureFlagsIntegration>('FeatureFlags');
27+
* if (flagsIntegration) {
28+
* flagsIntegration.setFlag('my-flag', true);
29+
* } else {
30+
* // check your setup
31+
* }
32+
* Sentry.captureException(Exception('broke')); // 'my-flag' should be captured to this Sentry event.
2233
* ```
2334
*/
2435
export const featureFlagsIntegration = defineIntegration(() => {
@@ -27,21 +38,10 @@ export const featureFlagsIntegration = defineIntegration(() => {
2738

2839
processEvent(event: Event, _hint: EventHint, _client: Client): Event {
2940
return copyFlagsFromScopeToEvent(event);
30-
}
31-
};
32-
}) as IntegrationFn;
33-
41+
},
3442

35-
/**
36-
* Records a flag and its value to be sent on subsequent error events. We
37-
* recommend you do this on flag evaluations. Flags are buffered per Sentry
38-
* scope and limited to 100 per event.
39-
*/
40-
export function addFlag(name: string, value: unknown): void {
41-
const client = getClient();
42-
if (!client || !client.getIntegrationByName('FeatureFlags')) {
43-
DEBUG_BUILD && logger.error('Must enable the Feature Flags Integration to use the addFlag function.');
44-
return;
45-
}
46-
insertFlagToScope(name, value);
47-
}
43+
setFlag(name: string, value: unknown): void {
44+
insertFlagToScope(name, value);
45+
},
46+
};
47+
}) as IntegrationFn<FeatureFlagsIntegration>;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export { featureFlagsIntegration, addFlag } from './featureFlagsIntegration';
1+
export { featureFlagsIntegration, type FeatureFlagsIntegration } from './featureFlagsIntegration';

test-results/.last-run.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)