From 7aec711200d8e79686370f5d40915e21df7651a4 Mon Sep 17 00:00:00 2001 From: Koichi Shiraishi Date: Sat, 7 Dec 2024 03:16:26 +0900 Subject: [PATCH] fix(pubsub): fix defer call in for loop (#11175) Signed-off-by: Koichi Shiraishi Co-authored-by: Alex Hong <9397363+hongalex@users.noreply.github.com> --- pubsub/topic.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pubsub/topic.go b/pubsub/topic.go index 72d9a3459035..eb46c318282d 100644 --- a/pubsub/topic.go +++ b/pubsub/topic.go @@ -1086,11 +1086,15 @@ func (t *Topic) initBundler() { for _, m := range bmsgs { m.batcherSpan.End() m.createSpan.AddEvent(eventPublishStart, trace.WithAttributes(semconv.MessagingBatchMessageCount(len(bmsgs)))) - defer m.createSpan.End() - defer m.createSpan.AddEvent(eventPublishEnd) } } t.publishMessageBundle(ctx, bmsgs) + if t.enableTracing { + for _, m := range bmsgs { + m.createSpan.AddEvent(eventPublishEnd) + m.createSpan.End() + } + } }) t.scheduler.DelayThreshold = t.PublishSettings.DelayThreshold t.scheduler.BundleCountThreshold = t.PublishSettings.CountThreshold