Skip to content
Draft
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
10 changes: 10 additions & 0 deletions relay-event-normalization/src/eap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ pub fn normalize_attribute_types(attributes: &mut Annotated<Attributes>) {
(Annotated(Some(Double), _), Annotated(Some(Value::U64(_)), _)) => (),
(Annotated(Some(Double), _), Annotated(Some(Value::F64(_)), _)) => (),
(Annotated(Some(String), _), Annotated(Some(Value::String(_)), _)) => (),
(Annotated(Some(Array), _), Annotated(Some(Value::Array(arr)), _)) => {
// TODO: implement this check
let is_supported_array = arr.iter().all(|v| v.value().is_some());

if !is_supported_array {
let original = attribute.value_mut().take();
attribute.meta_mut().add_error(ErrorKind::InvalidData);
attribute.meta_mut().set_original_value(original);
}
}
// Note: currently the mapping to Kafka requires that invalid or unknown combinations
// of types and values are removed from the mapping.
//
Expand Down
21 changes: 21 additions & 0 deletions relay-event-schema/src/protocol/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,29 @@ pub fn attribute_pii_from_conventions(state: &ProcessingState) -> Pii {

#[derive(Debug, Clone, PartialEq, Eq)]
pub enum AttributeType {
/// A boolean type.
Copy link
Contributor

Choose a reason for hiding this comment

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

I would remove the "type" from all of these.

Suggested change
/// A boolean type.
/// A boolean.

///
/// The respective value must be of type [`Value::Bool`].
Boolean,
/// A integer type.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// A integer type.
/// An integer type.

///
/// The respective value must be of type [`Value::I64`] or [`Value::U64`].
Integer,
/// A floating point/double type.
///
/// The respective value must be of type [`Value::F64`].
Double,
/// A string type.
///
/// The respective value must be of type [`Value::String`].
String,
/// A string type.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// A string type.
/// An array type.

///
/// The respective value must be of type [`Value::Array`].
Array,
/// An unknown type.
///
/// Kept for forward compatibility.
Unknown(String),
}

Expand All @@ -136,6 +155,7 @@ impl AttributeType {
Self::Integer => "integer",
Self::Double => "double",
Self::String => "string",
Self::Array => "array",
Self::Unknown(value) => value,
}
}
Expand All @@ -158,6 +178,7 @@ impl From<String> for AttributeType {
"integer" => Self::Integer,
"double" => Self::Double,
"string" => Self::String,
"array" => Self::Array,
_ => Self::Unknown(value),
}
}
Expand Down
1 change: 1 addition & 0 deletions relay-otel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pub fn otel_value_to_attribute(otel_value: OtelValue) -> Option<Attribute> {
})
.collect();

// TODO: convert to array here to support arrays for otlp
let json = serde_json::to_string(&safe_values).ok()?;
(AttributeType::String, Value::String(json))
}
Expand Down
20 changes: 18 additions & 2 deletions relay-server/src/processing/logs/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use prost_types::Timestamp;
use relay_event_schema::protocol::{Attributes, OurLog, OurLogLevel, SpanId};
use relay_protocol::{Annotated, IntoValue, Value};
use relay_quotas::Scoping;
use sentry_protos::snuba::v1::{AnyValue, TraceItem, TraceItemType, any_value};
use sentry_protos::snuba::v1::{AnyValue, ArrayValue, TraceItem, TraceItemType, any_value};
use uuid::Uuid;

use crate::envelope::WithHeader;
Expand Down Expand Up @@ -140,15 +140,31 @@ fn attributes(
continue;
};

// TODO: share this code with all EAP items
let Some(value) = (match value {
Value::Bool(v) => Some(any_value::Value::BoolValue(v)),
Value::I64(v) => Some(any_value::Value::IntValue(v)),
Value::U64(v) => i64::try_from(v).ok().map(any_value::Value::IntValue),
Value::F64(v) => Some(any_value::Value::DoubleValue(v)),
Value::String(v) => Some(any_value::Value::StringValue(v)),
Value::Array(v) => Some(any_value::Value::ArrayValue(ArrayValue {
values: v
.into_iter()
.filter_map(|v| v.into_value())
.map(|v| match v {
Value::Bool(v) => any_value::Value::BoolValue(v),
Value::I64(v) => any_value::Value::IntValue(v),
Value::U64(v) => any_value::Value::IntValue(v as i64),
Value::F64(v) => any_value::Value::DoubleValue(v),
Value::String(v) => any_value::Value::StringValue(v),
Value::Array(_) | Value::Object(_) => todo!(),
})
.map(|v| AnyValue { value: Some(v) })
.collect(),
})),
// These cases do not happen, as they are not valid attributes
// and they should have been filtered out before already.
Value::Array(_) | Value::Object(_) => {
Value::Object(_) => {
debug_assert!(false, "unsupported log value");
None
}
Expand Down
Loading