Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
before((done) => {
tracer.start({ samplingRate: 1, logger: logger.logger(4) })
tracer.registerSpanEventListener(rootSpanVerifier)
const basedir = path.dirname(require.resolve('mysql2'))
plugin.enable(mysql, tracer, VERSION, {}, basedir)
connectConnection(URL)
.then(server => {
client = server
pool = createPool(URL)
done()
})
.catch((err: Error) => {
console.log(
'Skipping test-mysql2. Could not connect. Run Mysql to test', err)
shouldTest = false
done()
})
})
request.on('error', err => {
reject(err)
})
})
}
}
let server: http2.Http2Server
let client: http2.ClientHttp2Session
const serverPort = 8080
const host = `localhost:${serverPort}`
const authority = `http://${host}`
const tracer = new CoreTracer()
const rootSpanVerifier = new RootSpanVerifier()
tracer.start({ samplingRate: 1, logger: logger.logger(4) })
it('should return a plugin', () => {
assert.ok(plugin instanceof Http2Plugin)
})
before(() => {
tracer.registerSpanEventListener(rootSpanVerifier)
plugin.enable(http2, tracer, VERSION, {}, '')
server = http2.createServer()
server.on('stream', (stream, requestHeaders) => {
const pathHeader = requestHeaders[':path']
if (pathHeader === undefined) throw new Error(`Undefined path header`)
const statusCode = pathHeader.length > 1 ?
+pathHeader.slice(1) :
200
before((done) => {
tracer.start({ samplingRate: 1, logger: logger.logger(4) })
tracer.registerSpanEventListener(rootSpanVerifier)
plugin.enable(redis, tracer, VERSION, {}, '')
client = redis.createClient({
url: URL
})
client.on('error', (err: Error) => {
console.log(
'Skipping test-redis. Could not connect. Run Redis to test', err)
shouldTest = false
done()
})
client.on('ready', done)
})
describe('HttpsPlugin', () => {
const hostName = 'fake.service.io'
const urlHost = `https://${hostName}`
let serverPort = 3000
let server: https.Server
const tracer = new CoreTracer()
const rootSpanVerifier = new RootSpanVerifier()
tracer.start({ samplingRate: 1, logger: logger.logger(4) })
it('should return a plugin', () => {
assert.ok(plugin instanceof HttpsPlugin)
})
before(() => {
plugin.enable(
https, tracer, VERSION, {
ignoreIncomingPaths: [
'/ignored/string', /^\/ignored\/regexp/,
(url: string) => url === '/ignored/function'
],
ignoreOutgoingUrls: [
`${urlHost}/ignored/string`,
/^https:\/\/fake\.service\.io\/ignored\/regexp$/,
(url: string) => url === `${urlHost}/ignored/function`
before(async () => {
tracer.start({ samplingRate: 1, logger: logger.logger(4) })
tracer.registerSpanEventListener(rootSpanVerifier)
const basedir = path.dirname(require.resolve("pg/package.json")); //require.resolve was returning direct path to lib, as in current pg version they have defined "main" path section which was breaking this test case. We need only path of PG nodule not lib folder. This fixes this issue.
plugin.enable(pg, tracer, VERSION, {}, basedir)
client = new pg.Client(CONFIG)
try {
await client.connect()
} catch (err) {
console.log(
'Skipping test-pg. Could not connect. Run Postgres to test', err)
shouldTest = false
}
})
before((done) => {
tracer.start({ samplingRate: 1, logger: logger.logger(4) })
tracer.registerSpanEventListener(rootSpanVerifier)
plugin.enable(net, tracer, VERSION, {}, '')
httpPlugin.plugin.enable(http, tracer, process.versions.node, {
createSpanWithNet: true
}, '')
return done()
})
before((done) => {
tracer.start({ samplingRate: 1, logger: logger.logger(4) })
tracer.registerSpanEventListener(rootSpanVerifier)
httpPlugin.plugin.enable(http, tracer, process.versions.node, {}, '')
plugin.enable(express, tracer, VERSION, {}, '')
return done()
})
constructor(options: ZipkinExporterOptions) {
this.zipkinUrl =
(options.url && url.parse(options.url)) ||
url.parse(ZipkinTraceExporter.DEFAULT_URL);
this.serviceName = options.serviceName;
this.buffer = new ExporterBuffer(this, options);
this.logger = options.logger || logger.logger();
}
stop() {
this.activeLocal = false;
this.tracer.stop();
if (this.pluginLoader) {
this.pluginLoader.unloadPlugins();
}
this.configLocal = {};
this.logger = logger.logger();
}
import { PluginLoader } from './instrumentation/plugin-loader';
const NOOP_EXPORTER = new core.NoopExporter();
/** Implements a Tracing. */
export class TracingBase implements core.Tracing {
/** A tracer object */
readonly tracer: core.TracerBase;
/** A plugin loader object */
private pluginLoader?: PluginLoader;
/** Plugin names */
protected defaultPlugins: core.PluginNames;
/** A configuration object to start the tracing */
private configLocal: core.Config = {};
/** An object to log information to. Logs to the JS console by default. */
private logger: core.Logger = logger.logger();
/** Singleton instance */
private static singletonInstance: core.Tracing;
/** Indicates if the tracing is active */
private activeLocal = false;
/** Constructs a new TracingImpl instance. */
constructor(pluginNames: string[] = []) {
this.tracer = new core.CoreTracerBase();
this.defaultPlugins = PluginLoader.defaultPluginsFromArray(pluginNames);
}
/** Gets the tracing instance. */
static get instance(): core.Tracing {
return this.singletonInstance || (this.singletonInstance = new this());
}