OpenCensus Stackdriver Exporter for Node.js
OpenCensus Stackdriver Exporter allows the user to send collected traces with OpenCensus Node.js and stats with OpenCensus Core to Stackdriver Cloud Tracing and Stackdriver Monitoring.
The library is in alpha stage and the API is subject to change.
OpenCensus Stackdriver Trace Exporter
Installation
Install OpenCensus Stackdriver Exporter with:
npm install @opencensus/nodejs
npm install @opencensus/exporter-stackdriver
Usage
To use Stackdriver as your exporter, make sure you have enabled Stackdriver Tracing on Google Cloud Platform. Enable your Application Default Credentials for authentication with:
export GOOGLE_APPLICATION_CREDENTIALS=path/to/your/credential.json
Create and register the exporter on your application and pass your Project ID.
For Javascript:
const tracing = require('@opencensus/nodejs');
const { StackdriverTraceExporter } = require('@opencensus/exporter-stackdriver');
const exporter = new StackdriverTraceExporter({projectId: "your-project-id"});
tracing.registerExporter(exporter).start();
Similarly for TypeScript:
import * as tracing from '@opencensus/nodejs';
import { StackdriverTraceExporter } from '@opencensus/exporter-stackdriver';
const exporter = new StackdriverTraceExporter({projectId: "your-project-id"});
Now, register the exporter and start tracing.
tracing.start({'exporter': exporter});
or
tracing.registerExporter(exporter).start();
Viewing your traces:
With the above you should now be able to navigate to the Stackdriver UI at: https://console.cloud.google.com/traces/traces
OpenCensus Stackdriver Stats(Metrics) Exporter
Installation
Install OpenCensus Stackdriver Exporter with:
npm install @opencensus/core
npm install @opencensus/exporter-stackdriver
Usage
To use Stackdriver as your exporter, make sure you have enabled Stackdriver Monitoring on Google Cloud Platform. Enable your Application Default Credentials for authentication with:
export GOOGLE_APPLICATION_CREDENTIALS=path/to/your/credential.json
Create and register the exporter on your application.
For Javascript:
const { globalStats } = require('@opencensus/core');
const { StackdriverStatsExporter } = require('@opencensus/exporter-stackdriver');
const exporter = new StackdriverStatsExporter({ projectId: "your-project-id" });
globalStats.registerExporter(exporter);
Similarly for TypeScript:
import { globalStats } from '@opencensus/core';
import { StackdriverStatsExporter } from '@opencensus/exporter-stackdriver';
const exporter = new StackdriverStatsExporter({ projectId: "your-project-id" });
globalStats.registerExporter(exporter);
Viewing your metrics:
With the above you should now be able to navigate to the Stackdriver UI at: https://console.cloud.google.com/monitoring
Useful links
0.0.12 - 2019-05-13
- Add
defaultAttributes
config to Tracer.start(config)
- http-instrumentation: Handle incoming requests with long request url path.
- Add Cumulative (
DoubleCumulative
, LongCumulative
, , DerivedDoubleCumulative
, DerivedLongCumulative
) APIs. - Export
TracerBase
as a separate @opencensus/nodejs-base
package. - Fix(deps): update dependency nyc to v14.
- Fix(deps): update dependency grpc to ~1.20.0
- chore(package): update handlebar to avoid security vulnabirity.
- Move propagation-binaryformat package to dependencies.
- Fix(deps): update dependency @grpc/proto-loader to ^0.5.0
- http-instrumentation: fix propagation errors when using Expect header.
- Consolidate Span and RootSpan to allow Spans to recursively have children.
This release has a breaking change. Please test your code accordingly after upgrading.
- removing Tracer's
startChildSpan(name?: string, kind?: types.SpanKind)
interface
Old code
// Multi argument interface
const span = tracer.startChildSpan('my-span', types.SpanKind.SERVER);
// Or options object interface
const span = tracer.startChildSpan({
name: 'my-span',
kind: types.SpanKind.SERVER
});
New code
// Only options object interface is supported
const span = tracer.startChildSpan({
name: 'my-span',
kind: types.SpanKind.SERVER
});