Skip to content

Commit

Permalink
improv(instrumentation-http): supressInstrumentation when we get a re…
Browse files Browse the repository at this point in the history
…quest on ignoredPath [#1831]
  • Loading branch information
vmarchaud committed Jan 17, 2021
1 parent 471306f commit df17763
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 2 deletions.
5 changes: 4 additions & 1 deletion packages/opentelemetry-instrumentation-http/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
TraceFlags,
ROOT_CONTEXT,
getSpan,
suppressInstrumentation,
} from '@opentelemetry/api';
import { NoRecordingSpan } from '@opentelemetry/core';
import type * as http from 'http';
Expand Down Expand Up @@ -392,7 +393,9 @@ export class HttpInstrumentation extends InstrumentationBase<Http> {
)
)
) {
return original.apply(this, [event, ...args]);
return context.with(suppressInstrumentation(context.active()), () => {
return original.apply(this, [event, ...args]);
});
}

const headers = request.headers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ describe('HttpInstrumentation', () => {
});
instrumentation.enable();
server = http.createServer((request, response) => {
if (request.url?.includes('/ignored')) {
provider.getTracer('test').startSpan('some-span').end();
}
response.end('Test Server Response');
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ describe('HttpsInstrumentation', () => {
cert: fs.readFileSync('test/fixtures/server-cert.pem'),
},
(request, response) => {
if (request.url?.includes('/ignored')) {
tracer.startSpan('some-span').end();
}
response.end('Test Server Response');
}
);
Expand Down
5 changes: 4 additions & 1 deletion packages/opentelemetry-plugin-http/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
setSpan,
ROOT_CONTEXT,
getSpan,
suppressInstrumentation,
} from '@opentelemetry/api';
import { BasePlugin, NoRecordingSpan } from '@opentelemetry/core';
import type {
Expand Down Expand Up @@ -295,7 +296,9 @@ export class HttpPlugin extends BasePlugin<Http> {
plugin._logger.error('caught ignoreIncomingPaths error: ', e)
)
) {
return original.apply(this, [event, ...args]);
return context.with(suppressInstrumentation(context.active()), () => {
return original.apply(this, [event, ...args]);
});
}

const headers = request.headers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ describe('HttpPlugin', () => {
};
plugin.enable(http, provider, provider.logger, config);
server = http.createServer((request, response) => {
if (request.url?.includes('/ignored')) {
provider.getTracer('test').startSpan('some-span').end();
}
response.end('Test Server Response');
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ describe('HttpsPlugin', () => {
cert: fs.readFileSync('test/fixtures/server-cert.pem'),
},
(request, response) => {
if (request.url?.includes('/ignored')) {
tracer.startSpan('some-span').end();
}
response.end('Test Server Response');
}
);
Expand Down

0 comments on commit df17763

Please sign in to comment.