How to use the jaeger-client.Tracer function in jaeger-client

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

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({
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
const request = require('request-promise-native')
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) => {
  if (err) {
github up1 / microservice-workshop / 08-tracing / service1.js View on Github external
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([
    request(Object.assign({ uri: 'http://localhost:3003/site/somkiat' }, requestOptions)),
    request(Object.assign({ uri: 'http://localhost:3003/site/skooldio' }, requestOptions))
github up1 / microservice-workshop / 08-tracing / service2.js View on Github external
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' })
    childSpan.setTag(Opentracing.Tags.PEER_SERVICE, ctx._topic)
github vulcainjs / vulcain-corejs / src / instrumentations / trackers / JaegerInstrumentation.ts View on Github external
static create() {
        let jaegerAddress = DynamicConfiguration.getPropertyValue<string>("jaeger");
        if (jaegerAddress) {
            if (!jaegerAddress.startsWith("http://")) {
                jaegerAddress = "http://" + jaegerAddress;
            }
            if (!/:[0-9]+/.test(jaegerAddress)) {
                jaegerAddress = jaegerAddress + ':9411';
            }

            const sender = new UDPSender();
            const tracer = new jaeger.Tracer(Service.fullServiceName,
                new jaeger.RemoteReporter(sender),
                new jaeger.RateLimitingSampler(1));

            return new JaegerInstrumentation(tracer);
        }
        return null;
    }
github moleculerjs / moleculer-metrics / packages / moleculer-jaeger / src / index.js View on Github external
getTracer(serviceName) {
			if (this.tracers[serviceName])
				return this.tracers[serviceName];

			const sampler = this.getSampler();
			const reporter = this.getReporter();

			const tracer = new Jaeger.Tracer(serviceName, reporter, sampler, this.settings.options);
			this.tracers[serviceName] = tracer;

			return tracer;
		}
	},
github sematext / opentracing-materials / nodejs / index.js View on Github external
const options = {
    tags: {
      'api-token': '<your-token>'
    }
};

const httpOpts = {
    host : 'localhost',
    method: 'GET',
    port : '3000',
    path: '/',
};

var reporter = new jaeger.RemoteReporter(new UDPSender());
var sampler = new jaeger.ConstSampler(1);
var tracer = new jaeger.Tracer(serviceName, reporter, sampler, options);

const span = tracer.startSpan('http-request');

http.request(httpOpts, res => {
    res.setEncoding('utf8');
    res.on('error', err => {
        span.setTag(opentracing.Tags.ERROR, true);
        span.log({'event': 'error', 'error.object': err, 'message': err.message, 'stack': err.stack});
        span.finish();
    });
    res.on('data', chunk => {
        span.log({'event': 'data_received', 'chunk_length': chunk.length});
    });
    res.on('end', () => {
        span.log({'event': 'request_end'});
        span.finish();