How to use the jaeger-client.initTracer 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.

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 DefinitelyTyped / DefinitelyTyped / types / jaeger-client / jaeger-client-tests.ts View on Github external
import * as jaegerClient from "jaeger-client";
import * as promClient from "prom-client";
import * as opentracing from "opentracing";

const tracingConfig: jaegerClient.TracingConfig = {};
const tracingOptions: jaegerClient.TracingOptions = {};

const tracer = jaegerClient.initTracer(tracingConfig, tracingOptions);
jaegerClient.initTracerFromEnv(tracingConfig, tracingOptions);

const metrics = new jaegerClient.PrometheusMetricsFactory(promClient, "foo");

const textCodec = new jaegerClient.TextMapCodec({
    contextKey: 'trace-id',
    baggagePrefix: 'baggage-',
    urlEncoding: false,
});
tracer.registerInjector(opentracing.FORMAT_TEXT_MAP, textCodec);
tracer.registerExtractor(opentracing.FORMAT_TEXT_MAP, textCodec);

const zipkinB3TextMapCodec = new jaegerClient.ZipkinB3TextMapCodec({
    baggagePrefix: 'baggage-',
    urlEncoding: false,
});
github hemerajs / hemera / packages / hemera-jaeger / index.js View on Github external
const contextKey = 'opentracing'
  const tracingKey = 'opentracing'
  const tracePrefix = 'Hemera'

  const tags = {
    HEMERA_PATTERN: 'hemera.pattern',
    HEMERA_SERVICE: 'hemera.service',
    HEMERA_ACT_TIMEOUT: 'hemera.act.timeout',
    HEMERA_ACT_MAXMSG: 'hemera.act.maxMsg',
    HEMERA_ACT_EXPECTEDMSG: 'hemera.act.expMsg',
    HEMERA_PUBSUB: 'hemera.pubsub',
    HEMERA_OP_TYPE: 'hemera.operationType',
    HEMERA_CONTEXT: 'hemera.context'
  }

  const tracer = initTracer(opts.config, opts.options)

  hemera.decorate('jaeger', {
    tracer
  })

  hemera.ext('onError', (hemera, payload, error, next) => {
    const span = hemera[jaegerContextKey]

    span.setTag(Opentracing.Tags.ERROR, true)
    span.log({
      event: 'error',
      'error.object': error,
      message: error.message,
      stack: error.stack
    })
github sourcegraph / javascript-typescript-langserver / src / language-server.ts View on Github external
'number of concurrent cluster workers (defaults to number of CPUs, ' + numCPUs + ')',
        parseInt
    )
    .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 options: ServeOptions & TypeScriptServiceOptions = {
    clusterSize: program.cluster || numCPUs,
    lspPort: program.port || defaultLspPort,
    strict: program.strict,
    logMessages: program.trace,
    logger: program.logfile ? new FileLogger(program.logfile) : new StdioLogger(),
    tracer: program.enableJaeger
        ? initTracer({ serviceName: 'javascript-typescript-langserver', sampler: { type: 'const', param: 1 } })
        : new Tracer(),
}

serve(options, client => new TypeScriptService(client, options))
github tvvignesh / node-skeleton / src / app / utils / tracing.utils.ts View on Github external
const options = {
        logger: {
            info(msg) {
                log('info', {
                    payload: msg
                });
            },
            error(msg) {
                log('error', {
                    payload: msg
                });
            }
        }
    };

    global['tracer'] = initJaegerTracer(tracerConfig, options);

    let parentSpan;

    if (Object.keys(headers).length === 0) {
        parentSpan = global['tracer'].startSpan(projectName);
    } else {
        const parentSpanContext = global['tracer'].extract(
            FORMAT_HTTP_HEADERS,
            headers
        );

        parentSpan = global['tracer'].startSpan(projectName, {
            childOf: parentSpanContext
        });
    }
github alextanhongpin / full-stack-microservice / opentracing / node / server.js View on Github external
sampler: {
    type: 'const',
    param: 1,
    host: 'localhost',
    port: '5775',
    refreshIntervalMs: 500
  }
}
const options = {
  tags: {
    'my-awesome-service.version': '1.1.2'
  },
  metrics: null,
  logger: null
}
const tracer = initTracer(config, options)

const parentSpan = tracer.startSpan('test')
parentSpan.addTags({ level: 0 })

const child = tracer.startSpan('child_span', { childOf: parentSpan })
child.setTag('alpha', '200')
child.setTag('beta', '50')
child.log({state: 'waiting'})

setTimeout(() => {
  child.log({state: 'done'})
  child.finish()
  parentSpan.finish()
  tracer.close()
}, 500)