Skip to content

Commit

Permalink
fix error span.finish() call when already called.
Browse files Browse the repository at this point in the history
  • Loading branch information
rotem Bloom committed Oct 27, 2020
1 parent 84e029d commit ff4dc42
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 6 additions & 2 deletions lib/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ const opentracingEnd = (options = {}) => {
span.log({ event: 'request_finished' });

try {
span.finish();
if (span._duration === undefined) {
span.finish();
}
} catch (err) {
return context;
}
Expand Down Expand Up @@ -106,7 +108,9 @@ const opentracingError = (options = {}) => {
span.log({ event: 'request_error', message });

try {
span.finish();
if (span._duration === undefined) {
span.finish();
}
} catch (err) {
return context;
}
Expand Down
6 changes: 5 additions & 1 deletion lib/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ module.exports = function (req, res, options = {}) {
if (resHeaders && Object.keys(resHeaders).length) { tagObject('response.headers', resHeaders, span, options); }
}

span.finish();
try {
if (span._duration === undefined) {
span.finish();
}
} catch (err) {}
};

res.on('close', finishSpan);
Expand Down

0 comments on commit ff4dc42

Please sign in to comment.