@dynatrace/openfeature-provider-web

中文文档
0.3.0-alpha发布于 2026/08/28Apache-2.0TypeScriptESM + CJS近 30 天下载 4456

The official Dynatrace OpenFeature provider for web.

原始使用文档
文档目录8 节
  1. Installation
  2. Configuration
  3. Usage
  4. Basic setup
  5. Context changes
  6. Periodic polling
  7. Listening for flag changes
  8. License

@dynatrace/openfeature-provider-web

The official Dynatrace OpenFeature provider for web.

Questions, comments or suggestions? Reach out to [email protected].


Installation

npm install @dynatrace/openfeature-provider-web @openfeature/web-sdk
# yarn requires manual installation of peer-dependencies
yarn add @dynatrace/openfeature-provider-web @openfeature/web-sdk @openfeature/core

Configuration

The provider is constructed with the SDK key as the first argument and optional overrides as the second:

new DynatraceProvider(sdkKey, options?);
OptionTypeDefaultDescription
apiOriginstringderived from keyOverride the OFREP API origin. When omitted, derived from the geo segment of the SDK key.
metricsOriginstringderived from keyOverride the metrics origin (scheme, host, optional port; no path). The provider appends /v1/metrics. When omitted, derived from the SDK key geo.
pollIntervalnumber-1 (disabled)How often (ms) the provider polls for updated flags. Set to -1 or omit to rely solely on context-change refetches. The minimum polling interval that can be set is 1000ms.
flushIntervalMsnumber30_000How often accumulated evaluation metrics are flushed. Values between 0 and 999 are clamped to 1000ms. Pass a negative number to disable periodic flushing.
maxCapacitynumber5_000Maximum number of distinct aggregate-map entries before a capacity flush is triggered.

The SDK key (e.g. dt01.web_us_…) is required as the first constructor argument. The region segment determines the OFREP and metrics endpoints; the full key is sent as the Authorization header.


Usage

Basic setup

import { OpenFeature } from '@openfeature/web-sdk';
import { DynatraceProvider } from '@dynatrace/openfeature-provider-web';

const provider = new DynatraceProvider('dt01.web_us_…');

// Set evaluation context before registering the provider so the initial
// bulk evaluation includes targeting information.
await OpenFeature.setContext({ targetingKey: 'user-abc' });

// Wait until the provider has fetched all flags before evaluating.
await OpenFeature.setProviderAndWait(provider);

const client = OpenFeature.getClient();
const showBanner = client.getBooleanValue('show-banner', false);

Context changes

Calling OpenFeature.setContext() after provider registration automatically triggers a new bulk evaluation for the new context. Changed flag keys are surfaced via the PROVIDER_CONFIGURATION_CHANGED event.

// Re-evaluates all flags for the new user context.
await OpenFeature.setContext({ targetingKey: 'user-xyz', plan: 'enterprise' });

Periodic polling

Pass a pollInterval (in milliseconds) to have the provider re-fetch flags on a timer in addition to context-change triggers.

const provider = new DynatraceProvider('dt01.web_us_…', {
  pollInterval: 60_000, // refresh every 60 seconds
});

Listening for flag changes

import { OpenFeature, ProviderEvents } from '@openfeature/web-sdk';

OpenFeature.addHandler(ProviderEvents.ConfigurationChanged, (event) => {
  console.log('Flags changed:', event?.flagsChanged);
  // Re-render components that depend on changed flags.
});

License

Apache-2.0

版本与发布记录

@dynatrace/openfeature-provider-web 共发布 14 个版本,首次发布于 2026/04/16;过去 12 个月发布了 14 个版本。

版本发布日期距今
0.3.0-alphalatest2026/08/282 个月前
0.2.7-alpha2026/07/283 个月前
0.2.6-alpha2026/07/283 个月前
0.2.5-alpha2026/07/153 个月前
0.2.4-alpha2026/06/204 个月前
0.2.2-alpha2026/06/015 个月前

其他发布通道:alpha → 0.1.3-alpha。

关于 @dynatrace/openfeature-provider-web 的常见问题

@dynatrace/openfeature-provider-web 是什么?

The official Dynatrace OpenFeature provider for web.

如何安装 @dynatrace/openfeature-provider-web?

在项目目录运行 npm install @dynatrace/openfeature-provider-web,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@openfeature/web-sdk(^1.4.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@dynatrace/openfeature-provider-web 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@dynatrace/openfeature-provider-web 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@dynatrace/openfeature-provider-web 可以商用吗?

@dynatrace/openfeature-provider-web 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@dynatrace/openfeature-provider-web 的下载量有多少?

根据 npm 官方下载统计,@dynatrace/openfeature-provider-web 在 2026/10/13 – 2026/11/11 这 30 天内被下载 4,456 次,日均约 149 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@dynatrace/openfeature-provider-web 还在维护吗?

最新版本 0.3.0-alpha 发布于 2026/08/28(2 个月前);至今共发布 14 个版本,其中过去 12 个月发布了 14 个;首次发布于 2026/04/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。