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

@apartmentlist/js-trace-logger

v0.6.0

Published

Logger outputs messages with Trace ID

Downloads

161

Readme

js-trace-logger

js-trace-logger decorates messages with DataDog Trace/Span ID and writes it to console.log(). So you can connect APM and Log!

Getting Started

Install js-trace-logger using npm:

npm install --save @apartmentlist/js-trace-logger

Let's configure it:

import { tracer } from 'dd-trace';
import { Logger } from '@apartmentlist/js-trace-logger';

const env     = process.env.DD_ENV     || 'development';
const service = process.env.DD_SERVICE || 'my_app';
const version = process.env.DD_VERSION || 'dev';
if (process.env.DD_API_KEY) {
  tracer.init({ env, service, version });
}
Logger.configure({ env, service, version });

// this is optional: If you don't need the decoration in
// non-production environments.
if (env !== 'production') {
  Logger.passThru = true;
}

Logger.warn('hello!');
// => [2019-01-16 18:38:41 +0000][my_app][WARN][dd.env=development dd.service=my_app dd.version=dev dd.trace_id=8545847825299552251 dd.span_id=3711755234730770098] hello!

The default log decoration is set to Datadog's recommendation as For logging in Ruby applications. See More on how to configure other style.

Usage

Logger.info('foobar');
  // => […][INFO][…] foobar

// Method footprint is `console.log()` compatible.
Logger.debug('hello', 'world', 111);
  // => […][DEBUG][…] Hello world 111

// You can set a log level to filter messages
Logger.level = 'warn';
Logger.info('not showing');
Logger.warn('showing');
  // => […][WARN][…] showing

// Object and array will be JSON.stringify()-ed
const obj = {a: 1, b: true};
Logger.warn(obj);
  // => […][WARN][…] {"a":1,"b":true}

// Error instance will be converted to a special construct
const err = new SyntaxError('something');
Logger.error(err);
  // => […][ERROR][…] {"error":{"class":"SyntaxError","message":"something","stacktrace":[…]}

More

If you wanna do something different:

const loggerOption = {
  env: 'production',
  service: 'my-service',
  version: '0001',
  progname: 'my-app',
  logTemplate: '{"datetime": "${datetime}", "progname": "${progname}", "serverity": "${severity}", "dd": ${trace}, "message": ${msg}}',
  traceTemplate: '{"env": "${env}", "service": "${service}", "version": "${version}", "trace_id": ${trace_id}, "span_id": ${span_id}}',
  dateFunc: (d) => {
    return d.toISOString();
  }
};
Logger.configure(loggerOption);
Logger.info(JSON.stringify("hello world"));
  // => {"datetime": "1970-01-01T00:00:00.000Z", "progname": "my-app", "serverity": "INFO", "dd": {"env": "production", "service": "my-service", "version": "0001", "trace_id": "1", "span_id": "1"}, "message": "hello world"}