/jaeger-tracer-node

Node Jaeger client extended with context propagation and external libs patches

Primary LanguageJavaScriptMIT LicenseMIT

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)
})