OpenCensus Object Exporter
OpenCensus Object Trace Exporter allows the user to collect and
programmatically access traces with OpenCensus Node.js. This module is useful for when you need
to access collected spans programmatically, for example for testing purposes.
Installation
Install OpenCensus Object Trace Exporter with:
npm install @opencensus/nodejs
npm install @opencensus/exporter-object
Usage
For javascript:
const tracing = require('@opencensus/nodejs');
const { ObjectTraceExporter } = require('@opencensus/exporter-object');
const exporter = new ObjectTraceExporter();
Similarly for Typescript:
import * as tracing from '@opencensus/nodejs';
import { ObjectTraceExporter } from '@opencensus/exporter-object';
const exporter = new ObjectTraceExporter();
Now, register the exporter and start tracing.
tracing.start({'exporter': exporter});
or
tracing.registerExporter(exporter).start();
Viewing your traces
exporter.startedSpans.forEach((span: Span)) => {}
exporter.endedSpans.forEach((span: Span)) => {}
exporter.publishedSpans.forEach((span: Span)) => {}
Reset exporter
Empties startedSpans
, endedSpans
and publishedSpans
span stores.
exporter.reset();
Useful links