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

Revert "feat(process-value): Add object level trimming" #3889

Merged
merged 1 commit into from
Aug 2, 2024
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
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
Loading