@elastic/opamp-client-node

中文文档
0.5.1发布于 2026/10/08Apache-2.0TypeScriptCommonJS构建来源已验证近 30 天下载 13.8万

一个用于节点.js的 OpAMP 客户端

中文使用文档
文档目录7 节
  1. 使用量
  2. 使用远程配置
  3. 使用 Agent 的 OpenTeleometry 资源Description
  4. 参考文献
  5. 新闻
  6. 可分割
  7. 限制

@ 弹性/ opamp- 客户端- 节点

一个用于Node.js的开放代理管理协议(OpAMP)客户端.

使用量

这个OpAMP客户端的最小用途就是这样:

import {createOpAMPClient} from '@elastic/opamp-client-node';

const client = createOpAMPClient({endpoint: 'http://localhost:4320/v1/opamp'});
client.setAgentDescription({
    identifyingAttributes: { 'service.name': 'minimal-example' },
});
client.start();

process.on('beforeExit', async () => {
    await client.shutdown();
});

// ...

使用远程配置

以下是如何使用可选的 OpAMP 客户端 OpAMP 代理配置支持数字 :

import {
    createOpAMPClient,
    AgentCapabilities,
    RemoteConfigStatuses
} from '@elastic/opamp-client-node';

const client = createOpAMPClient({
    endpoint: 'http://localhost:4320/v1/opamp',
    capabilities:
        AgentCapabilities.AgentCapabilities_AcceptsRemoteConfig |
        AgentCapabilities.AgentCapabilities_ReportsRemoteConfig,
    onMessage: ({remoteConfig}) => {
        if (remoteConfig) {
            console.log('Got remote config:', remoteConfig);

            // Apply the remote config.
            // ...

            // Report the remote config status.
            client.setRemoteConfigStatus({
                status: RemoteConfigStatuses.RemoteConfigStatuses_APPLIED,
                lastRemoteConfigHash: remoteConfig.configHash,
            });
        }
    },
});
client.setAgentDescription({
    identifyingAttributes: { 'service.name': 'minimal-example' },
});
client.start();

process.on('beforeExit', async () => {
    await client.shutdown();
});

// ...

使用 Agent 的 OpenTeleometry 资源Description

OpAMP 客户端需要 AgentDescription 运行。 此描述中包含哪些数据由用户决定, 但 OpAMP spec对什么语义公约有一些建议 资源属性 包括"SHOULD".

这里有一些代码,从一个 打开远程 JavaScript Resource数字 :

/**
 * Copy properties from `fromObj` to `toObj` that match the given name
 * patterns (`namePats`). This is a shallow copy.
 *
 * `namePats` supports an extremely limited subset of glob matching: if a
 * pattern ends with an asterisk (`*`), then the rest of string is compared
 * with `.startsWith()`. For example `cloud.*` matches a 'cloud.foo' property
 * of `fromObj`. Otherwise the pattern uses an exact match.
 */
function pickProps(toObj, fromObj, namePats) {
    const fromKeys = Object.keys(fromObj)
    for (let namePat of namePats) {
        if (namePat.endsWith('*')) {
            const prefix = namePat.slice(0, -1);
            for (let k of fromKeys) {
                if (k.startsWith(prefix)) {
                    toObj[k] = fromObj[k];
                }
            }
        } else {
            if (namePat in fromObj) {
                toObj[namePat] = fromObj[namePat];
            }
        }
    }
    return toObj;
};

const resource = ...;
const client = createOpAMPClient(...);

await resource?.waitForAsyncAttributes();
client.setAgentDescription({
    identifyingAttributes: pickProps({}, resource.attributes, [
        'service.name', 'service.namespace', 'service.version',
        'service.instance.id',
    ]
    nonIdentifyingAttributes: pickProps({}, resource.attributes, [
        'os.type', 'os.version',
        'host.*',
        'cloud.*',
    ]
});

// ...

参考文献

TODO: 大部分参考文件

新闻

注:如果 ReportsRemoteConfig 建立了能力,由用户决定 调用 client.setRemoteConfigStatus(...) 视情况而定. (TODO:这方面的例子)

TODO: 关于使用远程配置的更多细节 - 在Message不应该扔 - 应使用dupe数据处理多个呼叫:例如使用远程Config.configHash 减少工作。 应该处理 序列节点 配置Hash 检查应当同步 . - 提到如何设置状态 APLIED和失败 如果惊讶于配置 - 这需要建立报告检索能力 - 也许JSON配置有用.

可分割

TODO: doc this, 标记为实验性未承诺的 msg 结构

限制

  • 只支持HTTP运输(没有WebSocket运输).
  • 仅支持 spec 的子集: 没有Beta 或 Development 特性 除非另有说明。 TODO: 请具体说明

版本与发布记录

@elastic/opamp-client-node 共发布 6 个版本,首次发布于 2025/06/06;过去 12 个月发布了 2 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.5.1latest2026/10/081 个月前
0.5.02026/06/174 个月前
0.4.02025/11/111 年前
0.3.02025/11/061 年前
0.2.02025/06/121.4 年前
0.1.02025/06/061.4 年前

关于 @elastic/opamp-client-node 的常见问题

@elastic/opamp-client-node 是什么?

一个用于节点.js的 OpAMP 客户端

如何安装 @elastic/opamp-client-node?

在项目目录运行 npm install @elastic/opamp-client-node,或使用 pnpm add / yarn add / bun add。

@elastic/opamp-client-node 支持 TypeScript 吗?

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

@elastic/opamp-client-node 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@elastic/opamp-client-node 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js ^18.19.0 || >=20.6.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@elastic/opamp-client-node 可以商用吗?

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

@elastic/opamp-client-node 的下载量有多少?

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

@elastic/opamp-client-node 还在维护吗?

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