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

fix(http): do not set outgoing http span as active in the context #1479 #1546

Merged
merged 5 commits into from
Oct 13, 2020
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
30 changes: 17 additions & 13 deletions packages/opentelemetry-plugin-http/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
SpanContext,
TraceFlags,
getExtractedSpanContext,
setActiveSpan,
} from '@opentelemetry/api';
import { BasePlugin, NoRecordingSpan } from '@opentelemetry/core';
import type {
Expand Down Expand Up @@ -410,21 +411,24 @@ export class HttpPlugin extends BasePlugin<Http> {
kind: SpanKind.CLIENT,
};
const span = plugin._startHttpSpan(operationName, spanOptions);
if (!optionsParsed.headers) {
optionsParsed.headers = {};
}
propagation.inject(
optionsParsed.headers,
undefined,
setActiveSpan(context.active(), span)
);

return plugin._tracer.withSpan(span, () => {
if (!optionsParsed.headers) optionsParsed.headers = {};
propagation.inject(optionsParsed.headers);

const request: ClientRequest = plugin._safeExecute(
span,
() => original.apply(this, [optionsParsed, ...args]),
true
);
const request: ClientRequest = plugin._safeExecute(
span,
() => original.apply(this, [optionsParsed, ...args]),
true
);

plugin._logger.debug('%s plugin outgoingRequest', plugin.moduleName);
plugin._tracer.bind(request);
return plugin._traceClientRequest(request, optionsParsed, span);
});
plugin._logger.debug('%s plugin outgoingRequest', plugin.moduleName);
plugin._tracer.bind(request);
return plugin._traceClientRequest(request, optionsParsed, span);
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
propagation,
Span as ISpan,
SpanKind,
getActiveSpan,
} from '@opentelemetry/api';
import { NoopLogger } from '@opentelemetry/core';
import { NodeTracerProvider } from '@opentelemetry/node';
Expand Down Expand Up @@ -709,6 +710,14 @@ describe('HttpPlugin', () => {
SpanKind.CLIENT
);
});

it('should not set span as active in context for outgoing request', done => {
assert.deepStrictEqual(getActiveSpan(context.active()), undefined);
http.get(`${protocol}://${hostname}:${serverPort}/test`, res => {
assert.deepStrictEqual(getActiveSpan(context.active()), undefined);
done();
});
});
});

describe('with require parent span', () => {
Expand Down