How to use jaeger-client - 10 common examples

To help you get started, we’ve selected a few jaeger-client examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sourcegraph / javascript-typescript-langserver / src / language-server-stdio.ts View on Github external
const packageJson = require('../package.json')
const program = require('commander')
const { initTracer } = require('jaeger-client')

program
    .version(packageJson.version)
    .option('-s, --strict', 'enables strict mode')
    .option('-t, --trace', 'print all requests and responses')
    .option('-l, --logfile [file]', 'log to this file')
    .option('-j, --enable-jaeger', 'enable OpenTracing through Jaeger')
    .parse(process.argv)

const logger = program.logfile ? new FileLogger(program.logfile) : new StderrLogger()
const tracer = program.enableJaeger
    ? initTracer({ serviceName: 'javascript-typescript-langserver', sampler: { type: 'const', param: 1 } })
    : new Tracer()

const options: TypeScriptServiceOptions & MessageLogOptions & RegisterLanguageHandlerOptions = {
    strict: program.strict,
    logMessages: program.trace,
    logger,
    tracer,
}

const messageEmitter = new MessageEmitter(process.stdin, options)
const messageWriter = new MessageWriter(process.stdout, options)
const remoteClient = new RemoteLanguageClient(messageEmitter, messageWriter)
const service = new TypeScriptService(remoteClient, options)

// Add an exit notification handler to kill the process
messageEmitter.on('message', message => {
github signalfx / tracing-examples / aws-lambda / jaeger-nodejs / index.js View on Github external
type: 'const',
      param: 1,
    },
    reporter: {
      collectorEndpoint: ingestUrl,
    },
  };

  if (accessToken) {
      // SignalFx supports Basic authentication with username "auth" and access token as password
      config.reporter.username = 'auth'
      config.reporter.password = accessToken
  }

  const options = { logger: console };
  const tracer = initTracer(config, options);
  // Register our tracer instance as the global tracer for easy access
  // throughout Lambda function.
  opentracing.initGlobalTracer(tracer);

  return tracer;
}
github moorara / microservices-demo / services / site / util / tracer.js View on Github external
type: 'const',
      param: 1
    },
    reporter: {
      agentHost: config.jaegerAgentHost,
      agentPort: config.jaegerAgentPort,
      logSpans: config.jaegerLogSpans
    }
  }

  const tracerOptions = {
    logger: options.logger, // https://github.com/jaegertracing/jaeger-client-node/blob/master/src/_flow/logger.js
    metrics: options.metrics // https://github.com/jaegertracing/jaeger-client-node/blob/master/src/_flow/metrics.js
  }

  return initTracer(tracerConfig, tracerOptions)
}
github up1 / microservice-workshop / 08-tracing / service1.js View on Github external
'use strict'

const express = require('express')
const request = require('request-promise-native')
const opentracing = require('opentracing')
const jaeger = require('jaeger-client')

// Using UDP
const UDPSender = require('jaeger-client/dist/src/reporters/udp_sender').default

const app = express()
const port = process.env.PORT || 3002

// Tracer
const udpSender = new UDPSender()
const reporter = new jaeger.RemoteReporter(udpSender)
const sampler = new jaeger.RateLimitingSampler(1)
const tracer = new jaeger.Tracer('service 1', reporter, sampler)

app.get('/', (req, res) => {
  const span = tracer.startSpan('http_server')
  span.setTag(opentracing.Tags.HTTP_URL, `${req.protocol}://${req.hostname}${req.originalUrl}`)
  span.setTag(opentracing.Tags.HTTP_METHOD, req.method)
  span.setTag('request_path', req.route.path)
  span.setTag('request_id', req.headers['x-request-id'])

  const requestOptions = {
    headers: { 'trace-span-context': span.context().toString() },
    json: true
  }

  Promise.all([
github RisingStack / opentracing-auto / example / server1.js View on Github external
'use strict'

const jaeger = require('jaeger-client')
const UDPSender = require('jaeger-client/dist/src/reporters/udp_sender').default
// eslint-disable-next-line
const Instrument = require('../src')

const sampler = new jaeger.ConstSampler(true)
const reporter = new jaeger.RemoteReporter(new UDPSender())
const tracer = new jaeger.Tracer('my-server-1', reporter, sampler, {
  tags: {
    gitTag: 'foo'
  }
})
// eslint-disable-next-line
const instrument = new Instrument({
  tracers: [tracer],
  httpTimings: true
})

// eslint-disable-next-line
const http = require('http')
// eslint-disable-next-line
const express = require('express')
// eslint-disable-next-line
github up1 / microservice-workshop / 08-tracing / service2.js View on Github external
'use strict'

const express = require('express')
const opentracing = require('opentracing')
const jaeger = require('jaeger-client')
const request = require('request-promise-native')

// Using UDP
const UDPSender = require('jaeger-client/dist/src/reporters/udp_sender').default

const app = express()
const port = process.env.PORT || 3003

// Tracer
const udpSender = new UDPSender()
const reporter = new jaeger.RemoteReporter(udpSender)
const sampler = new jaeger.RateLimitingSampler(1)
const tracer = new jaeger.Tracer('service 2', reporter, sampler)

app.get('/site/:site', (req, res) => {
  const spanContext = jaeger.SpanContext.fromString(req.headers['trace-span-context'])
  const span = tracer.startSpan('http_server', {
    childOf: spanContext
  })
  span.setTag(opentracing.Tags.HTTP_URL, `${req.protocol}://${req.hostname}${req.originalUrl}`)
  span.setTag(opentracing.Tags.HTTP_METHOD, req.method)
  span.setTag('request_path', req.route.path)
  span.setTag('request_id', req.headers['x-request-id'])

  const requestOptions = {
    headers: { 'trace-span-context': span.context().toString() },
    json: true
github hemerajs / hemera / packages / hemera-opentracing / index.js View on Github external
function hemeraOpentracing(hemera, opts, done) {
  if (!opts.serviceName) {
    return done(new Error('serviceName is required'))
  }

  const sampler = new Jaeger.RateLimitingSampler(opts.jaeger.maxTracesPerSecond)
  const reporter = new Jaeger.RemoteReporter(new UDPSender())
  const tracer = new Jaeger.Tracer(opts.serviceName, reporter, sampler, opts)

  hemera.on('serverPreRequest', function(ctx) {
    const span = tracer.startSpan('serverRequest')
    span.log({ event: 'serverPreRequest' })
    span.setTag(Opentracing.Tags.PEER_SERVICE, ctx._topic)
    // span.setTag(Opentracing.Tags.SPAN_KIND_RPC_SERVER)
    // span.setTag(Opentracing.Tags.SPAN_KIND_MESSAGING_CONSUMER)
    ctx._jaegerServerTrace = span
  })

  hemera.on('serverPreResponse', function(ctx) {
    const childSpan = tracer.startSpan('serverRequest', {
      childOf: ctx._jaegerServerTrace
    })
    childSpan.log({ event: 'serverPreResponse' })
github RisingStack / opentracing-auto / example / server-pg.js View on Github external
'use strict'

const jaeger = require('jaeger-client')
const UDPSender = require('jaeger-client/dist/src/reporters/udp_sender').default
// eslint-disable-next-line
const Instrument = require('../src')

const sampler = new jaeger.ConstSampler(true)
const reporter = new jaeger.RemoteReporter(new UDPSender())
const tracer = new jaeger.Tracer('my-server-pg', reporter, sampler, {
  tags: {
    gitTag: 'foobar'
  }
})
// eslint-disable-next-line
const instrument = new Instrument({ tracers: [tracer] })

const knex = require('knex')
const express = require('express')

// postgres config
const pgUser = process.env.PG_USER || process.env.USER || 'root'
const pgPw = process.env.PG_PASSWORD || ''
const pgDB = process.env.PG_DATABASE || 'postgres'
github RisingStack / opentracing-auto / example / server2.js View on Github external
'use strict'

const jaeger = require('jaeger-client')
const UDPSender = require('jaeger-client/dist/src/reporters/udp_sender').default
// eslint-disable-next-line
const Instrument = require('../src')

const sampler = new jaeger.ConstSampler(true)
const reporter = new jaeger.RemoteReporter(new UDPSender())
const tracer = new jaeger.Tracer('my-server-2', reporter, sampler, {
  tags: {
    gitTag: 'bar'
  }
})
// eslint-disable-next-line
const instrument = new Instrument({
  tracers: [tracer],
  httpTimings: true
})

const express = require('express')
const request = require('request-promise-native')
const monk = require('monk')

const db = monk('localhost/mydb', (err) => {
github RisingStack / opentracing-auto / example / server-pg.js View on Github external
'use strict'

const jaeger = require('jaeger-client')
const UDPSender = require('jaeger-client/dist/src/reporters/udp_sender').default
// eslint-disable-next-line
const Instrument = require('../src')

const sampler = new jaeger.ConstSampler(true)
const reporter = new jaeger.RemoteReporter(new UDPSender())
const tracer = new jaeger.Tracer('my-server-pg', reporter, sampler, {
  tags: {
    gitTag: 'foobar'
  }
})
// eslint-disable-next-line
const instrument = new Instrument({ tracers: [tracer] })

const knex = require('knex')
const express = require('express')

// postgres config
const pgUser = process.env.PG_USER || process.env.USER || 'root'
const pgPw = process.env.PG_PASSWORD || ''
const pgDB = process.env.PG_DATABASE || 'postgres'

const pg = knex({