@gamechanger/datadog-apm

中文文档
1.4.2发布于 2025/04/18MITTypeScriptCommonJS近 30 天下载 4603

Utility functions to help integrate Datadog's APM with a Node.js client

此软件包已被标记为弃用

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

原始使用文档
文档目录7 节
  1. Motivation
  2. Install
  3. Decorators
  4. Tags
  5. Root Span Access
  6. Marking Spans as Errors
  7. Deploying

Datadog APM Helpers

A lightweight wrapper over Datadog's dd-trace library, adding utility functions to make it easier to trace, tag, and search for your functions.

Motivation

dd-trace offers power and flexibility, but with that comes complexity. This wrapper adds helpers to simplify with:

  • Tracing functions (including async)
  • Tracing class methods
  • Adding tags to the active span
  • Adding tags to the root span (Required to enable filtering and searching in Trace Search and Analytics)
  • Marking a span as an error without throwing

Install

npm install --save @gamechanger/datadog-apm

or

yarn add @gamechanger/datadog-apm

Decorators

Your observability code should stay out of the way of your business logic, and should be easy to add and remove. Decorators are a great way to accomplish that.

// Trace a function
@APM.trace()
async function foo() {}

// Trace *all* methods of a class
@APM.trace()
class GameChanger {
    public foo() {}
    private bar() {}
}

// Trace *individual* methods of a class
class GameChanger {
    @APM.trace()
    public foo() {}
    private bar() {}
}

// The decorator can be configured to override the defaults
class EmailQueue {
    @APM.trace({ serviceName: 'queue', spanName: 'queue.message' })
    public async pop() {}
}

Tags

Adding tags happens throughout the code, and so ideally adds as few lines as possible.

With vanilla dd-trace, you must always check if the active span exists:

const span = tracer.scope().active();

if (span !== null) {
    span.addTags({
        'http.method': req.method
    });
}

This wrapper helps clean things up for you:

APM.addTags({ 'http.method': req.method })

Root Span Access

If you're using koa or express, you can use APM.getRootSpanFromContext to get the root span. This can be used to add tags to the root span, which are then accessible in the Trace Search & Analytics screens in datadog.

APM.addTags({ teamId: context.params.teamId }, APM.getRootSpanFromContext(context));

NOTE: This uses undocumented properties and is not guaranteed to work. However, if the underlying dd-trace code were to change, it will safely fall back to adding the tags to the current span rather than the root span.

Marking Spans as Errors

APM.markAsError(new Error('I am not thrown'))

Deploying

All publishing is done through the CI pipeline.

To trigger a new deploy, simply update the version number using npm version <version> and then push the package.json change and related tag to the repo with git push --follow-tags.

版本与发布记录

@gamechanger/datadog-apm 共发布 27 个版本,首次发布于 2019/12/04;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.4.2latest2025/04/181.6 年前
1.4.12024/03/152 年前
1.4.02024/03/142 年前
1.5.1-beta2024/01/252 年前
1.4.7-beta2023/08/243 年前
1.4.5-beta2023/08/243 年前

关于 @gamechanger/datadog-apm 的常见问题

@gamechanger/datadog-apm 是什么?

Utility functions to help integrate Datadog's APM with a Node.js client注意:该包已被作者标记为弃用——Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

如何安装 @gamechanger/datadog-apm?

在项目目录运行 npm install @gamechanger/datadog-apm,或使用 pnpm add / yarn add / bun add。

@gamechanger/datadog-apm 支持 TypeScript 吗?

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

@gamechanger/datadog-apm 支持 ESM 还是 CommonJS?

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

@gamechanger/datadog-apm 可以商用吗?

@gamechanger/datadog-apm 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@gamechanger/datadog-apm 的下载量有多少?

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

@gamechanger/datadog-apm 还在维护吗?

最新版本 1.4.2 发布于 2025/04/18(1.6 年前);至今共发布 27 个版本,其中过去 12 个月发布了 0 个;首次发布于 2019/12/04。作者已将其标记为弃用,新项目建议寻找替代方案。