constructor(tracer, remoteServiceName) { this.tracer = tracer; this.instrumentation = new Instrumentation.HttpClient({tracer, remoteServiceName}); /** * This section is very important, it guarantees correct trace duration */ this.httpRequest = request.defaults((options, callback) => tracer.scoped(() => { const method = options.method || 'GET'; const url = options.uri || options.url; const wrappedOptions = this.instrumentation.recordRequest(options, url, method); const traceId = tracer.id; const recordResponse = response => tracer.scoped( // TODO: scoped bc recordResponse leaks () => this.instrumentation.recordResponse(traceId, response.statusCode) ); const recordError = error => tracer.scoped( // TODO: scoped bc recordError leaks () => this.instrumentation.recordError(traceId, error) ); return request(wrappedOptions, callback) .on('response', recordResponse) .on('error', recordError); })); }
describe('Instrumentation', () => { describe('HttpClient', () => { it('should have correct type', () => { const instrumentation: Instrumentation.HttpClient = new Instrumentation.HttpClient({ tracer: new Tracer({ ctxImpl: new ExplicitContext(),
constructor(tracer, remoteServiceName) { this.tracer = tracer; this.instrumentation = new Instrumentation.HttpClient({tracer, remoteServiceName}); /** * This section is very important, it guarantees correct trace duration */ this.httpRequest = request.defaults((options, callback) => tracer.scoped(() => { const method = options.method || 'GET'; const url = options.uri || options.url; const wrappedOptions = this.instrumentation.recordRequest(options, url, method); const traceId = tracer.id; const recordResponse = response => tracer.scoped( // TODO: scoped bc recordResponse leaks () => this.instrumentation.recordResponse(traceId, response.statusCode) ); const recordError = error => tracer.scoped( // TODO: scoped bc recordError leaks () => this.instrumentation.recordError(traceId, error) ); return request(wrappedOptions, callback) .on('response', recordResponse) .on('error', recordError); })); }
describe('Instrumentation', () => { describe('HttpClient', () => { it('should have correct type', () => { const instrumentation: Instrumentation.HttpClient = new Instrumentation.HttpClient({ tracer: new Tracer({ ctxImpl: new ExplicitContext(),