Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement