@opencensus/core (0.0.8)

Published 2026-02-24 13:49:55 +00:00 by atheaadmin

Installation

@opencensus:registry=
npm install @opencensus/core@0.0.8
"@opencensus/core": "0.0.8"

About this package

OpenCensus Core Node.js

Gitter chat Node Version NPM Published Version dependencies Status devDependencies Status Apache License

OpenCensus for Node.js is an implementation of OpenCensus, a toolkit for collecting application performance and behavior monitoring data. It currently includes 3 apis: stats, tracing and tags.

The library is in alpha stage and the API is subject to change.

Installation

Install the opencensus-core package with NPM:

npm install @opencensus/core

Usage

Set up a new Stats manager instance.

To enable metrics, we’ll import a few items from OpenCensus Core package.

const { Stats, MeasureUnit, AggregationType } = require('@opencensus/core');

// Create the Stats manager
const stats = new Stats();

// The latency in milliseconds
const mLatencyMs = stats.createMeasureDouble(
  "repl/latency",
  MeasureUnit.MS,
  "The latency in milliseconds"
);

Create Views and Tags:

We now determine how our metrics will be organized by creating Views. We will also create the variable needed to add extra text meta-data to our metrics – methodTagKey, statusTagKey, and errorTagKey.

const methodTagKey = "method";
const statusTagKey = "status";
const errorTagKey = "error";

const latencyView = stats.createView(
  "demo/latency",
  mLatencyMs,
  AggregationType.DISTRIBUTION,
  [methodTagKey, statusTagKey, errorTagKey],
  "The distribution of the latencies",
  // Bucket Boundaries:
  // [>=0ms, >=25ms, >=50ms, >=75ms, >=100ms, >=200ms, >=400ms, >=600ms, >=800ms, >=1s, >=2s, >=4s, >=6s]
  [0, 25, 50, 75, 100, 200, 400, 600, 800, 1000, 2000, 4000, 6000]
);

Recording Metrics:

Now we will record the desired metrics. To do so, we will use stats.record() and pass in measurements.

const [_, startNanoseconds] = process.hrtime();
const tags = {method: "repl", status: "OK"};

stats.record({
  measure: mLatencyMs,
  tags,
  value: sinceInMilliseconds(startNanoseconds)
});


function sinceInMilliseconds(startNanoseconds) {
  const [_, endNanoseconds] = process.hrtime();
  return (endNanoseconds - startNanoseconds) / 1e6;
}

See Quickstart/Metrics for a full example of registering and collecting metrics.

LICENSE

Apache License 2.0

Dependencies

Dependencies

ID Version
continuation-local-storage ^3.2.1
log-driver ^1.2.7
semver ^5.5.0
shimmer ^1.2.0
uuid ^3.2.1

Development Dependencies

ID Version
@types/continuation-local-storage ^3.2.1
@types/mocha ^5.2.5
@types/node ^10.12.12
@types/once ^1.4.0
@types/semver ^5.5.0
@types/shimmer ^1.0.1
@types/uuid ^3.4.3
gts ^0.9.0
intercept-stdout ^0.1.2
mocha ^5.0.4
ncp ^2.0.0
nyc 11.6.0
ts-node ^7.0.1
typescript ~2.6.1

Keywords

opencensus nodejs tracing profiling
Details
npm
2026-02-24 13:49:55 +00:00
0
Google Inc.
Apache-2.0
39 KiB
Assets (1)
Versions (2) View all
0.0.8 2026-02-24
0.0.9 2026-02-24