Skip to content

Add getAttribute to ReadableSpan#3458

Merged
anuraaga merged 4 commits intoopen-telemetry:mainfrom
trask:add-get-attribute-to-readable-span
Aug 14, 2021
Merged

Add getAttribute to ReadableSpan#3458
anuraaga merged 4 commits intoopen-telemetry:mainfrom
trask:add-get-attribute-to-readable-span

Conversation

@trask
Copy link
Copy Markdown
Member

@trask trask commented Aug 9, 2021

Resolves #3456


@Override
@Nullable
public <T> T getAttribute(AttributeKey<T> key) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Except for hasEnded (write-once) all other getters are for read-only fields. From a theoretical perspective, I would prefer not to have this getter, if we can find another solution to the original problem on the issue.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this is in the SDK and not API, I don't see a problem with adding these accessors if there's a use case. We actually have the toSpanData issue in zpages too just to getStatus.

https://github.com/open-telemetry/opentelemetry-java/blob/main/sdk-extensions/zpages/src/main/java/io/opentelemetry/sdk/extension/zpages/TracezSpanBuckets.java#L33

Here the UX does seem significantly better for keeping attributes consistent within a trace without having to use more concepts such as Baggage.

@codecov
Copy link
Copy Markdown

codecov bot commented Aug 13, 2021

Codecov Report

Merging #3458 (d8b3843) into main (012cf54) will decrease coverage by 0.01%.
The diff coverage is 50.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##               main    #3458      +/-   ##
============================================
- Coverage     90.66%   90.65%   -0.02%     
- Complexity     3237     3238       +1     
============================================
  Files           360      360              
  Lines          9978     9980       +2     
  Branches       1011     1012       +1     
============================================
  Hits           9047     9047              
  Misses          620      620              
- Partials        311      313       +2     
Impacted Files Coverage Δ
...ntelemetry/sdk/trace/RecordEventsReadableSpan.java 98.52% <50.00%> (-0.49%) ⬇️
...telemetry/sdk/trace/export/BatchSpanProcessor.java 89.20% <0.00%> (-0.72%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 012cf54...d8b3843. Read the comment docs.


@Override
@Nullable
public <T> T getAttribute(AttributeKey<T> key) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this is in the SDK and not API, I don't see a problem with adding these accessors if there's a use case. We actually have the toSpanData issue in zpages too just to getStatus.

https://github.com/open-telemetry/opentelemetry-java/blob/main/sdk-extensions/zpages/src/main/java/io/opentelemetry/sdk/extension/zpages/TracezSpanBuckets.java#L33

Here the UX does seem significantly better for keeping attributes consistent within a trace without having to use more concepts such as Baggage.

*/
SpanKind getKind();

/** Returns the value for the given {@link AttributeKey}, or {@code null} if not found. */
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's worth a note here about the fact that this call does require some locking, and that subsequent calls may result in different results, due to the inherent mutability of the underlying object.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you want me to add that same note for hasEnded(), getName(), and getLatencyNanos() also?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's actually probably a good idea, yes, if you don't mind.

Copy link
Copy Markdown
Contributor

@jkwatson jkwatson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm ok with this, as long as we add some documentation about the performance implications of using it.

@anuraaga anuraaga merged commit 651df06 into open-telemetry:main Aug 14, 2021
This was referenced Dec 19, 2021
@trask trask deleted the add-get-attribute-to-readable-span branch March 5, 2022 19:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

How to stamp a "tenant id" attribute on all spans?

4 participants