Skip to content

Commit

Permalink
fix(http-plugin): strip otel custom http header open-telemetry#983
Browse files Browse the repository at this point in the history
  • Loading branch information
vmarchaud committed Apr 26, 2020
1 parent b28bed4 commit 65988bd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/opentelemetry-plugin-http/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,12 @@ export class HttpPlugin extends BasePlugin<Http> {
extraOptions
);

if (utils.isOpenTelemetryRequest(optionsParsed)) {
delete optionsParsed.headers![utils.OT_REQUEST_HEADER];
return original.apply(this, [optionsParsed, ...args]);
}

if (
utils.isOpenTelemetryRequest(optionsParsed) ||
utils.isIgnored(
origin + pathname,
plugin._config.ignoreOutgoingUrls,
Expand Down
4 changes: 4 additions & 0 deletions packages/opentelemetry-plugin-http/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ import { AttributeNames } from './enums/AttributeNames';
import * as url from 'url';
import { Socket } from 'net';

/**
* Specific header used by exporters to "mark" outgoing request to avoid creating
* spans for request that export them which would create a infinite loop.
*/
export const OT_REQUEST_HEADER = 'x-opentelemetry-outgoing-request';

export const HTTP_STATUS_SPECIAL_CASES: SpecialHttpStatusCodeMapping = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ describe('HttpPlugin', () => {
};

const result = await httpRequest.get(options);
assert(
result.reqHeaders[OT_REQUEST_HEADER] === undefined,
'custom header should be stripped'
);
const spans = memoryExporter.getFinishedSpans();
assert.strictEqual(result.data, 'Ok');
assert.strictEqual(spans.length, 0);
Expand Down Expand Up @@ -293,6 +297,10 @@ describe('HttpPlugin', () => {
};

const result = await httpRequest.get(options);
assert(
result.reqHeaders[OT_REQUEST_HEADER] === undefined,
'custom header should be stripped'
);
const spans = memoryExporter.getFinishedSpans();
assert.strictEqual(result.data, 'Ok');
assert.strictEqual(spans.length, 0);
Expand Down

0 comments on commit 65988bd

Please sign in to comment.