Node
Packages to import
npm install @opencensus/nodejs
npm install @opencensus/exporter-zpages
Source code example
const tracing = require('@opencensus/nodejs');
const zpages = require('@opencensus/exporter-zpages');
const options = {
port: 8080, // default
startServer: true, // default
spanNames: ['predefined/span1', 'predefined/span2']
};
const exporter = new zpages.ZpagesExporter(options);
const tracer = tracing.registerExporter(exporter).start().tracer;
const tracing = require('@opencensus/nodejs');
const zpages = require('@opencensus/exporter-zpages');
const stdin = process.openStdin();
const options = {
port: 8080, // default
startServer: true, // default
spanNames: ['predefined/span1', 'predefined/span2']
};
const defaultConfig = {
name: 'readEvaulateProcessLine',
samplingRate: 1.0 // always sample
};
function delay() {
for (let i = 0; i < 1000000; i++) {}
}
const exporter = new zpages.ZpagesExporter(options);
const tracer = tracing.registerExporter(exporter).start().tracer;
function readEvaluateProcessLine(input) {
tracer.startRootSpan(defaultConfig, rootSpan => {
const text = readLine(input);
const upperCase = processLine(text);
process.stdout.write('< ' + upperCase + '\n> ');
rootSpan.end();
});
}
function readLine(input) {
const span = tracer.startChildSpan('readLine');
span.start();
const text = input.toString().trim();
span.addAttribute('length', text.length);
span.addAttribute('text', text);
delay();
span.end();
return text;
}
function processLine(text) {
const span = tracer.startChildSpan('processLine');
span.start();
const upperCaseText = text.toUpperCase();
delay();
span.end();
return upperCaseText;
}
/*
* In a REPL:
* 1. Read input
* 2. process input
*/
stdin.addListener("data", readEvaluateProcessLine);
process.stdout.write('> ');
Tracez
On visiting http://localhost:8080/tracez
TraceConfigz
On visiting http://localhost:8080/traceconfigz
References
Resource | URL |
---|---|
zPages NodeDoc | https://github.com/census-instrumentation/opencensus-node/tree/master/packages/opencensus-exporter-zpages |