Opentelemetry-java: SpanWrapper (SpanData) does not snapshot the value of hasEnded.

Created on 29 Jul 2020  路  6Comments  路  Source: open-telemetry/opentelemetry-java

Describe the bug
io.opentelemetry.sdk.trace.SpanWrapper does not store the value of hasEnded, updates to the originial Span will be inadvertedly reflected in the SpanData.

Steps to reproduce

SpanData sd = someSpan.toSpanData();
assertThat(sd.hasEnded()).isFalse();
someSpan.end();
assertThat(sd.hasEnded()).isFalse(); // Fails!

What did you expect to see?
No assertion failure -- SpanData should be immutable.

What did you see instead?
Assertion failure -- SpanData was modified.

What version and what artifacts are you using?
Master @ 8005c7eddd456b91023c661e8e9a9e37f641c9bb

Additional context
This can cause trouble when working with un-ended spans and multiple threads.

Bug p3 required-for-ga

All 6 comments

Haha 馃憤 I would like to close this as "working as intended" :)

SpanData is an immutable snapshot of the current Span, all data recorded after that will not reflect in SpanData.

This can cause trouble when working with un-ended spans and multiple threads.

Indeed the main reason to not support this.

@bogdandrutu I think the original report was exactly that SpanData is NOT immutable right now.

Yes, maybe "preserve" was not the best word choice. It inadvertedly reflects changing hasEnded in the Span.

After reading the code, it seems that name and endTimestamp are also read from the span instead of being part of the snapshot. Also, I couldn't find any unit tests that would guard against changes to any span property being reflected in the SpanData at all (not even for properties where it should work).

I will prepare a PR.

SpanData is an immutable snapshot of the current Span

Oh my, I totally oversaw the fact this is against SpanData directly, not Span returning an outdated SpanData ;) So yes, this is not an actual bug.

I think it is a bug. The @Immutable annotation on SpanData/SpanWrapper is violated. EDIT: It's also a regression, because previous versions did snapshot these values.

Was this page helpful?
0 / 5 - 0 ratings