Skip to content

Commit

Permalink
Add ld to dependencies and skeleton code. Get rid of core/
Browse files Browse the repository at this point in the history
  • Loading branch information
aliu39 committed Oct 29, 2024
1 parent 419cd83 commit 610da4d
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 9 deletions.
3 changes: 2 additions & 1 deletion packages/launchdarkly/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
"dependencies": {
"@sentry/core": "8.35.0",
"@sentry/types": "8.35.0",
"@sentry/utils": "8.35.0"
"@sentry/utils": "8.35.0",
"launchdarkly-js-client-sdk": "^3.5.0"
},
"scripts": {
"build": "run-p build:transpile build:types build:bundle",
Expand Down
Empty file.
9 changes: 3 additions & 6 deletions packages/launchdarkly/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// This file is used as entry point to generate the npm package and CDN bundles.

// export { sendFeedback } from './core/sendFeedback';
// export { buildFeedbackIntegration } from './core/integration';
// export { getFeedback } from './core/getFeedback';
// export { feedbackModalIntegration } from './modal/integration';
// export { feedbackScreenshotIntegration } from './screenshot/integration';
export { launchDarklyIntegration } from './integration';

export { buildLaunchDarklyIntegration } from './core/integration';
// export type {
// } from './types';
43 changes: 43 additions & 0 deletions packages/launchdarkly/src/integration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import type { IntegrationFn } from '@sentry/types';
import type { LDInspectionFlagUsedHandler } from 'launchdarkly-js-client-sdk';
import type { LaunchDarklyOptions } from './types';

/**
* Sentry integration for capturing feature flags from LaunchDarkly.
*
* See the [feature flag documentation](TODO:) for more information.
*
* @example
*
* ```
* Sentry.init({
* dsn: '__DSN__',
* integrations: [Sentry.replayIntegration()],
* });
* ```
*/
export const launchDarklyIntegration = ((options?: LaunchDarklyOptions) => {
const { ldClient } = options;

return {
name: 'launchdarkly',

setup(client) {
// type is Sentry SDK client

// pseudo-code
ldClient.addHandler(FlagUsedHandler());
},
};
}) satisfies IntegrationFn;

// https://launchdarkly.github.io/js-client-sdk/interfaces/LDInspectionFlagUsedHandler.html //TODO: rm this link
class FlagUsedHandler implements LDInspectionFlagUsedHandler {
public name = 'sentry-feature-flag-monitor'; // eslint-disable-line @sentry-internal/sdk/no-class-field-initializers
public synchronous?: boolean;
public type = 'flag-used' as const; // eslint-disable-line @sentry-internal/sdk/no-class-field-initializers
public method(flagKey, flagDetail, context) {
//TODO:
return;
}
}
7 changes: 5 additions & 2 deletions packages/launchdarkly/src/types/launchdarkly.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// Integration options
// TODO: could we just put everything in a types.ts file?

// Integration interface?
import type { LDClient } from 'launchdarkly-js-client-sdk';

export type LaunchDarklyOptions = {
ldClient: LDClient;
};

0 comments on commit 610da4d

Please sign in to comment.