Skip to content

Node Jaeger client extended with context propagation and external libs patches

License

Notifications You must be signed in to change notification settings

weidian-lab/jaeger-tracer-node

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Jaeger Tracer for NodeJS

js-standard-style

Basic Usage

This module automaticaly does most of the work by patching external libraries, such as http, ioredis, mongodb, and sequelize. The only thing that has to be done import this module before all others and configure the tracer.

const jaeger = require('jaeger-tracer-node')

// Other imports

jaeger.configure({
  disable: false,
  probability: 0.001,
  serviceName: 'my-service',
  tags: {
    'my-tag': 'my-value'
  }
})

// Main loop

Advanced Usage

In case there is need for manually creating spans, two approaches exist for referencing the parent.

Notice that the spans need to be propagated in order for the patched libraries to know which is the current span. Also, if your custom code sends requests to other servers, the span can be injected into a carrier for transmission.

Using a span carrier

This carrier can be something similar to an HTTP header or null.

let span = jaeger.startSpan(carrier, 'my-span', {
  'my-tag': 'my-value'
})

span.propagate(() => {
  mySynchronousFunction(request)
})
span.finish()

Using the current span

The current span will never be null, so no check is needed. However, if it is not set, the new span will lack a parent.

let parent = jaeger.currentSpan()
let span = parent.startSpan('my-span')

span.inject(myCarrier)

myFunctionWithCallback(myCarrier, err => {
  span.finish(err)
})

About

Node Jaeger client extended with context propagation and external libs patches

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%