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

perf: small perf improvements in OTel API #2842

Merged
merged 3 commits into from
Mar 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions opentelemetry/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,9 +482,10 @@ impl PartialEq for InstrumentationScope {
self.name == other.name
&& self.version == other.version
&& self.schema_url == other.schema_url
&& self.attributes.len() == other.attributes.len()
&& {
let mut self_attrs = self.attributes.clone();
let mut other_attrs = other.attributes.clone();
let mut self_attrs = Vec::from_iter(&self.attributes);
let mut other_attrs = Vec::from_iter(&other.attributes);
self_attrs.sort_unstable_by(|a, b| a.key.cmp(&b.key));
other_attrs.sort_unstable_by(|a, b| a.key.cmp(&b.key));
self_attrs == other_attrs
Expand All @@ -499,7 +500,7 @@ impl hash::Hash for InstrumentationScope {
self.name.hash(state);
self.version.hash(state);
self.schema_url.hash(state);
let mut sorted_attrs = self.attributes.clone();
let mut sorted_attrs = Vec::from_iter(&self.attributes);
sorted_attrs.sort_unstable_by(|a, b| a.key.cmp(&b.key));
for attribute in sorted_attrs {
attribute.hash(state);
Expand Down
4 changes: 1 addition & 3 deletions opentelemetry/src/propagation/composite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ impl TextMapCompositePropagator {
pub fn new(propagators: Vec<Box<dyn TextMapPropagator + Send + Sync>>) -> Self {
let mut fields = HashSet::new();
for propagator in &propagators {
for field in propagator.fields() {
fields.insert(field.to_string());
}
fields.extend(propagator.fields().map(ToString::to_string));
}

TextMapCompositePropagator {
Expand Down
8 changes: 4 additions & 4 deletions opentelemetry/src/trace/span_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ impl TraceState {
return Err(TraceStateError::Value(value));
}

let mut trace_state = self.delete_from_deque(key.clone());
let mut trace_state = self.delete_from_deque(&key);
let kvs = trace_state.0.get_or_insert(VecDeque::with_capacity(1));

kvs.push_front((key, value));
Expand All @@ -155,14 +155,14 @@ impl TraceState {
return Err(TraceStateError::Key(key));
}

Ok(self.delete_from_deque(key))
Ok(self.delete_from_deque(&key))
}

/// Delete key from trace state's deque. The key MUST be valid
fn delete_from_deque(&self, key: String) -> TraceState {
fn delete_from_deque(&self, key: &str) -> TraceState {
let mut owned = self.clone();
if let Some(kvs) = owned.0.as_mut() {
if let Some(index) = kvs.iter().position(|x| *x.0 == *key) {
if let Some(index) = kvs.iter().position(|x| x.0 == key) {
kvs.remove(index);
}
}
Expand Down