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

feat(protocol): Add origin to trace context and span #1984

Merged
merged 22 commits into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Metrics:
- Changes how device class is determined for iPhone devices. Instead of checking processor frequency, the device model is mapped to a device class. ([#1970](https://github.com/getsentry/relay/pull/1970))
- Don't sanitize transactions if no clustering rules exist and no UUIDs were scrubbed. ([#1976](https://github.com/getsentry/relay/pull/1976))
- Add `thread.lock_mechanism` field to protocol. ([#1979](https://github.com/getsentry/relay/pull/1979))
- Add `origin` to trace context and span. ([#1984](https://github.com/getsentry/relay/pull/1984))

**Internal**:

Expand Down
8 changes: 7 additions & 1 deletion relay-general/src/protocol/contexts/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use regex::Regex;
use serde::{Serialize, Serializer};

use crate::processor::ProcessValue;
use crate::protocol::OperationType;
use crate::protocol::{OperationType, OriginType};
use crate::types::{
Annotated, Empty, Error, FromValue, IntoValue, Object, SkipSerialization, Value,
};
Expand Down Expand Up @@ -102,6 +102,10 @@ pub struct TraceContext {
/// should not ever send this value.
pub client_sample_rate: Annotated<f64>,

/// The origin of the trace indicates what created the trace (see [OriginType] docs).
#[metastructure(max_chars = "enumlike", allow_chars = "a-zA-Z0-9_.")]
pub origin: Annotated<OriginType>,
philipphofmann marked this conversation as resolved.
Show resolved Hide resolved

/// Additional arbitrary fields for forwards compatibility.
#[metastructure(additional_properties, retain = "true", pii = "maybe")]
pub other: Object<Value>,
Expand Down Expand Up @@ -203,6 +207,7 @@ mod tests {
"status": "ok",
"exclusive_time": 0.0,
"client_sample_rate": 0.5,
"origin": "auto.http",
"other": "value",
"type": "trace"
}"#;
Expand All @@ -214,6 +219,7 @@ mod tests {
status: Annotated::new(SpanStatus::Ok),
exclusive_time: Annotated::new(0.0),
client_sample_rate: Annotated::new(0.5),
origin: Annotated::new("auto.http".to_owned()),
other: {
let mut map = Object::new();
map.insert(
Expand Down
4 changes: 4 additions & 0 deletions relay-general/src/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,7 @@ pub use self::transaction::*;
pub use self::types::*;
pub use self::user::*;
pub use self::user_report::*;

/// Origin type such as `auto.http`.
/// Follows the pattern described in the [develop docs](https://develop.sentry.dev/sdk/performance/trace-origin/).
pub type OriginType = String;
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry I missed this earlier, but let's move this to relay-general/protocol/contexts/mod.rs, like OperationType.

12 changes: 10 additions & 2 deletions relay-general/src/protocol/span.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::protocol::{JsonLenientString, OperationType, SpanId, SpanStatus, Timestamp, TraceId};
use crate::protocol::{
JsonLenientString, OperationType, OriginType, SpanId, SpanStatus, Timestamp, TraceId,
};
use crate::types::{Annotated, Object, Value};

#[derive(Clone, Debug, Default, PartialEq, Empty, FromValue, IntoValue, ProcessValue)]
Expand Down Expand Up @@ -43,6 +45,10 @@ pub struct Span {
#[metastructure(pii = "maybe")]
pub tags: Annotated<Object<JsonLenientString>>,

/// The origin of the span indicates what created the span (see [OriginType] docs).
#[metastructure(max_chars = "enumlike", allow_chars = "a-zA-Z0-9_.")]
pub origin: Annotated<OriginType>,

/// Arbitrary additional data on a span, like `extra` on the top-level event.
#[metastructure(pii = "true")]
pub data: Annotated<Object<Value>>,
Expand Down Expand Up @@ -70,7 +76,8 @@ mod tests {
"op": "operation",
"span_id": "fa90fdead5f74052",
"trace_id": "4c79f60c11214eb38604f4ae0781bfb2",
"status": "ok"
"status": "ok",
"origin": "auto.http"
}"#;

let span = Annotated::new(Span {
Expand All @@ -84,6 +91,7 @@ mod tests {
trace_id: Annotated::new(TraceId("4c79f60c11214eb38604f4ae0781bfb2".into())),
span_id: Annotated::new(SpanId("fa90fdead5f74052".into())),
status: Annotated::new(SpanStatus::Ok),
origin: Annotated::new("auto.http".to_owned()),
..Default::default()
});
assert_eq!(json, span.to_json_pretty().unwrap());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3311,6 +3311,14 @@ expression: "relay_general::protocol::event_json_schema()"
"null"
]
},
"origin": {
"description": " The origin of the trace indicates what created the trace (see [OriginType] docs).",
"default": null,
"type": [
"string",
"null"
]
},
"parent_span_id": {
"description": " The ID of the span enclosing this span.",
"default": null,
Expand Down