-
Notifications
You must be signed in to change notification settings - Fork 99
feat(protocol): Add transaction_info to events [INGEST-1427] #1330
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
85b3514
feat(protocol): Add transaction_source to events
jan-auer 47bde73
meta: Changelog
jan-auer 07ce622
ref: Fix JSON schema
jan-auer 564071e
ref: Remove fallback variant
jan-auer c34cc5a
Merge branch 'master' into feat/transaction-source
jan-auer 2c24a6f
feat(server): Log a metric for transaction sources
jan-auer dab1d3e
fix: Feature flagging
jan-auer fdc51c9
feat(server): More metric tags
jan-auer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
use std::fmt; | ||
use std::str::FromStr; | ||
|
||
use crate::processor::ProcessValue; | ||
use crate::types::{Annotated, Empty, ErrorKind, FromValue, IntoValue, SkipSerialization, Value}; | ||
|
||
/// Describes how the name of the transaction was determined. | ||
#[derive(Clone, Debug, Eq, PartialEq)] | ||
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))] | ||
#[cfg_attr(feature = "jsonschema", schemars(rename_all = "kebab-case"))] | ||
pub enum TransactionSource { | ||
/// User-defined name set through `set_transaction_name`. | ||
Custom, | ||
/// Raw URL, potentially containing identifiers. | ||
Url, | ||
/// Parametrized URL or route. | ||
Route, | ||
/// Name of the view handling the request. | ||
View, | ||
/// Named after a software component, such as a function or class name. | ||
Component, | ||
/// Name of a background task (e.g. a Celery task). | ||
Task, | ||
/// This is the default value set by Relay for legacy SDKs. | ||
Unknown, | ||
/// Any other unknown source that is not explicitly defined above. | ||
#[cfg_attr(feature = "jsonschema", schemars(skip))] | ||
Other(String), | ||
} | ||
|
||
impl FromStr for TransactionSource { | ||
type Err = std::convert::Infallible; | ||
|
||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
match s { | ||
"custom" => Ok(Self::Custom), | ||
"url" => Ok(Self::Url), | ||
"route" => Ok(Self::Route), | ||
"view" => Ok(Self::View), | ||
"component" => Ok(Self::Component), | ||
"task" => Ok(Self::Task), | ||
"unknown" => Ok(Self::Unknown), | ||
s => Ok(Self::Other(s.to_owned())), | ||
} | ||
} | ||
} | ||
|
||
impl fmt::Display for TransactionSource { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { | ||
Self::Custom => write!(f, "custom"), | ||
Self::Url => write!(f, "url"), | ||
Self::Route => write!(f, "route"), | ||
Self::View => write!(f, "view"), | ||
Self::Component => write!(f, "component"), | ||
Self::Task => write!(f, "task"), | ||
Self::Unknown => write!(f, "unknown"), | ||
Self::Other(s) => write!(f, "{}", s), | ||
} | ||
} | ||
} | ||
|
||
impl Default for TransactionSource { | ||
fn default() -> Self { | ||
Self::Unknown | ||
} | ||
} | ||
|
||
impl Empty for TransactionSource { | ||
#[inline] | ||
fn is_empty(&self) -> bool { | ||
matches!(self, Self::Unknown) | ||
} | ||
} | ||
|
||
impl FromValue for TransactionSource { | ||
fn from_value(value: Annotated<Value>) -> Annotated<Self> { | ||
match String::from_value(value) { | ||
Annotated(Some(value), mut meta) => match value.parse() { | ||
Ok(source) => Annotated(Some(source), meta), | ||
Err(_) => { | ||
meta.add_error(ErrorKind::InvalidData); | ||
meta.set_original_value(Some(value)); | ||
Annotated(None, meta) | ||
} | ||
}, | ||
Annotated(None, meta) => Annotated(None, meta), | ||
} | ||
} | ||
} | ||
|
||
impl IntoValue for TransactionSource { | ||
fn into_value(self) -> Value | ||
where | ||
Self: Sized, | ||
{ | ||
Value::String(self.to_string()) | ||
} | ||
|
||
fn serialize_payload<S>(&self, s: S, _behavior: SkipSerialization) -> Result<S::Ok, S::Error> | ||
where | ||
Self: Sized, | ||
S: serde::Serializer, | ||
{ | ||
serde::Serialize::serialize(&self.to_string(), s) | ||
} | ||
} | ||
|
||
impl ProcessValue for TransactionSource {} | ||
|
||
/// Additional information about the name of the transaction. | ||
#[derive(Clone, Debug, Default, PartialEq, Empty, FromValue, IntoValue, ProcessValue)] | ||
#[cfg_attr(feature = "jsonschema", derive(JsonSchema))] | ||
pub struct TransactionInfo { | ||
/// Describes how the name of the transaction was determined. | ||
/// | ||
/// This will be used by the server to decide whether or not to scrub identifiers from the | ||
/// transaction name, or replace the entire name with a placeholder. | ||
pub source: Annotated<TransactionSource>, | ||
|
||
/// The unmodified transaction name as obtained by the source. | ||
/// | ||
/// This value will only be set if the transaction name was modified during event processing. | ||
#[metastructure(max_chars = "culprit", trim_whitespace = "true")] | ||
pub original: Annotated<String>, | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use crate::testutils; | ||
|
||
#[test] | ||
fn test_other_source_roundtrip() { | ||
let json = r#""something-new""#; | ||
let source = Annotated::new(TransactionSource::Other("something-new".to_owned())); | ||
|
||
testutils::assert_eq_dbg!(source, Annotated::from_json(json).unwrap()); | ||
testutils::assert_eq_str!(json, source.payload_to_json_pretty().unwrap()); | ||
} | ||
|
||
#[test] | ||
fn test_transaction_info_roundtrip() { | ||
let json = r#"{ | ||
"source": "url", | ||
"original": "/auth/login/john123/" | ||
}"#; | ||
|
||
let info = Annotated::new(TransactionInfo { | ||
source: Annotated::new(TransactionSource::Url), | ||
original: Annotated::new("/auth/login/john123/".to_owned()), | ||
}); | ||
|
||
testutils::assert_eq_dbg!(info, Annotated::from_json(json).unwrap()); | ||
testutils::assert_eq_str!(json, info.to_json_pretty().unwrap()); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
--- | ||
source: relay-general/tests/test_fixtures.rs | ||
assertion_line: 106 | ||
expression: event_json_schema() | ||
--- | ||
{ | ||
|
@@ -347,6 +348,18 @@ expression: event_json_schema() | |
"null" | ||
] | ||
}, | ||
"transaction_info": { | ||
"description": " Additional information about the name of the transaction.", | ||
"default": null, | ||
"anyOf": [ | ||
{ | ||
"$ref": "#/definitions/TransactionInfo" | ||
}, | ||
{ | ||
"type": "null" | ||
} | ||
] | ||
}, | ||
"type": { | ||
"description": " Type of the event. Defaults to `default`.\n\n The event type determines how Sentry handles the event and has an impact on processing, rate\n limiting, and quotas. There are three fundamental classes of event types:\n\n - **Error monitoring events**: Processed and grouped into unique issues based on their\n exception stack traces and error messages.\n - **Security events**: Derived from Browser security violation reports and grouped into\n unique issues based on the endpoint and violation. SDKs do not send such events.\n - **Transaction events** (`transaction`): Contain operation spans and collected into traces\n for performance monitoring.\n\n Transactions must explicitly specify the `\"transaction\"` event type. In all other cases,\n Sentry infers the appropriate event type from the payload and overrides the stated type.\n SDKs should not send an event type other than for transactions.\n\n Example:\n\n ```json\n {\n \"type\": \"transaction\",\n \"spans\": []\n }\n ```", | ||
"default": null, | ||
|
@@ -2803,6 +2816,50 @@ expression: event_json_schema() | |
} | ||
] | ||
}, | ||
"TransactionInfo": { | ||
"description": " Additional information about the name of the transaction.", | ||
"anyOf": [ | ||
{ | ||
"type": "object", | ||
"properties": { | ||
"original": { | ||
"description": " The unmodified transaction name as obtained by the source.\n\n This value will only be set if the transaction name was modified during event processing.", | ||
"default": null, | ||
"type": [ | ||
"string", | ||
"null" | ||
] | ||
}, | ||
"source": { | ||
"description": " Describes how the name of the transaction was determined.\n\n This will be used by the server to decide whether or not to scrub identifiers from the\n transaction name, or replace the entire name with a placeholder.", | ||
"default": null, | ||
"anyOf": [ | ||
{ | ||
"$ref": "#/definitions/TransactionSource" | ||
}, | ||
{ | ||
"type": "null" | ||
} | ||
] | ||
} | ||
}, | ||
"additionalProperties": false | ||
} | ||
] | ||
}, | ||
"TransactionSource": { | ||
"description": "Describes how the name of the transaction was determined.", | ||
"type": "string", | ||
"enum": [ | ||
"custom", | ||
"url", | ||
"route", | ||
"view", | ||
"component", | ||
"task", | ||
"unknown" | ||
] | ||
}, | ||
"User": { | ||
"description": " Information about the user who triggered an event.\n\n ```json\n {\n \"user\": {\n \"id\": \"unique_id\",\n \"username\": \"my_user\",\n \"email\": \"[email protected]\",\n \"ip_address\": \"127.0.0.1\",\n \"subscription\": \"basic\"\n }\n }\n ```", | ||
"anyOf": [ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually, don't we have _meta for original data?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the DACI it was decided not to use _meta to make the information more accessible to the product.