Skip to content

Commit

Permalink
manually emit end event from close if one has not already been em…
Browse files Browse the repository at this point in the history
…ited
  • Loading branch information
SimenB committed Mar 21, 2023
1 parent f2c139d commit 1f07e5f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,21 @@ export class HttpInstrumentation extends InstrumentationBase<Http> {

context.bind(context.active(), response);
this._diag.debug('outgoingRequest on response()');

// See https://github.com/open-telemetry/opentelemetry-js/pull/3625#issuecomment-1475673533
let endEmitted = false;
if (semver.lt(process.version, '16.0.0')) {
response.on('close', () => {
this._diag.debug('outgoingRequest on close()');
if (!endEmitted) {
response.emit('end');
}
});
}

response.on('end', () => {
this._diag.debug('outgoingRequest on end()');
endEmitted = true;
let status: SpanStatus;

if (response.aborted && !response.complete) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ describe('HttpInstrumentation', () => {
`${protocol}://${hostname}:${serverPort}/hang`,
res => {
res.on('close', () => {});
res.on('error', () => {});
res.on('error', reject);
}
);
// close the socket.
Expand Down

0 comments on commit 1f07e5f

Please sign in to comment.