Skip to content

Commit

Permalink
feat(protocol): Add origin to trace context and span (#1984)
Browse files Browse the repository at this point in the history
Adds origin to both trace context and the span. The origin of the span
indicates what created the span.

Related RFC getsentry/rfcs#73 and develop docs
PR getsentry/develop#887
  • Loading branch information
philipphofmann committed Apr 7, 2023
1 parent c3b339e commit 6242ca3
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 3 deletions.
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
4 changes: 4 additions & 0 deletions relay-general/src/protocol/contexts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ use crate::user_agent::{ClientHints, RawUserAgentInfo};
/// Tries to follow OpenCensus/OpenTracing's span types.
pub type OperationType = String;

/// 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;

/// A context describes environment info (e.g. device, os or browser).
#[derive(Clone, Debug, PartialEq, Empty, FromValue, IntoValue, ProcessValue)]
#[cfg_attr(feature = "jsonschema", derive(JsonSchema))]
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>,

/// 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
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

0 comments on commit 6242ca3

Please sign in to comment.