-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathintegration.ts
More file actions
55 lines (51 loc) · 1.81 KB
/
integration.ts
File metadata and controls
55 lines (51 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import type { Client, Event, EventHint, IntegrationFn, Span } from '@sentry/core';
import {
_INTERNAL_bufferSpanFeatureFlag,
_INTERNAL_copyFlagsFromScopeToEvent,
_INTERNAL_freezeSpanFeatureFlags,
_INTERNAL_insertFlagToScope,
defineIntegration,
} from '@sentry/core';
import type { FeatureGate, StatsigClient } from './types';
/**
* Sentry integration for capturing feature flag evaluations from the Statsig js-client SDK.
*
* See the [feature flag documentation](https://develop.sentry.dev/sdk/expected-features/#feature-flags) for more information.
*
* @example
* ```
* import { StatsigClient } from '@statsig/js-client';
* import * as Sentry from '@sentry/browser';
*
* const statsigClient = new StatsigClient();
*
* Sentry.init({
* dsn: '___PUBLIC_DSN___',
* integrations: [Sentry.statsigIntegration({featureFlagClient: statsigClient})],
* });
*
* await statsigClient.initializeAsync(); // or statsigClient.initializeSync();
*
* const result = statsigClient.checkGate('my-feature-gate');
* Sentry.captureException(new Error('something went wrong'));
* ```
*/
export const statsigIntegration = defineIntegration(
({ featureFlagClient: statsigClient }: { featureFlagClient: StatsigClient }) => {
return {
name: 'Statsig',
setup(client: Client) {
client.on('spanEnd', (span: Span) => {
_INTERNAL_freezeSpanFeatureFlags(span);
});
statsigClient.on('gate_evaluation', (event: { gate: FeatureGate }) => {
_INTERNAL_insertFlagToScope(event.gate.name, event.gate.value);
_INTERNAL_bufferSpanFeatureFlag(event.gate.name, event.gate.value);
});
},
processEvent(event: Event, _hint: EventHint, _client: Client): Event {
return _INTERNAL_copyFlagsFromScopeToEvent(event);
},
};
},
) satisfies IntegrationFn;