@dreamit/otel-json-logger

中文文档
3.0.3发布于 2025/07/10MITTypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 2258

JSON diagnose logger for OpenTelemetry

此软件包已被标记为弃用

@dreamit/otel-json-logger is deprecated and will no longer be maintained. Use at your own risk!

原始使用文档
文档目录12 节
  1. Installation
  2. Compatibility
  3. Features
  4. Usage
  5. JsonDiagLogger functions
  6. General functions
  7. DiagLogger interface functions
  8. LogLevel values
  9. Changelog
  10. v3.x
  11. Contact
  12. License

otel-json-logger

JSON diagnose logger for OpenTelemetry

Deprecated: This library will no longer be maintained. Use at your own risk!

Installation

npm install --save @dreamit/otel-json-logger

TypeScript declarations are provided within the project.

Compatibility

otel-json-logger is compatible with @opentelemetry/api version ^1.6.0.

Features

  • Provides JSON Logger for OpenTelemetry DiagLogger interface
  • Stringifies/inspects messages with objects and arrays as well as log arguments to avoid breaking logging tools
  • Creates ISODate timestamp for log entry

Usage

Create a JsonDiagLogger object by providing a fitting loggerName and serviceName. The logger can be used standalone to log JSON to console as well as a global DiagLogger.

import { JsonDiagLogger } from '@dreamit/otel-json-logger'
import { diag, DiagLogLevel } from "@opentelemetry/api";

// Standalone
const logger = new JsonDiagLogger({
    loggerName: 'test-logger', // The loggerName printed in field "logger"
    serviceName: 'test-service', // The serviceName printed in field "serviceName"
    minLogLevel: 'INFO', // Optional: The minimum log level to use. Default: Does not check for min LogLevel.
    logFirstIncomingRequest: true, // Optional: If true, the first incoming request will be logged. Other messages on debug level will be log if minLogLevel is set to debug or higher. Default: false. Note: If you use diag.setLogger ensure that at least "DEBUG" is set, otherwise the message will be ignored.
    logLevelForAsyncAttributeError: 'INFO' // Optional: The log level to use for the message "Accessing resource attributes before async attributes settled". These errors might not be relevant enough to log them on error level.
    logLevelForRegisterGlobalMessages: 'INFO' // Optional: The log level to use for messages "... Registered a global ...". These are helpful to check if OTEL is running properly but are logged on debug level by default. Increase this log level to see these messages.
    logLevelForServiceRequestErrorMessages: 'INFO', // Optional: The log level to use for error message "Service request". These contain request information that might not be logged on error level.
    logLevelForTimeoutErrorMessages: 'INFO', // Optional: The log level to use for Timeout related messages. These might be of short nature and be downgraded or ignored.
    logLevelForVerbose: 'OFF' // Optional: Set LogLevel for verbose entries or ignore them
    truncateLimit: 200 // Optional:  The length of the message before the message gets truncated. Default: undefined/0 (off).
    truncatedText: '_TRC_' // Optional: The text to display if a message is truncated.
})
logger.debug('test', 1, {name: 'myname'})

// Add as global DiagLogger
diag.setLogger(logger, DiagLogLevel.ERROR)

JsonDiagLogger functions

General functions

  • createLogEntry: Creates and returns a log entry of type LogEntry with the provided information.
  • logMessage: Central function being called by all DiagLogger interface functions. Calls createLogEntry, stringifies the result and calls console.log().
  • formatMessage: Formats the message. If the message contains an object or array wrap it in JSON.stringify to avoid these being interpreted as JSON objects.
  • setOptions: Sets the LoggerOptions to be used for logging. Can be called after constructor call to set new/other options.
  • containsTimeout: Check if the message contains a Timeout information like "4 DEADLINE_EXCEEDED" or "14 UNAVAILABLE".
  • isIncomingRequestLogMessage: Checks if the arguments are part of an incomingRequest message, i.e. the first argument contains the text 'incomingRequest'
  • isEqualOrHigherMinLogLevel: Checks if the log level is equal or higher than the minimum log level.
  • containsAsyncAttributeError: Check if the message contains an async attribute error like "Accessing resource attributes before async attributes settled".

DiagLogger interface functions

  • debug: Logs a debug message
  • error: Logs an error message
  • info: Logs an info message
  • verbose: Logs a verbose message
  • warn: Logs a warn message

LogLevel values

  • DEBUG
  • ERROR
  • INFO
  • OFF : Do not log these entries!
  • VERBOSE
  • WARN

Changelog

v3.x

LogLevel has been changed from enum to string type.

Contact

If you have questions or issues please visit our Issue page and open a new issue if there are no fitting issues for your topic yet.

License

otel-json-logger is under MIT-License.

版本与发布记录

@dreamit/otel-json-logger 共发布 21 个版本,首次发布于 2023/09/21;过去 12 个月发布了 0 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
3.0.3latest2025/07/101.3 年前
3.0.22025/06/061.4 年前
3.0.12025/04/161.6 年前
3.0.02025/03/181.7 年前
2.7.32024/12/101.9 年前
2.7.22024/11/152 年前

关于 @dreamit/otel-json-logger 的常见问题

@dreamit/otel-json-logger 是什么?

JSON diagnose logger for OpenTelemetry注意:该包已被作者标记为弃用——@dreamit/otel-json-logger is deprecated and will no longer be maintained. Use at your own risk!

如何安装 @dreamit/otel-json-logger?

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

@dreamit/otel-json-logger 支持 TypeScript 吗?

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

@dreamit/otel-json-logger 支持 ESM 还是 CommonJS?

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

@dreamit/otel-json-logger 可以商用吗?

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

@dreamit/otel-json-logger 的下载量有多少?

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

@dreamit/otel-json-logger 还在维护吗?

最新版本 3.0.3 发布于 2025/07/10(1.3 年前);至今共发布 21 个版本,其中过去 12 个月发布了 0 个;首次发布于 2023/09/21。作者已将其标记为弃用,新项目建议寻找替代方案。