Skip to content

Commit

Permalink
fix: avoid adding child spans to closed root (#631)
Browse files Browse the repository at this point in the history
Fixes: #603
  • Loading branch information
ofrobots committed Jan 4, 2018
1 parent 3b1cd24 commit 63ca143
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/trace-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,17 @@ export class TraceAgent implements TraceAgentInterface {
return null;
} else {
if (rootSpan.span.isClosed()) {
// A closed root span suggests that we either have context confusion or
// some work is being done after the root request has been completed.
// The first case could lead to a memory leak, if somehow all spans end
// up getting misattributed to the same root span – we get a root span
// with continuously growing number of child spans. The second case
// seems to have some value, but isn't representable. The user probably
// needs a custom outer span that encompasses the entirety of work.
this.logger.warn(
this.pluginName + ': creating child for an already closed span',
options.name, rootSpan.span.name);
return null;
}
// Create a new child span and return it.
options = options || {name: ''};
Expand Down

0 comments on commit 63ca143

Please sign in to comment.