@eqxjs/nest-opentelemetry

中文文档
3.2.2发布于 2026/03/30ISCTypeScriptCommonJS近 30 天下载 1975

Opentelemetry Service for nestjs

此软件包已被标记为弃用

This package moved to private repository

原始使用文档
文档目录17 节
  1. Features
  2. Installation
  3. Usage
  4. Programmatic Usage
  5. Environment Variables
  6. Exporters
  7. Instrumentation
  8. Resource Detectors
  9. Deployment Attributes (applied to Kafka / Socket.IO spans)
  10. Supported Instrumentations
  11. Message Protocol Span Enrichment
  12. M1 Protocol
  13. M2 Protocol
  14. M3 Protocol
  15. Kafka Span Attributes
  16. Build
  17. License

@eqxjs/nest-opentelemetry

Version: 3.2.1 (stable)

OpenTelemetry auto-instrumentation for NestJS applications. Wraps @opentelemetry/sdk-node with a pre-configured set of instrumentations, exporters, and resource detectors — all driven by environment variables.

Features

  • Zero-code instrumentation — register once and all supported libraries are auto-instrumented
  • Multiple exporters — OTLP (traces, metrics, logs) and Azure Monitor Application Insights
  • Custom Kafka span enrichment — supports KafkaJS, eqxjs-kafkajs, and Confluent Kafka with M1/M2/M3 message protocol parsing
  • Custom Socket.IO span enrichment — captures socket ID, key, and M1 protocol attributes
  • Cloud resource detection — automatic detection for AWS, Azure, GCP, Alibaba, container, and more
  • Graceful shutdown — listens for SIGTERM and beforeExit and flushes telemetry before exit

Installation

npm install @eqxjs/nest-opentelemetry

Usage

Register the SDK before your application loads by passing --require to Node.js:

node --require ./node_modules/@eqxjs/nest-opentelemetry/dist/register.js dist/main.js

Or in your package.json start script:

{
  "scripts": {
    "start": "node --require ./node_modules/@eqxjs/nest-opentelemetry/dist/register.js dist/main.js"
  }
}

Programmatic Usage

You can also import individual helpers from the package:

import {
  getNodeAutoInstrumentations,
  getResourceDetectors,
  InstrumentationConfigMap,
} from '@eqxjs/nest-opentelemetry';

Use getNodeAutoInstrumentations(config?) to build the instrumentation list with your own NodeSDK setup, and getResourceDetectors() to apply the environment-driven resource detector list.

Environment Variables

Exporters

VariableDescription
TRACES_URLOTLP endpoint for traces (default: http://localhost:4318/v1/traces)
METRICS_URLOTLP endpoint for metrics (default: http://localhost:4318/v1/metrics)
LOGGER_URLOTLP endpoint for logs (default: http://localhost:4318/v1/logs)
APPLICATIONINSIGHTS_CONNECTION_STRING_TRACEAzure Monitor connection string for traces (takes priority over TRACES_URL)
APPLICATIONINSIGHTS_CONNECTION_STRING_METRICAzure Monitor connection string for metrics (takes priority over METRICS_URL)
APPLICATIONINSIGHTS_CONNECTION_STRING_LOGAzure Monitor connection string for logs (takes priority over LOGGER_URL)
METRIC_EXPORT_INTERVALMetrics export interval in milliseconds (default: 60000)
METRIC_PROMETHEUS_PORTExpose a Prometheus scrape endpoint on this port (e.g. 8081). Takes effect only when neither APPLICATIONINSIGHTS_CONNECTION_STRING_METRIC nor METRICS_URL is set.

Instrumentation

VariableDescription
OTEL_HTTP_HEADERComma-separated list of HTTP header names to capture as span attributes on both request and response
OTEL_NODE_ENABLED_INSTRUMENTATIONSComma-separated list of instrumentation suffixes to enable. When unset, all instrumentations are enabled. Example: http,grpc,pg

Valid values for OTEL_NODE_ENABLED_INSTRUMENTATIONS:

ValueLibrary
amqplibAMQP (RabbitMQ)
aws-lambdaAWS Lambda
aws-sdkAWS SDK
bunyanBunyan logger
cassandra-driverCassandra
confluent-kafkaConfluent Kafka (node-rdkafka)
confluent-kafka-jsConfluent Kafka (KafkaJS)
connectConnect
cucumberCucumber
dataloaderDataLoader
dnsDNS
eqxjs-ioredisEqxJS IORedis
eqxjs-kafkajsEqxJS KafkaJS
mongodb2MongoDB (legacy v2 driver)
expressExpress
fastifyFastify
fsFile System (fs)
generic-poolGeneric Pool
graphqlGraphQL
grpcgRPC
hapiHapi
httpHTTP / HTTPS
ioredisIORedis
kafkajsKafkaJS
knexKnex
koaKoa
lru-memoizerLRU Memoizer
memcachedMemcached
mongodbMongoDB
mongodb2MongoDB (v2 driver)
mongooseMongoose
mysqlMySQL
mysql2MySQL2
nestjs-coreNestJS core
netNet
pgPostgreSQL
pinoPino logger
redisRedis v2
redis-4Redis v4
restifyRestify
routerRouter
socket.ioSocket.IO
tediousTedious (MSSQL)
winstonWinston logger

Resource Detectors

VariableDescription
OTEL_NODE_RESOURCE_DETECTORSComma-separated list of resource detectors. Defaults to all. Use none to disable all.

Available detector values:

ValueDetects
allEnables every detector below
noneDisables all detectors
containerContainer ID
envOTEL_RESOURCE_ATTRIBUTES environment variable
hostHostname
osOS name and version
processProcess PID, runtime name, and version
serviceinstanceRandom service instance ID
alibabaAlibaba Cloud ECS metadata
awsAWS EC2 / ECS / EKS / Beanstalk / Lambda metadata
azureAzure App Service / Functions / VM metadata
gcpGoogle Cloud Platform metadata

Deployment Attributes (applied to Kafka / Socket.IO spans)

VariableSpan attribute set
CLOUD_ZONEcloud.zone
DEPLOYMENT_ENVdeployment.environment
DEPLOYMENT_NAMESPACEk8s.namespace.name

Supported Instrumentations

LibraryPackage
HTTP / HTTPS@opentelemetry/instrumentation-http
gRPC@opentelemetry/instrumentation-grpc
Express@opentelemetry/instrumentation-express
Fastify@fastify/otel
Koa@opentelemetry/instrumentation-koa
Hapi@opentelemetry/instrumentation-hapi
NestJS core@opentelemetry/instrumentation-nestjs-core
Socket.IO@opentelemetry/instrumentation-socket.io
GraphQL@opentelemetry/instrumentation-graphql
KafkaJSopentelemetry-instrumentation-kafkajs
EqxJS KafkaJSopentelemetry-instrumentation-eqxjs-kafkajs
Confluent Kafka (node-rdkafka)opentelemetry-instrumentation-confluent-kafka
Confluent Kafka (KafkaJS)opentelemetry-instrumentation-confluent-kafka (KafkaJSInstrumentation)
AMQP (RabbitMQ)@opentelemetry/instrumentation-amqplib
MongoDB@opentelemetry/instrumentation-mongodb (enhanced reporting enabled)
MongoDB v2 driveropentelemetry-instrumentation-mongodb2 (enhanced reporting enabled)
Mongoose@opentelemetry/instrumentation-mongoose
PostgreSQL@opentelemetry/instrumentation-pg
MySQL / MySQL2@opentelemetry/instrumentation-mysql, @opentelemetry/instrumentation-mysql2
Redis v2 / v4@opentelemetry/instrumentation-redis, @opentelemetry/instrumentation-redis-4
IORedis@opentelemetry/instrumentation-ioredis, opentelemetry-instrumentation-eqxjs-ioredis
Cassandra@opentelemetry/instrumentation-cassandra-driver
Memcached@opentelemetry/instrumentation-memcached
Knex@opentelemetry/instrumentation-knex
AWS SDK@opentelemetry/instrumentation-aws-sdk
AWS Lambda@opentelemetry/instrumentation-aws-lambda
DNS@opentelemetry/instrumentation-dns
Net@opentelemetry/instrumentation-net
FS@opentelemetry/instrumentation-fs
Pino@opentelemetry/instrumentation-pino
Winston@opentelemetry/instrumentation-winston
Bunyan@opentelemetry/instrumentation-bunyan
DataLoader@opentelemetry/instrumentation-dataloader
Generic Pool@opentelemetry/instrumentation-generic-pool
LRU Memoizer@opentelemetry/instrumentation-lru-memoizer
Connect@opentelemetry/instrumentation-connect
Restify@opentelemetry/instrumentation-restify
Router@opentelemetry/instrumentation-router
Tedious (MSSQL)@opentelemetry/instrumentation-tedious
Cucumber@opentelemetry/instrumentation-cucumber

Message Protocol Span Enrichment

Kafka producer/consumer hooks and Socket.IO hooks parse message payloads and add structured span attributes based on the detected message format.

M1 Protocol

Messages with a protocol field are parsed as M1 and produce the following attributes in addition to all M2 attributes:

AttributeSource field
M1.protocol.versionprotocol.version
M1.protocol.commandprotocol.command
M1.protocol.sub_commandprotocol.subCommand
M1.protocol.invokeprotocol.invoke
M1.protocol.topicprotocol.topic

M2 Protocol

Messages with a header field are parsed as M2:

AttributeSource field
enduser.idheader.identity.user
M2.header.versionheader.version
M2.header.org_serviceheader.orgService
M2.header.fromheader.from
M2.header.channelheader.channel
M2.header.brokerheader.broker
M2.header.agentheader.agent
M2.header.useCaseheader.useCase
M2.header.use_case_stepheader.useCaseStep
M2.header.use_case_ageheader.useCaseAge
M2.header.function_nameheader.functionName
M2.header.sessionheader.session
M2.header.transactionheader.transaction

M3 Protocol

Messages with a service field are parsed as M3:

AttributeSource field
enduser.idservice.identity.user
M3.service.versionservice.version
M3.service.org_serviceservice.orgService
M3.service.fromservice.from
M3.service.channelservice.channel
M3.service.brokerservice.broker
M3.service.agentservice.agent
M3.service.useCaseservice.useCase
M3.service.use_case_stepservice.useCaseStep
M3.service.use_case_ageservice.useCaseAge
M3.service.function_nameservice.functionName
M3.service.sessionservice.session
M3.service.transactionservice.transaction

Kafka Span Attributes

All Kafka spans (producer and consumer) include:

AttributeDescription
kafka.directionproduce or consume
kafka.topicTopic name
kafka.keyMessage key
kafka.partitionMessage partition
kafka.offsetMessage offset
kafka.header.<name>Each message header value

Build

npm run build

Output is emitted to ./dist.

License

ISC

版本与发布记录

@eqxjs/nest-opentelemetry 共发布 59 个版本,首次发布于 2024/04/09;过去 12 个月发布了 14 个版本。

版本发布日期距今
3.2.2latest2026/03/307 个月前
3.2.12026/03/277 个月前
3.2.02026/03/108 个月前
3.1.32026/02/278 个月前
3.1.22026/02/278 个月前
3.1.12026/02/278 个月前

其他发布通道:@eqxjs/nest-opentelemetry → 3.0.2-beta.6,nest-opentelemetry → 3.0.5-beta.2,beta.0 → 3.0.9-beta.0,next → 3.0.9-beta.6。

关于 @eqxjs/nest-opentelemetry 的常见问题

@eqxjs/nest-opentelemetry 是什么?

Opentelemetry Service for nestjs注意:该包已被作者标记为弃用——This package moved to private repository

如何安装 @eqxjs/nest-opentelemetry?

在项目目录运行 npm install @eqxjs/nest-opentelemetry,或使用 pnpm add / yarn add / bun add。

@eqxjs/nest-opentelemetry 支持 TypeScript 吗?

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

@eqxjs/nest-opentelemetry 支持 ESM 还是 CommonJS?

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

@eqxjs/nest-opentelemetry 可以商用吗?

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

@eqxjs/nest-opentelemetry 的下载量有多少?

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

@eqxjs/nest-opentelemetry 还在维护吗?

最新版本 3.2.2 发布于 2026/03/30(7 个月前);至今共发布 59 个版本,其中过去 12 个月发布了 14 个;首次发布于 2024/04/09。作者已将其标记为弃用,新项目建议寻找替代方案。