SHARE
TWEET

Untitled

a guest Sep 16th, 2019 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const tracing = require('@opencensus/nodejs');
  2. const { StackdriverTraceExporter } = require('@opencensus/exporter-stackdriver');
  3.  
  4. const exporter = new StackdriverTraceExporter({projectId: "YOUR-GCP-PROJECT"});
  5.  
  6. const tracer = tracing.registerExporter(exporter).start({ samplingRate: 1 }).tracer();
  7.  
  8. function A () {
  9.   let traceId;
  10.   tracer.startRootSpan({ name: 'A' }, rootSpan => {
  11.     doSomeWorkInA();
  12.  
  13.     traceId = rootSpan.traceId();
  14.     rootSpan.end();
  15.   });
  16.  
  17.   // Pass traceId to another function
  18. }
  19.  
  20. function B () {
  21.   let traceId = 'The trace ID passed from A';
  22.   tracer.startRootSpan({ name: 'B', traceId: traceId }, rootSpan => {
  23.     doSomeWorkInB();
  24.  
  25.     rootSpan.end();
  26.   });
  27.  
  28.   // Keep passing the traceId if needed
  29. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top