Skip to content

Commit

Permalink
Init[WIP]
Browse files Browse the repository at this point in the history
  • Loading branch information
aliu39 committed Dec 30, 2024
1 parent 3693a5d commit 90714e1
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/browser/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,4 @@ export {
} from './integrations/featureFlags';
export { launchDarklyIntegration, buildLaunchDarklyFlagUsedHandler } from './integrations/featureFlags/launchdarkly';
export { openFeatureIntegration, OpenFeatureIntegrationHook } from './integrations/featureFlags/openfeature';
export { unleashIntegration } from './integrations/featureFlags/unleash';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { unleashIntegration } from './integration';
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import type { Client, Event, EventHint, IntegrationFn } from '@sentry/core';

import { defineIntegration } from '@sentry/core';
import { copyFlagsFromScopeToEvent, insertFlagToScope } from '../../../utils/featureFlags';
import type { UnleashClient } from './types';

/**
* Sentry integration for capturing feature flags from the Unleash SDK.
*
* See the [feature flag documentation](https://develop.sentry.dev/sdk/expected-features/#feature-flags) for more information.
*
* @example
* ```
* import * as Sentry from '@sentry/browser';
* TODO:
*
* Sentry.init({
* dsn: '___PUBLIC_DSN___',
* integrations: [TODO:]
* });
* ```
*/
export const unleashIntegration = defineIntegration((openFeatureClient: UnleashClient ) => {
return {
name: 'Unleash',

processEvent(event: Event, _hint: EventHint, _client: Client): Event {
return copyFlagsFromScopeToEvent(event);
},

setupOnce() {
openFeatureClient.isEnabled = Proxy();
openFeatureClient.getVariant = Proxy();
},
};
}) satisfies IntegrationFn;
11 changes: 11 additions & 0 deletions packages/browser/src/integrations/featureFlags/unleash/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export type Variant = {
variantName: string;
enabled: boolean;
payload?: object; // TODO:
// TODO:
}

export interface UnleashClient {
isEnabled(featureName: string): boolean;
getVariant(featureName: string): Variant;
}

0 comments on commit 90714e1

Please # to comment.