Generic Feature Flags Integration

了解如何将自定义功能标志数据附加到 Sentry 错误事件。

功能标志集成允许您通过 API 手动跟踪功能标志评估。这些评估保存在内存中,并在错误发生时发送到 Sentry。 目前,我们仅支持布尔标志评估。 此集成在 Sentry SDK 版本 8.43.0 或更高版本 中可用。

Import names: Sentry.featureFlagsIntegration and type Sentry.FeatureFlagsIntegration

Copied
import * as Sentry from '@sentry/browser';

Sentry.init({
  dsn: 'https://examplePublicKey@o0.ingest.sentry.io/0',
  integrations: [Sentry.featureFlagsIntegration()]
});

const flagsIntegration = Sentry.getClient()?
  .getIntegrationByName<Sentry.FeatureFlagsIntegration>('FeatureFlags');
if (flagsIntegration) {
  flagsIntegration.addFeatureFlag('test-flag', false);
} else {
  // Something went wrong, check your DSN and/or integrations
}
Sentry.captureException(new Error('Something went wrong!'));

访问 Sentry 网站并确认您的错误事件已记录功能标志 "test-flag" 及其值 "false"。