diff --git a/src/publisher/message-queues.ts b/src/publisher/message-queues.ts index 2d307cea1..c7d4a1999 100644 --- a/src/publisher/message-queues.ts +++ b/src/publisher/message-queues.ts @@ -173,12 +173,15 @@ export abstract class MessageQueue extends EventEmitter { throw e; } finally { messages.forEach(m => { - // We're finished with both the RPC and the whole publish operation, - // so close out all of the related spans. - rpcSpan?.end(); tracing.PubsubEvents.publishEnd(m); - m.parentSpan?.end(); }); + + // We're finished with both the RPC and the whole publish operation, + // so close out all of the related spans. + new Set(messages.map(m => m.parentSpan)).forEach(parentSpan => { + parentSpan?.end(); + }); + rpcSpan?.end(); } } }