Skip to content
Closed
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
14 changes: 13 additions & 1 deletion relay-event-schema/src/protocol/attributes.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use relay_protocol::{Annotated, Empty, FromValue, IntoValue, Object, SkipSerialization, Value};
use relay_protocol::{
Annotated, DeepValue, Empty, FromValue, IntoValue, Object, SkipSerialization, Value,
};
use std::fmt;

use crate::processor::ProcessValue;
Expand Down Expand Up @@ -159,3 +161,13 @@ impl IntoValue for AttributeType {
serde::ser::Serialize::serialize(self.as_str(), s)
}
}

impl DeepValue for Attribute {
fn deep_value_ref(&self) -> Option<&Value> {
self.value.value.value()
}

fn deep_value(self) -> Option<Value> {
self.value.value.into_value()
}
}
11 changes: 11 additions & 0 deletions relay-protocol/src/annotated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::fmt;
use serde::ser::SerializeMap;
use serde::{Deserialize, Deserializer, Serialize, Serializer};

use crate::DeepValue;
use crate::meta::{Error, Meta};
use crate::traits::{Empty, FromValue, IntoValue, SkipSerialization};
use crate::value::{Map, Value};
Expand Down Expand Up @@ -412,3 +413,13 @@ impl<T> Default for Annotated<T> {
Annotated::empty()
}
}

impl<T: DeepValue> DeepValue for Annotated<T> {
fn deep_value_ref(&self) -> Option<&Value> {
self.value()?.deep_value_ref()
}

fn deep_value(self) -> Option<Value> {
self.into_value()?.deep_value()
}
}
8 changes: 8 additions & 0 deletions relay-protocol/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,11 @@ pub trait Getter {
None
}
}

/// Helper trait for retrieving `Value`s from deeply nested structures.
pub trait DeepValue {
/// Returns the contained `Value`.
fn deep_value(self) -> Option<Value>;
/// Returns a reference to the contained `Value`.
fn deep_value_ref(&self) -> Option<&Value>;
}
13 changes: 3 additions & 10 deletions relay-spans/src/v2_to_v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use relay_event_schema::protocol::{
EventId, Span as SpanV1, SpanData, SpanId, SpanLink, SpanStatus, SpanV2, SpanV2Kind,
SpanV2Status,
};
use relay_protocol::{Annotated, FromValue, Object, Value};
use relay_protocol::{Annotated, DeepValue, FromValue, Object, Value};

/// Transforms a Sentry span V2 to a Sentry span V1.
///
Expand Down Expand Up @@ -195,12 +195,7 @@ fn span_v2_link_to_span_v1_link(link: SpanV2Link) -> SpanLink {
let attributes = attributes.map_value(|attributes| {
attributes
.into_iter()
.map(|(key, attribute)| {
(
key,
attribute.and_then(|attribute| attribute.value.value.into_value()),
)
})
.map(|(key, attribute)| (key, attribute.and_then(|attr| attr.deep_value())))
.collect()
});
SpanLink {
Expand Down Expand Up @@ -258,9 +253,7 @@ fn derive_op_for_v2_span(span: &SpanV2) -> String {

if let Some(faas_trigger) = attributes
.get("faas.trigger")
.and_then(|faas_trigger| faas_trigger.value())
.and_then(|trigger_value| trigger_value.value.value.value())
.and_then(|v| v.as_str())
.and_then(|attr| attr.deep_value_ref()?.as_str())
{
return faas_trigger.to_owned();
}
Expand Down
Loading