0.0.3 • Published 9 months ago

@cran/lib.node.telemetry v0.0.3

Weekly downloads
-
License
MIT
Repository
-
Last release
9 months ago

Telemetry Baseline

CC BY-SA 4.0   NPM

Installation

npm install @cran/lib.node.telemetry

Basic Usage

Important: To properly utilize and configure instrumentation, this library must be imported and configured before all others, however it may be started at any time

NOTE: Do not combine auto and classic import methodologies from below, they are not compatible and will result in two reporters

import "@cran/lib.node.telemetry/auto";

-- or --

node --require @cran/lib.node.telemetry/auto [file.js]

Note: To see default tracing utilize the DEBUG environment variable

DEBUG=cran:telemetry:*,-cran:telemetry:fs

Advanced Usage

import { MetricTracer } from "@cran/lib.node.telemetry";

MetricTracer.init({
  prefix: "my_app_",
  trace ( span ) {
    // default utilizes debug
    console.log(span);
  },
  relabel: {
    "@opentelemetry/instrumentation-fs" ( ) {
      // turn off metric reporting
      return null;
    },
    "@opentelemetry/instrumentation-http" ( span ) {
      // alter labels (span.attributes is defaulted)
      return { ...span.attributes, my_label: "my_value" };
    },
  },
  instrumentations: [
    require("instrumentation-custom")(),
  ],
  override: {
    // SEE https://www.npmjs.com/package/@opentelemetry/auto-instrumentations-node?activeTab=readme
    "@opentelemetry/instrumentation-http": {
      applyCustomAttributesOnSpan ( span ) {
        span.setAttribute("foo", "bar");
      },
    },
  },
})

Tip

It may help to put telemetry code in its own location and import it directly at the top of your main or index file.

import "./telemetry";

// other code