OpenCensus for Node.js
OpenCensus Node.js is an implementation of OpenCensus, a toolkit for collecting application performance and behavior monitoring data. Right now OpenCensus for Node.js supports custom tracing and automatic tracing for HTTP and HTTPS.
The library is in alpha stage and the API is subject to change.
Please join gitter for help or feedback on this project.
Installation
Install OpenCensus with:
npm install @deal/opencensus-nodejs
Traces
Instrumenting an Application
OpenCensus for Node.js has automatic instrumentation for HTTP and HTTPS out of the box. This means that spans are automatically created for operations of those packages. To use it, simply start the tracing instance.
var tracing = require('@deal/opencensus-nodejs');
tracing.start();
Similarly for Typescript:
import * as tracing from '@deal/opencensus-nodejs';
tracing.start();
Manualy Instrument an Application
In addition to automatic tracing, it is possible to manualy create your own root and child spans.
const rootSpanOptions = { name: 'your root span' };
tracing.tracer.startRootSpan(rootSpanOptions, (rootSpan) => {
// You can create as many child spans as needed
childSpan = tracing.tracer.startChildSpan('name of your child span');
// Do some operation...
// Finish the child span at the end of it's operation
childSpan.end();
// Finish the root span at the end of the operation
rootSpan.end();
});
Tracing Options
Tracing has many options available to choose from. At tracing.start()
, you can set the following:
Options | Type | Description |
---|---|---|
bufferSize |
number |
The number of traces to be collected before exporting to a backend |
bufferTimeout |
number |
Maximum time to wait before exporting to a backend |
logger |
Logger |
A logger object |
logLevel |
number |
Level of logger - 0: disable, 1: error, 2: warn, 3: info, 4: debug |
samplingRate |
number |
Determines the span's sampling rate. Ranges from 0.0 to 1.0 |
ignoreUrls |
Array<string> |
A list of ignored (or blacklisted) URLs to not trace |
propagation |
Propagation |
A propagation instance to use |
maximumLabelValueSize |
number |
The maximum number of characters reported on a label value |
plugin |
PluginNames |
A list of trace instrumentations plugins to load |
exporter |
Exporter |
An exporter object |
Plugins
OpenCensus can collect tracing data automatically using plugins. Users can also create and use their own plugins. Currently, OpenCensus supports automatic tracing for:
Propagation
OpenCensus collects distributed tracing. It is able to do so by propagating span data through services. Currently, OpenCensus supports:
Exporters
OpenCensus can export trace data to various backends. Currently, OpenCensus supports:
If no exporter is registered in the tracing instance, as default, a console log exporter is used.
Useful links
- For more information on OpenCensus, visit: https://opencensus.io/
- To checkout the OpenCensus for Node.js, visit: https://github.com/census-instrumentation/opencensus-node
- For help or feedback on this project, join us on gitter