Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow O(1) get operations for SpanBuilder::attributes [breaking] #799

Conversation

LukeMathWalker
Copy link
Contributor

@LukeMathWalker LukeMathWalker commented May 17, 2022

Closes #794

It changes the type of SpanBuilder::attributes from Vec<KeyValue> to OrderMap. OrderMap is a thin wrapper around index_map::IndexMap that only exposes the methods that preserve the original insertion order, which is what we care about later in the pipeline when enforcing the maximum number of attributes per span.

@codecov
Copy link

codecov bot commented May 17, 2022

Codecov Report

Merging #799 (e39fdd4) into main (7534891) will increase coverage by 0.0%.
The diff coverage is 65.2%.

@@          Coverage Diff          @@
##            main    #799   +/-   ##
=====================================
  Coverage   69.7%   69.8%           
=====================================
  Files        109     110    +1     
  Lines       9045    9060   +15     
=====================================
+ Hits        6313    6324   +11     
- Misses      2732    2736    +4     
Impacted Files Coverage Δ
opentelemetry-api/src/trace/mod.rs 72.0% <ø> (ø)
opentelemetry-api/src/trace/tracer.rs 61.3% <50.0%> (ø)
opentelemetry-sdk/src/trace/tracer.rs 90.6% <60.0%> (-0.1%) ⬇️
opentelemetry-api/src/trace/order_map.rs 64.2% <64.2%> (ø)
opentelemetry-sdk/src/trace/sampler.rs 97.4% <100.0%> (+<0.1%) ⬆️
opentelemetry-sdk/src/metrics/controllers/push.rs 83.3% <0.0%> (+3.3%) ⬆️

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 7534891...e39fdd4. Read the comment docs.

@LukeMathWalker LukeMathWalker changed the title Allow O(1) get operations for SpanBuilder::attributes Allow O(1) get operations for SpanBuilder::attributes [breaking] May 17, 2022
@LukeMathWalker LukeMathWalker marked this pull request as ready for review May 18, 2022 07:42
@LukeMathWalker LukeMathWalker requested a review from a team May 18, 2022 07:42
@TommyCpp
Copy link
Contributor

TommyCpp commented May 19, 2022

👍 Nice work. Just one request

@LukeMathWalker
Copy link
Contributor Author

I've addressed it in an additional commit 👍🏻
That code example now compiles without having to be touched at all.

Copy link
Contributor

@TommyCpp TommyCpp left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks a lot. This is a great improvement 🎉

@TommyCpp TommyCpp merged commit a767fd3 into open-telemetry:main May 21, 2022
@jtescher
Copy link
Member

@LukeMathWalker @TommyCpp Uping MSRV to 1.55 will likely break compatibility with tracing's 1.49 MSRV for tracing-opentelemtry. What's the motivation for optimizing attribute get operations?

@TommyCpp
Copy link
Contributor

@LukeMathWalker @TommyCpp Uping MSRV to 1.55 will likely break compatibility with tracing's 1.49 MSRV for tracing-opentelemtry. What's the motivation for optimizing attribute get operations?

#794 has the full discussion but on the high level, lib writers wants to manipulate the attributes attached on spans and current implementation only supports do it by iterate through the attributes array, which is O(N)

On top of that we need to preserve the relative order the insertion so that the when number of the attributes exceed the limits we can trim the last attributes.

Combine the requirements we somehow want a OrderMap. indexmap provided that function. It's not a must have as we can just implement the same function on our own.

We can try to pin the version of indexmap to an older version to avoid a MSRV bump. I think tower depends on indexmap 1.0?

There are other places in the PR uses features stabilized after 1.49 but we can probably remove them.

@jtescher
Copy link
Member

#794 has the full discussion but on the high level, lib writers wants to manipulate the attributes attached on spans and current implementation only supports do it by iterate through the attributes array, which is O(N)

I see. The spec has some similar issues open, could be worth documenting the relationship between OrderMap and EvictedHashMap, or consider merging the concepts and exposing in API crate if necessary.

Also worth considering the configuration options for other structs besides Span that currently take a Vec<KeyValue> (e.g. Event, Link) as there is now some inconsistency in how attributes are passed.

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.

API design: SpanBuilder::attributes
3 participants