How to use the opentracing.initGlobalTracer function in opentracing

To help you get started, we’ve selected a few opentracing 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 opentracing-contrib / nginx-opentracing / example / zoo / node / opentracing-express.js View on Github external
exports.middleware = function middleware(options) {
  if (typeof options === 'undefined') {
    options = {};
  }
  if (options.tracer) {
    opentracing.initGlobalTracer(options.tracer);
  } else {
    opentracing.initGlobalTracer();
  }

  return (req, res, next) => {
    const tracer = opentracing.globalTracer();
    const wireCtx =
        tracer.extract(opentracing.FORMAT_HTTP_HEADERS, req.headers);
    const pathname = url.parse(req.url).pathname;
    const span = tracer.startSpan(pathname, { childOf: wireCtx });
    span.logEvent('request_received');

    // include some useful tags on the trace
    span.setTag('http.method', req.method);
    span.setTag('span.kind', 'server');
    span.setTag('http.url', req.url);
github signalfx / tracing-examples / aws-lambda / jaeger-nodejs / index.js View on Github external
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 lightstep / lightstep-tracer-javascript / examples / node / index.js View on Github external
// Proxy the requests through a LightStep server
var PROXY_HOST = process.env.LIGHTSTEP_PROXY_HOST || 'example-proxy.lightstep.com';
var PROXY_PORT = process.env.LIGHTSTEP_PROXY_PORT || 80;

//
// The first argument to the script is the GitHub user name
//
var username = process.argv[2] || 'lightstep';

// Initialize the OpenTracing APIs to use the LightStep bindings
//
// NOTE: the access token will need to be replaced with your project's access
// token. The component_name can be an identifier you wish to use to identify the
// service or process.
//
opentracing.initGlobalTracer(new lightstep.Tracer({
    access_token   : '{your_access_token}',
    component_name : 'lightstep-tracer/examples/node',
}));

// Do the work.
printUserInfo(username);

//
// Worker functions
//
function printUserInfo(username) {

    // Start the outer operation span
    var span = opentracing.globalTracer().startSpan('printUserInfo');
    span.log({ event : 'query_started' });
github opentracing-contrib / nginx-opentracing / example / zoo / node / opentracing-express.js View on Github external
exports.middleware = function middleware(options) {
  if (typeof options === 'undefined') {
    options = {};
  }
  if (options.tracer) {
    opentracing.initGlobalTracer(options.tracer);
  } else {
    opentracing.initGlobalTracer();
  }

  return (req, res, next) => {
    const tracer = opentracing.globalTracer();
    const wireCtx =
        tracer.extract(opentracing.FORMAT_HTTP_HEADERS, req.headers);
    const pathname = url.parse(req.url).pathname;
    const span = tracer.startSpan(pathname, { childOf: wireCtx });
    span.logEvent('request_received');

    // include some useful tags on the trace
    span.setTag('http.method', req.method);
    span.setTag('span.kind', 'server');
    span.setTag('http.url', req.url);
    span.setTag('component', 'express');
github DanielMSchmidt / zipkin-javascript-opentracing / src / __tests__ / index.js View on Github external
it("should set a global tracer", () => {
    opentracing.initGlobalTracer(
      new Tracer({
        serviceName: "MyService",
        recorder: {},
        kind: "server"
      })
    );

    const tracer = opentracing.globalTracer();
    expect(tracer.startSpan).toBeInstanceOf(Function);
  });
github instana / nodejs-sensor / test / tracing / open_tracing / app.js View on Github external
instana({
  agentPort: process.env.AGENT_PORT,
  level: 'warn',
  serviceName: 'theFancyServiceYouWouldntBelieveActuallyExists',
  tracing: {
    enabled: process.env.TRACING_ENABLED === 'true',
    forceTransmissionStartingAt: 1,
    disableAutomaticTracing: process.env.DISABLE_AUTOMATIC_TRACING === 'true'
  }
});

var opentracing = require('opentracing');
var express = require('express');
var app = express();

opentracing.initGlobalTracer(instana.opentracing.createTracer());
var tracer = opentracing.globalTracer();

app.get('/', function(req, res) {
  res.send('OK');
});

app.get('/withOpentracing', function(req, res) {
  log('########################## Start span!');
  var serviceSpan = tracer.startSpan('service');
  log('########################## Started span:', serviceSpan);
  serviceSpan.setTag(opentracing.Tags.SPAN_KIND, opentracing.Tags.SPAN_KIND_RPC_SERVER);
  var authSpan = tracer.startSpan('auth', { childOf: serviceSpan });
  authSpan.finish();
  serviceSpan.finish();
  res.send('OK');
});
github opentracing-contrib / nginx-opentracing / example / zoo / node / server.js View on Github external
winston.error('no data_root given!');
  process.exit(1);
}

if (typeof program.access_token === 'undefined') {
  winston.error('no access_token given!');
  process.exit(1);
}

const databasePath = path.join(program.data_root, common.databaseName);
const imageRoot = path.join(program.data_root, '/images/');
const accessToken = program.access_token;

const tracer = new lightstep.Tracer(
    { access_token: accessToken, component_name: 'zoo' });
opentracing.initGlobalTracer(tracer);

const db = new sqlite3.Database(databasePath);
db.run('PRAGMA journal_mode = WAL');
db.configure('busyTimeout', 15000);

function onExit() {
  db.close();
  process.exit(0);
}
process.on('SIGINT', onExit);
process.on('SIGTERM', onExit);

const app = express();
app.use(tracingMiddleware.middleware({ tracer }));
app.set('view engine', 'pug');
app.set('views', path.join(__dirname, '/views'));
github zalando-zmon / zmon-controller / zmon-controller-ui / lib / opentracing-javascript-utils / src / lib.js View on Github external
.then( () => {
          let customTracer = lib.getCustomTracer(tracerConfig)
          opentracing.initGlobalTracer(customTracer)
          resolve(opentracing.globalTracer())
        })
        .catch( (e) => {