npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@dreamit/otel-json-logger

v2.7.2

Published

JSON diagnose logger for OpenTelemetry

Downloads

75

Readme

otel-json-logger

JSON diagnose logger for OpenTelemetry

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: LogLevel.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 monLogLevel is set to debug or higher. Default: false. Note: If you use diag.setLogger ensure that at least "LogLevel.debug" is set, otherwise the message will be ignored.
    logLevelForAsyncAttributeError: LogLevel.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: LogLevel.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: LogLevel.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: LogLevel.info, // Optional: The log level to use for Timeout related messages. These might be of short nature and be downgraded or ignored.
    logLevelForVerbose: LogLevel.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 enum values

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

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.