fix(pubsub): fix defer call in for loop - #11175
Conversation
|
/cc @hongalex |
26bbf75 to
cf474ab
Compare
bc6f17c to
70dd1ef
Compare
|
@hongalex gentle ping |
70dd1ef to
4aea6cf
Compare
|
Apologies for missing this the first time around. Could you explain in more detail why this is necessary? Calling |
|
@hongalex Example playground is here: https://go.dev/play/p/tM6Gt11reCo I thought you assumed |
|
Yeah I definitely overlooked the order of when the message spans are ended when using defer. In my mind, it's not a super pressing bug since the events are batched anyway on the exporter so the timing is fairly tight, but it would be nice to get correct. If that's the case, I would prefer iterating over t.publishMessageBundle(ctx, bmsgs)
if t.enableTracing {
for i, m := range bmsgs {
m.createSpan.End()
m.createSpan.AddEvent(eventPublishEnd)
}
} |
|
@hongalex I agreed your opinion. But just for confirm, you means calling t.publishMessageBundle(ctx, bmsgs)
if t.enableTracing {
for _, m := range bmsgs {
m.createSpan.AddEvent(eventPublishEnd)
m.createSpan.End()
}
}Edit: changed and pushed. PTAL. |
Signed-off-by: Koichi Shiraishi <zchee.io@gmail.com>
4aea6cf to
378fa2b
Compare
Sorry, no I didn't. I copy and pasted the order from the defer side (because the opposite order is correct) but in this case we should be calling AddEvent and then End. |
SSIA. Avoid the
deferfunction call in for loop.