Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improv(instrumentation-http): supressInstrumentation when we get a request on ignoredPath [#1831] #1838

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 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,11 @@ export class HttpInstrumentation extends InstrumentationBase<Http> {
)
)
) {
return original.apply(this, [event, ...args]);
return context.with(suppressInstrumentation(context.active()), () => {
context.bind(request);
context.bind(response);
return original.apply(this, [event, ...args]);
vmarchaud marked this conversation as resolved.
Show resolved Hide resolved
});
}

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
7 changes: 6 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,11 @@ 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()), () => {
context.bind(request);
context.bind(response);
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