Skip to content

Commit d626c2a

Browse files
authored
ref: Remove some methods from Attributes (#5312)
1 parent 0fec946 commit d626c2a

File tree

7 files changed

+18
-64
lines changed

7 files changed

+18
-64
lines changed

relay-event-normalization/src/eap/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub fn normalize_attribute_types(attributes: &mut Annotated<Attributes>) {
2525
return;
2626
};
2727

28-
let attributes = attributes.iter_mut().map(|(_, attr)| attr);
28+
let attributes = attributes.0.values_mut();
2929
for attribute in attributes {
3030
use AttributeType::*;
3131

@@ -185,7 +185,7 @@ fn normalize_attribute_names_inner(
185185
return;
186186
};
187187

188-
let attribute_names: Vec<_> = attributes.keys().cloned().collect();
188+
let attribute_names: Vec<_> = attributes.0.keys().cloned().collect();
189189

190190
for name in attribute_names {
191191
let Some(attribute_info) = attribute_info(&name) else {
@@ -195,7 +195,7 @@ fn normalize_attribute_names_inner(
195195
match attribute_info.write_behavior {
196196
WriteBehavior::CurrentName => continue,
197197
WriteBehavior::NewName(new_name) => {
198-
let Some(old_attribute) = attributes.get_raw_mut(&name) else {
198+
let Some(old_attribute) = attributes.0.get_mut(&name) else {
199199
continue;
200200
};
201201

@@ -205,14 +205,14 @@ fn normalize_attribute_names_inner(
205205
let new_attribute = std::mem::replace(old_attribute, Annotated(None, meta));
206206

207207
if !attributes.contains_key(new_name) {
208-
attributes.insert_raw(new_name.to_owned(), new_attribute);
208+
attributes.0.insert(new_name.to_owned(), new_attribute);
209209
}
210210
}
211211
WriteBehavior::BothNames(new_name) => {
212212
if !attributes.contains_key(new_name)
213-
&& let Some(current_attribute) = attributes.get_raw(&name).cloned()
213+
&& let Some(current_attribute) = attributes.0.get(&name).cloned()
214214
{
215-
attributes.insert_raw(new_name.to_owned(), current_attribute);
215+
attributes.0.insert(new_name.to_owned(), current_attribute);
216216
}
217217
}
218218
}

relay-event-schema/src/protocol/attributes.rs

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -236,32 +236,14 @@ impl Attributes {
236236
Some(&self.0.get(key)?.value()?.value.value)
237237
}
238238

239-
/// Returns the annotated attribute with the given key.
240-
pub fn get_raw<Q>(&self, key: &Q) -> Option<&Annotated<Attribute>>
241-
where
242-
String: Borrow<Q>,
243-
Q: Ord + ?Sized,
244-
{
245-
self.0.get(key)
246-
}
247-
248-
/// Mutably returns the annotated attribute with the given key.
249-
pub fn get_raw_mut<Q>(&mut self, key: &Q) -> Option<&mut Annotated<Attribute>>
250-
where
251-
String: Borrow<Q>,
252-
Q: Ord + ?Sized,
253-
{
254-
self.0.get_mut(key)
255-
}
256-
257239
/// Inserts an attribute with the given value into this collection.
258240
pub fn insert<K: Into<String>, V: Into<AttributeValue>>(&mut self, key: K, value: V) {
259241
fn inner(slf: &mut Attributes, key: String, value: AttributeValue) {
260242
let attribute = Annotated::new(Attribute {
261243
value,
262244
other: Default::default(),
263245
});
264-
slf.insert_raw(key, attribute);
246+
slf.0.insert(key, attribute);
265247
}
266248
let value = value.into();
267249
if !value.value.is_empty() {
@@ -280,11 +262,6 @@ impl Attributes {
280262
}
281263
}
282264

283-
/// Inserts an annotated attribute into this collection.
284-
pub fn insert_raw(&mut self, key: String, attribute: Annotated<Attribute>) {
285-
self.0.insert(key, attribute);
286-
}
287-
288265
/// Checks whether this collection contains an attribute with the given key.
289266
pub fn contains_key<Q>(&self, key: &Q) -> bool
290267
where
@@ -302,31 +279,6 @@ impl Attributes {
302279
{
303280
self.0.remove(key)
304281
}
305-
306-
/// Iterates over this collection's attribute keys and values.
307-
pub fn iter(&self) -> std::collections::btree_map::Iter<'_, String, Annotated<Attribute>> {
308-
self.0.iter()
309-
}
310-
311-
/// Iterates mutably over this collection's attribute keys and values.
312-
pub fn iter_mut(
313-
&mut self,
314-
) -> std::collections::btree_map::IterMut<'_, String, Annotated<Attribute>> {
315-
self.0.iter_mut()
316-
}
317-
318-
/// Returns an iterator over the keys in this collection.
319-
pub fn keys(&self) -> std::collections::btree_map::Keys<'_, String, Annotated<Attribute>> {
320-
self.0.keys()
321-
}
322-
323-
/// Provides mutable access to an entry in this collection.
324-
pub fn entry(
325-
&mut self,
326-
key: String,
327-
) -> std::collections::btree_map::Entry<'_, String, Annotated<Attribute>> {
328-
self.0.entry(key)
329-
}
330282
}
331283

332284
impl IntoIterator for Attributes {

relay-otel/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ pub fn otel_scope_into_attributes(
107107
.and_then(otel_value_to_attribute)
108108
{
109109
let key = format!("resource.{}", attribute.key);
110-
attributes.insert_raw(key, Annotated::new(attr));
110+
attributes.0.insert(key, Annotated::new(attr));
111111
}
112112
}
113113

@@ -119,7 +119,7 @@ pub fn otel_scope_into_attributes(
119119
.and_then(otel_value_to_attribute)
120120
{
121121
let key = format!("instrumentation.{}", attribute.key);
122-
attributes.insert_raw(key, Annotated::new(attr));
122+
attributes.0.insert(key, Annotated::new(attr));
123123
}
124124
}
125125

relay-ourlogs/src/otel_to_sentry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub fn otel_to_sentry_log(
8585
.and_then(|v| v.value)
8686
.and_then(otel_value_to_attribute)
8787
{
88-
attribute_data.insert_raw(attribute.key, Annotated::new(attr));
88+
attribute_data.0.insert(attribute.key, Annotated::new(attr));
8989
}
9090
}
9191

relay-server/src/processing/logs/store.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,11 +284,11 @@ mod tests {
284284
.add_error(MetaError::expected("something in the body"));
285285

286286
let attributes = get_mut!(log.attributes);
287-
attributes.insert_raw(
287+
attributes.0.insert(
288288
"attr_meta".to_owned(),
289289
Annotated(None, Meta::from_error(MetaError::expected("meow"))),
290290
);
291-
attributes.insert_raw(
291+
attributes.0.insert(
292292
"value_meta".to_owned(),
293293
Annotated::new(Attribute {
294294
value: AttributeValue {

relay-spans/src/otel_to_sentry_v2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ pub fn otel_to_sentry_span(
8888
}
8989

9090
if let Some(v) = otel_value_to_attribute(value) {
91-
sentry_attributes.insert_raw(key, Annotated::new(v));
91+
sentry_attributes.0.insert(key, Annotated::new(v));
9292
}
9393
}
9494

relay-spans/src/v1_to_v2.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ pub fn span_v1_to_span_v2(span_v1: SpanV1) -> SpanV2 {
7878
if let Some(tags) = tags.into_value() {
7979
for (key, value) in tags {
8080
if !attributes.contains_key(&key) {
81-
attributes.insert_raw(
81+
attributes.0.insert(
8282
key,
8383
value
8484
.map_value(|JsonLenientString(s)| AttributeValue::from(s))
8585
.and_then(Attribute::from),
86-
)
86+
);
8787
}
8888
}
8989
}
@@ -96,7 +96,9 @@ pub fn span_v1_to_span_v2(span_v1: SpanV1) -> SpanV2 {
9696
other => Cow::Owned(format!("sentry.{}", other)),
9797
};
9898
if !value.is_empty() && !attributes.contains_key(key.as_ref()) {
99-
attributes.insert_raw(key.into_owned(), attribute_from_value(value));
99+
attributes
100+
.0
101+
.insert(key.into_owned(), attribute_from_value(value));
100102
}
101103
}
102104
}

0 commit comments

Comments
 (0)