How to use the opentracing.globalTracer 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 lightstep / lightstep-tracer-javascript / examples / node / index.js View on Github external
function httpGet(parentSpan, urlString, callback) {
    var span = opentracing.globalTracer().startSpan('http.get', { childOf : parentSpan });
    var callbackWrapper = function (err, data) {
        span.finish();
        callback(err, data);
    };

    try {
        var carrier = {};
        opentracing.globalTracer().inject(span, opentracing.FORMAT_TEXT_MAP, carrier);

        var dest = url.parse(urlString);
        var options = {
            host : PROXY_HOST,
            path : dest.path,
            port : PROXY_PORT,
            headers: {
                // User-Agent is required by the GitHub APIs
github zalando / tailor / lib / request-fragment.js View on Github external
'use strict';

const http = require('http');
const https = require('https');
const url = require('url');
const { globalTracer, FORMAT_HTTP_HEADERS } = require('opentracing');
const tracer = globalTracer();

// By default tailor supports gzipped response from fragments
const requiredHeaders = {
    'accept-encoding': 'gzip, deflate'
};

/**
 * Simple Request Promise Function that requests the fragment server with
 *  - filtered headers
 *  - Specified timeout from fragment attributes
 *
 * @param {filterHeaders} - Function that handles the header forwarding
 * @param {string} fragmentUrl - URL of the fragment server
 * @param {Object} fragmentAttributes - Attributes passed via fragment tags
 * @param {Object} request - HTTP request stream
 * @param {Object} span - opentracing span context passed for propagation
github signalfx / tracing-examples / aws-lambda / jaeger-nodejs / index.js View on Github external
function playRoulette(choice, parentSpan) {
  // Retrieve our previously-registered tracer
  const tracer = opentracing.globalTracer();
  const options = { childOf: parentSpan.context() };
  const span = tracer.startSpan('playRoulette', options);
  span.setTag('choice', choice);

  // Here we create a child span in parent function for direct access
  // within spinRouletteWheel().
  const childSpan = tracer.startSpan('spinRouletteWheel', { childOf: span.context() });
  const actual = spinRouletteWheel(childSpan);
  childSpan.finish();

  span.setTag('actual', actual);
  try {
    if (choice === actual || choice === 'win') {
      throw new Error('Confirmation Bias!');
    }
    return `You Lost! The ball landed on ${actual}.`;
github opentracing-contrib / nginx-opentracing / example / zoo / node / opentracing-express.js View on Github external
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');

    // include trace ID in headers so that we can debug slow requests we see in
    // the browser by looking up the trace ID found in response headers
    const responseHeaders = {};
    tracer.inject(span, opentracing.FORMAT_TEXT_MAP, responseHeaders);
github fapspirit / axios-opentracing / tests / index.spec.ts View on Github external
it('should return same span when he passed', () => {
      const tracer = globalTracer();
      const span = tracer.startSpan('test');
      const returnedSpan = applyTracingInterceptors(axiosInstance, { span });

      expect(span).to.be.equal(returnedSpan);
    });
  });
github hawkular / hawkular-apm / tests / app / polyglot-opentracing / js / index.js View on Github external
});

        http.get({
            host: httpOptions.host,
            port: httpOptions.port,
            path: httpOptions.path,
            headers: createCarrier(opentracing.globalTracer(), clientSpan),
        }, function (response) {
            clientSpan.setTag('http.status_code', response.statusCode);
            clientSpan.finish();
            callback(response);
        });
    }

    const serverSpan = opentracing.globalTracer().startSpan('get_user', {
        childOf: extractSpanContext(opentracing.globalTracer(), req.headers),
        tags: {
            'http.method': 'GET',
            'http.url': extractUrl(req),
        }
    });

    getRequest(serverSpan, {
        host: 'wildfly-swarm',
        port: 3000,
        path: '/wildfly-swarm/user'
    }, 'get_user[wildfly-swarm]', function (response) {
        serverSpan.setTag('http.status_code', 200);
        serverSpan.finish();
        res.writeHead(200);
        res.end(JSON.stringify({name: "admin"}));
    });
github SyncOT / SyncOT / packages / connection / src / connection.ts View on Github external
private async onServiceRequest(
        { instance, streams: serviceStreams }: RegisteredServiceDescriptor,
        message: RequestMessage,
    ): Promise {
        const stream = this.stream
        const { id, name, service } = message
        const span = globalTracer().startSpan('syncot.connection.request')
        span.setTag('component', component)
        span.setTag('request.name', name)
        span.setTag('request.service', service)
        span.setTag('span.kind', 'server')

        try {
            const reply = await (instance as any)[name](
                ...message.data,
                span.context(),
            )

            span.finish()
            if (this.stream !== stream) {
                if (isStream(reply)) {
                    reply.destroy()
                }