Skip to content

Commit

Permalink
fix: use socket from the request
Browse files Browse the repository at this point in the history
  • Loading branch information
mzahor committed Feb 17, 2021
1 parent 03e741b commit b654fa4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion packages/opentelemetry-instrumentation-http/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,10 @@ export const getIncomingRequestAttributesOnResponse = (
request: IncomingMessage & { __ot_middlewares?: string[] },
response: ServerResponse & { socket: Socket }
): SpanAttributes => {
const { statusCode, statusMessage, socket } = response;
// take socket from the request,
// since it may be detached from the response object in keep-alive mode
const { socket } = request;
const { statusCode, statusMessage } = response;
const { localAddress, localPort, remoteAddress, remotePort } = socket;
const { __ot_middlewares } = (request as unknown) as {
[key: string]: unknown;
Expand Down
5 changes: 4 additions & 1 deletion packages/opentelemetry-plugin-http/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,10 @@ export const getIncomingRequestAttributesOnResponse = (
request: IncomingMessage & { __ot_middlewares?: string[] },
response: ServerResponse & { socket: Socket }
): SpanAttributes => {
const { statusCode, statusMessage, socket } = response;
// use socket from the request,
// since it may be detached from the response object in keep-alive mode
const { socket } = request;
const { statusCode, statusMessage } = response;
const { localAddress, localPort, remoteAddress, remotePort } = socket;
const { __ot_middlewares } = (request as unknown) as {
[key: string]: unknown;
Expand Down

0 comments on commit b654fa4

Please sign in to comment.