Stackdriver (Tracing)
Introduction
Stackdriver Trace is a distributed tracing system that collects latency data from your applications and displays it in the Google Cloud Platform Console.
You can track how requests propagate through your application and receive detailed near real-time performance insights. Stackdriver Trace automatically analyzes all of your application’s traces to generate in-depth latency reports to surface performance degradations, and can capture traces from all of your VMs, containers, or Google App Engine projects.
OpenCensus Node.js has support for this exporter available, distributed through NPM package @opencensus/exporter-stackdriver
For assistance setting up Stackdriver, Click here for a guided codelab.
Installing the exporter
Install OpenCensus Stackdriver Exporter with:
npm install @opencensus/nodejs
npm install @opencensus/exporter-stackdriver
Creating the exporter
To create the exporter, you’ll need to:
- Have a GCP Project ID
- Have already enabled Stackdriver Tracing, if not, please visit the Code lab
- Enable your Application Default Credentials for authentication with:
export GOOGLE_APPLICATION_CREDENTIALS=path/to/your/credential.json
To create the exporter, in code:
const tracing = require('@opencensus/nodejs');
const { StackdriverTraceExporter } = require('@opencensus/exporter-stackdriver');
// Add your project id to the Stackdriver options
const exporter = new StackdriverTraceExporter({projectId: "your-project-id"});
tracing.registerExporter(exporter).start();
Viewing your traces
Please visit https://console.cloud.google.com/traces/traces
References
Resource | URL |
---|---|
NPM: @opencensus/exporter-stackdriver | https://www.npmjs.com/package/@opencensus/exporter-stackdriver |
NPM: @opencensus/nodejs | https://www.npmjs.com/package/@opencensus/nodejs |
Github: OpenCensus for Node.js | https://github.com/census-instrumentation/opencensus-node/tree/master/packages/opencensus-nodejs |