OpenFeature

了解如何将 Sentry 与 OpenFeature 配合使用。

OpenFeature 集成会跟踪由 OpenFeature SDK 生成的功能标志评估。这些评估保存在内存中,并在发生错误时发送到 Sentry 进行审查和分析。目前,我们仅支持布尔标志评估。 此集成在 Sentry SDK 版本 8.43.0 或更高版本 中可用。

Import name: Sentry.openFeatureIntegration and Sentry.OpenFeatureIntegrationHook

在使用此集成之前,您需要在应用程序中安装并插装 OpenFeature SDK。通过阅读 OpenFeature 的 SDK 文档提供程序文档 了解更多。

Copied
import * as Sentry from "@sentry/nextjs";
import { OpenFeature } from "@openfeature/web-sdk";

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

OpenFeature.setProvider(new MyProviderOfChoice());
OpenFeature.addHooks(new Sentry.OpenFeatureIntegrationHook());

const client = OpenFeature.getClient();
const result = client.getBooleanValue("test-flag", false); // evaluate with a default value
Sentry.captureException(new Error("Something went wrong!"));

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