Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
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;
}
// 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' });
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');
it("should set a global tracer", () => {
opentracing.initGlobalTracer(
new Tracer({
serviceName: "MyService",
recorder: {},
kind: "server"
})
);
const tracer = opentracing.globalTracer();
expect(tracer.startSpan).toBeInstanceOf(Function);
});
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');
});
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'));
.then( () => {
let customTracer = lib.getCustomTracer(tracerConfig)
opentracing.initGlobalTracer(customTracer)
resolve(opentracing.globalTracer())
})
.catch( (e) => {