Skip to content

Commit 7b14926

Browse files
committed
Move util to browser pkg
1 parent aef6dba commit 7b14926

File tree

7 files changed

+16
-10
lines changed

7 files changed

+16
-10
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { expect } from '@playwright/test';
33
import { sentryTest } from '../../../../utils/fixtures';
44

55
import { envelopeRequestParser, waitForErrorRequest } from '../../../../utils/helpers';
6+
// import { FLAG_BUFFER_SIZE } from '@sentry/browser'; // TODO: not picking up export atm
7+
const FLAG_BUFFER_SIZE = 100;
68

79
sentryTest('e2e test', async ({ getLocalTestPath, page }) => {
810
await page.route('https://dsn.ingest.sentry.io/**/*', route => {
@@ -18,10 +20,10 @@ sentryTest('e2e test', async ({ getLocalTestPath, page }) => {
1820

1921
await page.waitForFunction(() => {
2022
const ldClient = (window as any).InitializeLD();
21-
for (let i = 1; i <= 100; i++) { // TODO: import constant for buffer size
23+
for (let i = 1; i <= FLAG_BUFFER_SIZE; i++) { // TODO: import constant for buffer size
2224
ldClient.variation(`feat${i}`, false);
2325
}
24-
ldClient.variation('feat101', true); // eviction
26+
ldClient.variation(`feat${FLAG_BUFFER_SIZE+1}`, true); // eviction
2527
ldClient.variation('feat3', true); // update
2628
return true;
2729
});
@@ -32,10 +34,10 @@ sentryTest('e2e test', async ({ getLocalTestPath, page }) => {
3234
const event = envelopeRequestParser(req);
3335

3436
const expectedFlags = [{ flag: 'feat2', result: false }];
35-
for (let i = 4; i <= 100; i++) {
37+
for (let i = 4; i <= FLAG_BUFFER_SIZE; i++) {
3638
expectedFlags.push({ flag: `feat${i}`, result: false });
3739
}
38-
expectedFlags.push({ flag: 'feat101', result: true });
40+
expectedFlags.push({ flag: `feat${FLAG_BUFFER_SIZE + 1}`, result: true });
3941
expectedFlags.push({ flag: 'feat3', result: true });
4042

4143
expect(event.contexts?.flags?.values).toEqual(expectedFlags);

packages/browser/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,4 @@ export { makeBrowserOfflineTransport } from './transports/offline';
7676
export { browserProfilingIntegration } from './profiling/integration';
7777
export { spotlightBrowserIntegration } from './integrations/spotlight';
7878
export { launchDarklyIntegration, buildLaunchDarklyFlagUsedHandler } from './integrations/launchdarkly';
79+
export { FLAG_BUFFER_SIZE } from './utils/flags';

packages/browser/src/integrations/launchdarkly.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Client, Event, EventHint, IntegrationFn } from '@sentry/types';
22
import type { LDContext, LDEvaluationDetail, LDInspectionFlagUsedHandler } from 'launchdarkly-js-client-sdk';
33

4-
import { insertToFlagBuffer } from '@sentry/utils';
4+
import { insertToFlagBuffer } from '../utils/flags'
55
import { defineIntegration, getCurrentScope } from '@sentry/core';
66

77
/**

packages/utils/src/flags.ts renamed to packages/browser/src/utils/flags.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import type { FeatureFlag } from '@sentry/types';
66
* from oldest to newest.
77
*/
88

9-
export const DEFAULT_MAX_SIZE = 100;
9+
/**
10+
* Max size of the LRU flag buffer stored in Sentry scope and event contexts.
11+
*/
12+
export const FLAG_BUFFER_SIZE = 100;
1013

1114
/**
1215
* Insert into a FeatureFlag array while maintaining ordered LRU properties. Not
@@ -26,7 +29,7 @@ export function insertToFlagBuffer(
2629
flags: FeatureFlag[],
2730
name: string,
2831
value: boolean,
29-
maxSize: number = DEFAULT_MAX_SIZE,
32+
maxSize: number = FLAG_BUFFER_SIZE,
3033
): void {
3134
if (flags.length > maxSize) {
3235
throw Error(`insertToFlagBuffer called on a buffer larger than the given maxSize=${maxSize}`);

packages/utils/test/flags.test.ts renamed to packages/browser/test/utils/flags.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
import { insertToFlagBuffer } from '../src';
2+
import { insertToFlagBuffer } from '../../src/utils/flags';
33
import type { FeatureFlag } from '@sentry/types';
44

55
describe('flags', () => {

packages/core/src/scope.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ class ScopeClass implements ScopeInterface {
129129
newScope._extra = { ...this._extra };
130130
newScope._contexts = { ...this._contexts };
131131
if (this._contexts.flags) {
132-
// The flags context needs a deep copy.
132+
// We need to copy the `values` array so insertions on a cloned scope
133+
// won't affect the original array.
133134
newScope._contexts.flags = {
134135
values: [...this._contexts.flags.values]
135136
}

packages/utils/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,3 @@ export * from './propagationContext';
4141
export * from './vercelWaitUntil';
4242
export * from './version';
4343
export * from './debug-ids';
44-
export * from './flags';

0 commit comments

Comments
 (0)