Socket
Socket
Sign inDemoInstall

@opencensus/core

Package Overview
Dependencies
5
Maintainers
7
Versions
21
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @opencensus/core

OpenCensus is a toolkit for collecting application performance and behavior data.


Version published
Weekly downloads
1.3M
increased by3.42%
Maintainers
7
Install size
690 kB
Created
Weekly downloads
 

Package description

What is @opencensus/core?

The @opencensus/core package is a set of libraries for collecting, processing, and exporting telemetry data (metrics and traces) for analysis to improve the performance and reliability of applications. It is part of the OpenCensus project, which aims to provide a single, high-quality telemetry collection framework across multiple languages.

What are @opencensus/core's main functionalities?

Tracing

This feature allows the collection and export of trace data, which helps in understanding the flow of requests through various services and in identifying bottlenecks and latency issues.

const { Tracing } = require('@opencensus/core');
const tracing = Tracing.instance;

// Configure tracing
tracing.start({samplingRate: 1});

// Create a custom span
const rootSpan = tracing.tracer.startRootSpan({name: 'main'}, rootSpan => {
  // Do work within the span
  rootSpan.end(); // End the span
});

Metrics

This feature enables the collection and aggregation of metrics data, such as counts or latencies, which can be used for monitoring application performance and health.

const { Metrics, MeasureUnit } = require('@opencensus/core');
const metrics = Metrics.instance;

// Create a measure
const requestCountMeasure = metrics.createMeasureInt64('request_count', MeasureUnit.UNIT, 'Count of requests received');

// Create and register a view to aggregate the data
metrics.createView('request_count_view', requestCountMeasure, 'count', [], 'The count of requests', []);

// Record data
metrics.record([{measure: requestCountMeasure, value: 1}]);

Other packages similar to @opencensus/core

Changelog

Source

0.0.9 - 2019-02-12

  • Add Metrics API.
  • Add Resource API.
  • Add Tags API.
  • Add Gauges (DoubleGauge, LongGauge, DerivedDoubleGauge, DerivedLongGauge) APIs.
  • Add support for supplying instrumentation configuration via tracing option. Option argument added to instrumentation interface.
  • Add ignoreIncomingPaths and ignoreOutgoingUrls support to the http and https tracing instrumentations.
  • Add opencensus-resource-util to auto detect AWS, GCE and Kubernetes(K8S) monitored resource, based on the environment where the application is running.
  • Add optional uncompressedSize and compressedSize fields to MessageEvent interface.
  • Add a setStatus method in the Span.
  • OpenCensus Stackdriver Trace Exporter is updated to use Stackdriver Trace V2 APIs.

This release has multiple breaking changes. Please test your code accordingly after upgrading.

  • Modify Logger interface: level made optional, silly removed.
  • The new Stats() has been deprecated on Stats class. The global singleton globalStats object should be used instead. Also, registerView() is separated out from createView().
  • Use TagKey, TagValue and TagMap to create the tag keys, tag values.
  • The status field on Span is no longer a number, use CanonicalCode instead.
  • Add enum type for MessageEvent, Link and SpanKind, instead of string.
Old code
const { Stats } = require("@opencensus/core");
const stats = new Stats();

// Counts/groups the lengths of lines read in.
const mLineLengths = stats.createMeasureInt64(
  "demo/line_lengths",
  MeasureUnit.BYTE,
  "The distribution of line lengths"
);

// Create tag keys
const tagKeys = ["method", "status"];

// Create and register the view
stats.createView(
  "demo/lines_in",
  mLineLengths,
  AggregationType.COUNT,
  tagKeys,
  "The number of lines from standard input"
);

// Records measurements
stats.record({
  measure: mLineLengths,
  tags,
  value: 2
});

New code
// Gets the global stats instance
const { globalStats } = require("@opencensus/core");

// Counts/groups the lengths of lines read in.
const mLineLengths = globalStats.createMeasureInt64(
  "demo/line_lengths",
  MeasureUnit.BYTE,
  "The distribution of line lengths"
);

// Creates the method and status key
const methodKey = {name: "method"};
const statusKey = {name: "status"};

// Creates the view
const view = globalStats.createView(
  "demo/lines_in",
  mLineLengths,
  AggregationType.COUNT,
  [methodKey, statusKey],
  "The number of lines from standard input"
);

// Registers the view
globalStats.registerView(view);

// Creates tags map -> key/value pair
const tagMap = new TagMap();
tagMap.set(methodKey, {value: 'REPL'});
tagMap.set(statusKey, {value: 'OK'});

// Creates measurements (measure + value)
const measurements = [{
  measure: mLineLengths,
  value: 2
}];

// Records measurement with tagMap
globalStats.record(measurements, tagMap);

Readme

Source

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

Get the global Stats manager instance.

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

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

// The latency in milliseconds
const mLatencyMs = globalStats.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 = { name: "method" };
const statusTagKey = { name: "status" };
const errorTagKey = { name: "error" };

// Create & Register the view.
const latencyView = globalStats.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]
);
globalStats.registerView(latencyView);
Recording Metrics:

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

const [_, startNanoseconds] = process.hrtime();
const tags = new TagMap();
tags.set(methodTagKey, { value: "REPL" });
tags.set(statusTagKey, { value: "OK" });

globalStats.record([{
  measure: mLatencyMs,
  value: sinceInMilliseconds(startNanoseconds)
}], tags);

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

Measures can be of type Int64 or DOUBLE, created by calling createMeasureInt64 and createMeasureDouble respectively. Its units can be:

MeasureUnitUsage
UNITfor general counts
BYTEbytes
KBYTEKbytes
SECseconds
MSmillisecond
NSnanosecond

Views can have agregations of type SUM, LAST_VALUE, COUNT and DISTRIBUTION. To know more about Stats core concepts, please visit: https://opencensus.io/core-concepts/metrics/

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

LICENSE

Apache License 2.0

Keywords

FAQs

Last updated on 13 Feb 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc