Skip to content

Commit

Permalink
Revert "feat(process-value): Add object level trimming" (#3889)
Browse files Browse the repository at this point in the history
This seems to not have solved the problem and introduced new failures.

Reverts #3877
  • Loading branch information
jjbayer authored Aug 2, 2024
1 parent e6b967a commit b399af5
Show file tree
Hide file tree
Showing 5 changed files with 178 additions and 107 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

- Add experimental support for V2 envelope buffering. ([#3855](https://github.com/getsentry/relay/pull/3855), [#3863](https://github.com/getsentry/relay/pull/3863))
- Add `client_sample_rate` to spans, pulled from the trace context. ([#3872](https://github.com/getsentry/relay/pull/3872))
- Introduce `trim = "disabled"` type attribute to prevent trimming of spans. ([#3877](https://github.com/getsentry/relay/pull/3877))

## 24.7.1

Expand Down
68 changes: 14 additions & 54 deletions relay-event-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

use proc_macro2::{Span, TokenStream};
use quote::{quote, ToTokens};
use std::str::FromStr;
use syn::{Ident, Lit, Meta, NestedMeta};
use synstructure::decl_derive;

Expand Down Expand Up @@ -91,8 +90,7 @@ fn derive_process_value(mut s: synstructure::Structure<'_>) -> TokenStream {

let mut body = TokenStream::new();
for (index, bi) in variant.bindings().iter().enumerate() {
let mut field_attrs = parse_field_attributes(index, bi.ast(), &mut is_tuple_struct);
field_attrs.trim = Some(matches!(type_attrs.trim, TrimmingMode::Enabled));
let field_attrs = parse_field_attributes(index, bi.ast(), &mut is_tuple_struct);
let ident = &bi.binding;
let field_attrs_name = Ident::new(&format!("FIELD_ATTRS_{index}"), Span::call_site());
let field_name = field_attrs.field_name.clone();
Expand Down Expand Up @@ -171,14 +169,6 @@ fn derive_process_value(mut s: synstructure::Structure<'_>) -> TokenStream {
}
});

// In case we have `trim` set on the type, we want to override this field attribute
// manually.
let field_attrs = FieldAttrs {
trim: Some(matches!(type_attrs.trim, TrimmingMode::Enabled)),
..Default::default()
};
let field_attrs_tokens = field_attrs.as_tokens(Some(quote!(parent_attrs)));

s.gen_impl(quote! {
#[automatically_derived]
gen impl crate::processor::ProcessValue for @Self {
Expand All @@ -197,13 +187,6 @@ fn derive_process_value(mut s: synstructure::Structure<'_>) -> TokenStream {
where
P: crate::processor::Processor,
{
let parent_attrs = __state.attrs();
let attrs = #field_attrs_tokens;

let __state = &__state.enter_nothing(
Some(::std::borrow::Cow::Owned(attrs))
);

#process_func_call_tokens;
match *self {
#process_value_arms
Expand Down Expand Up @@ -231,32 +214,10 @@ fn derive_process_value(mut s: synstructure::Structure<'_>) -> TokenStream {
})
}

#[derive(Default, Copy, Clone)]
enum TrimmingMode {
#[default]
Enabled,
Disabled,
}

impl FromStr for TrimmingMode {
type Err = ();

fn from_str(s: &str) -> Result<Self, Self::Err> {
let trimming_mode = match s {
"enabled" => TrimmingMode::Enabled,
"disabled" => TrimmingMode::Disabled,
_ => return Err(()),
};

Ok(trimming_mode)
}
}

#[derive(Default)]
struct TypeAttrs {
process_func: Option<String>,
value_type: Vec<String>,
trim: TrimmingMode,
}

impl TypeAttrs {
Expand Down Expand Up @@ -315,19 +276,7 @@ fn parse_type_attributes(s: &synstructure::Structure<'_>) -> TypeAttrs {
rv.value_type.push(litstr.value());
}
_ => {
panic!("Got non string literal for value_type");
}
}
} else if ident == "trim" {
match name_value.lit {
Lit::Str(litstr) => {
rv.trim = litstr
.value()
.parse()
.expect("Got invalid value for trim")
}
_ => {
panic!("Got invalid value for trim");
panic!("Got non string literal for value type");
}
}
}
Expand Down Expand Up @@ -481,7 +430,7 @@ impl FieldAttrs {
max_bytes: #max_bytes,
pii: #pii,
retain: #retain,
trim: #trim
trim: #trim,
}
})
}
Expand Down Expand Up @@ -656,6 +605,17 @@ fn parse_field_attributes(
panic!("Got non string literal for retain");
}
}
} else if ident == "trim" {
match name_value.lit {
Lit::Str(litstr) => match litstr.value().as_str() {
"true" => rv.trim = None,
"false" => rv.trim = Some(false),
other => panic!("Unknown value {other}"),
},
_ => {
panic!("Got non string literal for trim");
}
}
} else if ident == "legacy_alias" || ident == "skip_serialization" {
// Skip
} else {
Expand Down
Loading

0 comments on commit b399af5

Please sign in to comment.