Skip to content

Commit 2fcb76d

Browse files
authored
improv(instrumentation-http): supressInstrumentation when we get a request on ignoredPath [#1831] (#1838)
1 parent f43855d commit 2fcb76d

File tree

6 files changed

+24
-2
lines changed

6 files changed

+24
-2
lines changed

packages/opentelemetry-instrumentation-http/src/http.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
TraceFlags,
2727
ROOT_CONTEXT,
2828
getSpan,
29+
suppressInstrumentation,
2930
} from '@opentelemetry/api';
3031
import { NoRecordingSpan } from '@opentelemetry/core';
3132
import type * as http from 'http';
@@ -392,7 +393,11 @@ export class HttpInstrumentation extends InstrumentationBase<Http> {
392393
)
393394
)
394395
) {
395-
return original.apply(this, [event, ...args]);
396+
return context.with(suppressInstrumentation(context.active()), () => {
397+
context.bind(request);
398+
context.bind(response);
399+
return original.apply(this, [event, ...args]);
400+
});
396401
}
397402

398403
const headers = request.headers;

packages/opentelemetry-instrumentation-http/test/functionals/http-enable.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ describe('HttpInstrumentation', () => {
209209
});
210210
instrumentation.enable();
211211
server = http.createServer((request, response) => {
212+
if (request.url?.includes('/ignored')) {
213+
provider.getTracer('test').startSpan('some-span').end();
214+
}
212215
response.end('Test Server Response');
213216
});
214217

packages/opentelemetry-instrumentation-http/test/functionals/https-enable.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@ describe('HttpsInstrumentation', () => {
200200
cert: fs.readFileSync('test/fixtures/server-cert.pem'),
201201
},
202202
(request, response) => {
203+
if (request.url?.includes('/ignored')) {
204+
tracer.startSpan('some-span').end();
205+
}
203206
response.end('Test Server Response');
204207
}
205208
);

packages/opentelemetry-plugin-http/src/http.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
setSpan,
2727
ROOT_CONTEXT,
2828
getSpan,
29+
suppressInstrumentation,
2930
} from '@opentelemetry/api';
3031
import { BasePlugin, NoRecordingSpan } from '@opentelemetry/core';
3132
import type {
@@ -295,7 +296,11 @@ export class HttpPlugin extends BasePlugin<Http> {
295296
plugin._logger.error('caught ignoreIncomingPaths error: ', e)
296297
)
297298
) {
298-
return original.apply(this, [event, ...args]);
299+
return context.with(suppressInstrumentation(context.active()), () => {
300+
context.bind(request);
301+
context.bind(response);
302+
return original.apply(this, [event, ...args]);
303+
});
299304
}
300305

301306
const headers = request.headers;

packages/opentelemetry-plugin-http/test/functionals/http-enable.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,9 @@ describe('HttpPlugin', () => {
211211
};
212212
plugin.enable(http, provider, provider.logger, config);
213213
server = http.createServer((request, response) => {
214+
if (request.url?.includes('/ignored')) {
215+
provider.getTracer('test').startSpan('some-span').end();
216+
}
214217
response.end('Test Server Response');
215218
});
216219

packages/opentelemetry-plugin-https/test/functionals/https-enable.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@ describe('HttpsPlugin', () => {
216216
cert: fs.readFileSync('test/fixtures/server-cert.pem'),
217217
},
218218
(request, response) => {
219+
if (request.url?.includes('/ignored')) {
220+
tracer.startSpan('some-span').end();
221+
}
219222
response.end('Test Server Response');
220223
}
221224
);

0 commit comments

Comments
 (0)