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

fix(pii): Fix issue where $span would not be recognized in Advanced Data Scrubbing #781

Merged
merged 6 commits into from
Sep 21, 2020
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

**Bug Fixes**:

- Fix issue where `$span` would not be recognized in Advanced Data Scrubbing. ([#781](https://github.com/getsentry/relay/pull/781))

## 20.9.0

**Features**:
Expand Down
1 change: 1 addition & 0 deletions py/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

- Fix issue where `$span` would not be recognized in Advanced Data Scrubbing. ([#781](https://github.com/getsentry/relay/pull/781))
- Require macOS 10.15.0 or newer for the macOS wheel after moving to GitHub Actions. ([#780](https://github.com/getsentry/relay/pull/780))

## 0.7.0
Expand Down
53 changes: 53 additions & 0 deletions relay-general/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,56 @@ macro_rules! impl_str_serde {
impl_str_de!($type);
};
}

/// Implements FromStr and Display on a flat/C-like enum such that strings roundtrip correctly and
/// all variants can be FromStr'd.
///
///
/// Usage:
///
/// ```rust
/// // derive fail for this or whatever you need. The type must be ZST though.
/// struct ValueTypeError;
///
/// enum ValueType {
/// Foo,
/// Bar,
/// }
///
/// derive_fromstr_and_display!(ValueType, ValueTypeError, {
/// ValueType::Foo => "foo" | "foo2", // fromstr will recognize foo/foo2, display will use foo.
/// ValueType::Bar => "bar",
/// });
/// ```
macro_rules! derive_fromstr_and_display {
($type:ty, $error_type:tt, { $($variant:path => $($name:literal)|*),+ $(,)? }) => {
impl $type {
pub fn as_str(&self) -> &'static str {
match *self {
$(
$variant => ($($name, )*).0
),*
}
}
}

impl ::std::fmt::Display for $type {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
write!(f, "{}", self.as_str())
}
}

impl ::std::str::FromStr for $type {
type Err = $error_type;

fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(match s {
$(
$($name)|* => $variant,
)*
_ => return Err($error_type)
})
}
}
}
}
91 changes: 25 additions & 66 deletions relay-general/src/processor/attrs.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::borrow::Cow;
use std::fmt;
use std::str::FromStr;

use failure::Fail;
use smallvec::SmallVec;
Expand Down Expand Up @@ -52,73 +51,33 @@ impl ValueType {
pub fn for_field<T: ProcessValue>(field: &Annotated<T>) -> Option<Self> {
field.value().and_then(ProcessValue::value_type)
}

pub fn name(self) -> &'static str {
match self {
ValueType::String => "string",
ValueType::Binary => "binary",
ValueType::Number => "number",
ValueType::Boolean => "boolean",
ValueType::DateTime => "datetime",
ValueType::Array => "array",
ValueType::Object => "object",
ValueType::Event => "event",
ValueType::Attachments => "attachments",
ValueType::Exception => "error",
ValueType::Stacktrace => "stack",
ValueType::Frame => "frame",
ValueType::Request => "http",
ValueType::User => "user",
ValueType::LogEntry => "logentry",
ValueType::Message => "message",
ValueType::Thread => "thread",
ValueType::Breadcrumb => "breadcrumb",
ValueType::Span => "span",
ValueType::ClientSdkInfo => "sdk",
ValueType::Minidump => "minidump",
ValueType::HeapMemory => "heap_memory",
ValueType::StackMemory => "stack_memory",
}
}
}

impl fmt::Display for ValueType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.name())
}
}

impl FromStr for ValueType {
type Err = UnknownValueTypeError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(match s {
"string" => ValueType::String,
"binary" => ValueType::Binary,
"number" => ValueType::Number,
"bool" | "boolean" => ValueType::Boolean,
"datetime" => ValueType::DateTime,
"array" | "list" => ValueType::Array,
"object" => ValueType::Object,
"event" => ValueType::Event,
"attachments" => ValueType::Attachments,
"exception" | "error" => ValueType::Exception,
"stacktrace" | "stack" => ValueType::Stacktrace,
"frame" => ValueType::Frame,
"request" | "http" => ValueType::Request,
"user" => ValueType::User,
"logentry" => ValueType::LogEntry,
"message" => ValueType::Message,
"thread" => ValueType::Thread,
"breadcrumb" => ValueType::Breadcrumb,
"sdk" => ValueType::ClientSdkInfo,
"minidump" => ValueType::Minidump,
"heap_memory" => ValueType::HeapMemory,
"stack_memory" => ValueType::StackMemory,
_ => return Err(UnknownValueTypeError),
})
}
}
derive_fromstr_and_display!(ValueType, UnknownValueTypeError, {
ValueType::String => "string",
ValueType::Binary => "binary",
ValueType::Number => "number",
ValueType::Boolean => "boolean" | "bool",
ValueType::DateTime => "datetime",
ValueType::Array => "array" | "list",
ValueType::Object => "object",
ValueType::Event => "event",
ValueType::Attachments => "attachments",
ValueType::Exception => "error" | "exception",
ValueType::Stacktrace => "stack" | "stacktrace",
ValueType::Frame => "frame",
ValueType::Request => "http" | "request",
ValueType::User => "user",
ValueType::LogEntry => "logentry",
ValueType::Message => "message",
ValueType::Thread => "thread",
ValueType::Breadcrumb => "breadcrumb",
ValueType::Span => "span",
ValueType::ClientSdkInfo => "sdk",
ValueType::Minidump => "minidump",
ValueType::HeapMemory => "heap_memory",
ValueType::StackMemory => "stack_memory",
});

/// The maximum length of a field.
#[derive(Debug, Clone, Copy, PartialEq, Hash)]
Expand Down
Loading