OpenCensus Zpages Exporter for Node.js
OpenCensus Zpages Exporter implements a collection of HTML pages that display stats and trace data sent from OpenCensus Node.js.
This project is still at an early stage of development. It's subject to change.
Installation
npm install @opencensus/nodejs
npm install @opencensus/exporter-zpages
Usage
Zpages always runs on localhost, but you can change the port in the options. If the option startServer
is set to true
, Zpages server will start when a new Zpages instance is created. It's also possible to predefined some span names. These empty spans will be listed on Zpages.
To use Zpages, instance the exporter on your application and pass the options. For javascript:
var tracing = require('@opencensus/nodejs');
var zpages = require('@opencensus/exporter-zipkin');
var options = {
port: 8080,
startServer: true,
spanNames: ['predefined/span1', 'predefined/span2']
}
var exporter = new zpages.ZpagesExporter(options);
Similarly for Typescript:
import * as tracing from '@opencensus/nodejs';
import {ZpagesExporter, ZpagesExporterOptions} from '@opencensus/zpages-exporter';
const options = {
port: 8080,
startServer: true,
spanNames: ['predefined/span1', 'predefined/span2']
} as ZpagesExporterOptions;
const exporter = new ZpagesExporter(options);
Now, register the exporter and start tracing.
tracing.start({'exporter': exporter});
or
tracing.registerExporter(exporter).start();
Starting the Zpages server
If options.startServer
is set to false
, the server can be started by calling startServer
method:
zpages.startServer();
The server will run at http:\\localhost:port
.
Browsing the Zpages pages
There are four pages you can browse.
-
/tracez: Trace list.
-
/traceconfigz: Trace settings.
-
/rpcz: RPC stats (not yet implemented).
-
/stats: Stats page (not yet implemented).
Stoping the Zpages server
If it is necessary to stop the server programmatically, use the following command:
zpages.stopServer();
Useful links
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);