Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'jaeger-client' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
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 => {
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;
}
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)
}
'use strict'
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([
'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
'use strict'
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
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' })
'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'
'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) => {
'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({