Skip to content

Commit 6eab55f

Browse files
committed
Fix normalize depth of 3 for contexts.flags, improve docstrings
1 parent 5561633 commit 6eab55f

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

packages/core/src/utils/prepareEvent.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,14 @@ function normalizeEvent(event: Event | null, depth: number, maxBreadth: number):
339339
});
340340
}
341341

342+
// event.contexts.flags (FeatureFlagContext) stores context for our feature
343+
// flag integrations. It has a greater nesting depth than our other typed
344+
// Contexts, so we re-normalize with a fixed depth of 3 here. We do not want
345+
// to skip this in case of conflicting, user-provided context.
346+
if (event.contexts && event.contexts.flags && normalized.contexts) {
347+
normalized.contexts.flags = normalize(event.contexts.flags, 3, maxBreadth);
348+
}
349+
342350
return normalized;
343351
}
344352

packages/launchdarkly/src/core/integration.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* eslint-disable @sentry-internal/sdk/no-class-field-initializers */
2-
31
import * as Sentry from '@sentry/browser';
42
import type { Client as SentryClient, Event, EventHint, IntegrationFn } from '@sentry/types';
53
import type { LDContext, LDEvaluationDetail, LDInspectionFlagUsedHandler } from 'launchdarkly-js-client-sdk';
@@ -9,15 +7,15 @@ import { insertToFlagBuffer } from '@sentry/utils';
97
/**
108
* Sentry integration for capturing feature flags from LaunchDarkly.
119
*
12-
* See the [feature flag documentation](TODO:) for more information.
10+
* See the [feature flag documentation](https://develop.sentry.dev/sdk/expected-features/#feature-flags) for more information.
1311
*
1412
* @example
1513
* ```
16-
* import {SentryInspector, launchDarklyIntegration} from '@sentry/launchdarkly';
14+
* import {buildSentryFlagUsedInspector, buildLaunchDarklyIntegration} from '@sentry/launchdarkly';
1715
* import {LDClient} from 'launchdarkly-js-client-sdk';
1816
*
19-
* Sentry.init(..., integrations: [launchDarklyIntegration()])
20-
* const ldClient = LDClient.initialize(..., inspectors: [SentryInspector]);
17+
* Sentry.init(..., integrations: [buildLaunchDarklyIntegration()])
18+
* const ldClient = LDClient.initialize(..., {inspectors: [buildSentryFlagUsedInspector()]});
2119
* ```
2220
*/
2321
export const buildLaunchDarklyIntegration = ((_options?: LaunchDarklyOptions) => {

packages/types/src/context.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,11 @@ export interface MissingInstrumentationContext extends Record<string, unknown> {
127127
['javascript.is_cjs']?: boolean;
128128
}
129129

130+
/**
131+
* Used to buffer flag evaluation data on the current scope and attach it to
132+
* error events. `values` should be initialized as empty ([]), and it should
133+
* only be modified by @sentry/util "FlagBuffer" methods.
134+
*/
130135
export interface FeatureFlagContext extends Record<string, unknown> {
131-
// This should only be modified by @sentry/util methods (insertToFlagBuffer).
132-
readonly values: FeatureFlag[];
136+
values: FeatureFlag[];
133137
}

0 commit comments

Comments
 (0)