Skip to content

Commit

Permalink
feat(spans): Derive geo info for standalone spans (#4047)
Browse files Browse the repository at this point in the history
Derive geo info from the `span.data[client.address]`.
  • Loading branch information
jjbayer authored Sep 20, 2024
1 parent ea9b631 commit c6e3021
Show file tree
Hide file tree
Showing 8 changed files with 309 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
**Features:**

- Add a config option to add default tags to all Relay Sentry events. ([#3944](https://github.com/getsentry/relay/pull/3944))
- Automatically derive `client.address` and `user.geo` for standalone spans. ([#4047](https://github.com/getsentry/relay/pull/4047))

## 24.9.0

Expand Down
92 changes: 88 additions & 4 deletions relay-event-schema/src/protocol/span.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
mod convert;

use relay_protocol::{Annotated, Empty, Error, FromValue, Getter, IntoValue, Object, Val, Value};
use relay_protocol::{
Annotated, Array, Empty, Error, FromValue, Getter, IntoValue, Object, Val, Value,
};

use crate::processor::ProcessValue;
use crate::protocol::{
EventId, JsonLenientString, LenientString, Measurements, MetricsSummary, OperationType,
EventId, IpAddr, JsonLenientString, LenientString, Measurements, MetricsSummary, OperationType,
OriginType, SpanId, SpanStatus, ThreadId, Timestamp, TraceId,
};

Expand Down Expand Up @@ -352,6 +354,66 @@ pub struct SpanData {
#[metastructure(field = "user")]
pub user: Annotated<Value>,

/// User email address.
///
/// <https://opentelemetry.io/docs/specs/semconv/attributes-registry/user/>
#[metastructure(field = "user.email")]
pub user_email: Annotated<String>,

/// User’s full name.
///
/// <https://opentelemetry.io/docs/specs/semconv/attributes-registry/user/>
#[metastructure(field = "user.full_name")]
pub user_full_name: Annotated<String>,

/// Two-letter country code (ISO 3166-1 alpha-2).
///
/// This is not an OTel convention (yet).
#[metastructure(field = "user.geo.country_code")]
pub user_geo_country_code: Annotated<String>,

/// Human readable city name.
///
/// This is not an OTel convention (yet).
#[metastructure(field = "user.geo.city")]
pub user_geo_city: Annotated<String>,

/// Human readable subdivision name.
///
/// This is not an OTel convention (yet).
#[metastructure(field = "user.geo.subdivision")]
pub user_geo_subdivision: Annotated<String>,

/// Human readable region name or code.
///
/// This is not an OTel convention (yet).
#[metastructure(field = "user.geo.region")]
pub user_geo_region: Annotated<String>,

/// Unique user hash to correlate information for a user in anonymized form.
///
/// <https://opentelemetry.io/docs/specs/semconv/attributes-registry/user/>
#[metastructure(field = "user.hash")]
pub user_hash: Annotated<String>,

/// Unique identifier of the user.
///
/// <https://opentelemetry.io/docs/specs/semconv/attributes-registry/user/>
#[metastructure(field = "user.id")]
pub user_id: Annotated<String>,

/// Short name or login/username of the user.
///
/// <https://opentelemetry.io/docs/specs/semconv/attributes-registry/user/>
#[metastructure(field = "user.name")]
pub user_name: Annotated<String>,

/// Array of user roles at the time of the event.
///
/// <https://opentelemetry.io/docs/specs/semconv/attributes-registry/user/>
#[metastructure(field = "user.roles")]
pub user_roles: Annotated<Array<String>>,

/// Replay ID
#[metastructure(field = "sentry.replay.id", legacy_alias = "replay_id")]
pub replay_id: Annotated<Value>,
Expand Down Expand Up @@ -410,7 +472,7 @@ pub struct SpanData {

/// The client's IP address.
#[metastructure(field = "client.address")]
pub client_address: Annotated<String>,
pub client_address: Annotated<IpAddr>,

/// The current route in the application.
///
Expand Down Expand Up @@ -463,6 +525,16 @@ impl Getter for SpanData {
"thread\\.name" => self.thread_name.as_str()?.into(),
"ui\\.component_name" => self.ui_component_name.value()?.into(),
"url\\.scheme" => self.url_scheme.value()?.into(),
"user" => self.user.value()?.into(),
"user\\.email" => self.user_email.as_str()?.into(),
"user\\.full_name" => self.user_full_name.as_str()?.into(),
"user\\.geo\\.city" => self.user_geo_city.as_str()?.into(),
"user\\.geo\\.country_code" => self.user_geo_country_code.as_str()?.into(),
"user\\.geo\\.region" => self.user_geo_region.as_str()?.into(),
"user\\.geo\\.subdivision" => self.user_geo_subdivision.as_str()?.into(),
"user\\.hash" => self.user_hash.as_str()?.into(),
"user\\.id" => self.user_id.as_str()?.into(),
"user\\.name" => self.user_name.as_str()?.into(),
"transaction" => self.segment_name.as_str()?.into(),
"release" => self.release.as_str()?.into(),
_ => {
Expand Down Expand Up @@ -777,6 +849,16 @@ mod tests {
ui_component_name: ~,
url_scheme: ~,
user: ~,
user_email: ~,
user_full_name: ~,
user_geo_country_code: ~,
user_geo_city: ~,
user_geo_subdivision: ~,
user_geo_region: ~,
user_hash: ~,
user_id: ~,
user_name: ~,
user_roles: ~,
replay_id: ~,
sdk_name: ~,
sdk_version: ~,
Expand Down Expand Up @@ -805,7 +887,9 @@ mod tests {
messaging_message_id: "abc123",
user_agent_original: "Chrome",
url_full: "my_url.com",
client_address: "192.168.0.1",
client_address: IpAddr(
"192.168.0.1",
),
route: ~,
previous_route: ~,
other: {
Expand Down
10 changes: 10 additions & 0 deletions relay-event-schema/src/protocol/span/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,16 @@ mod tests {
ui_component_name: ~,
url_scheme: ~,
user: ~,
user_email: ~,
user_full_name: ~,
user_geo_country_code: ~,
user_geo_city: ~,
user_geo_subdivision: ~,
user_geo_region: ~,
user_hash: ~,
user_id: ~,
user_name: ~,
user_roles: ~,
replay_id: ~,
sdk_name: "sentry.php",
sdk_version: "1.2.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@ expression: "(&event.value().unwrap().spans, metrics)"
ui_component_name: ~,
url_scheme: ~,
user: ~,
user_email: ~,
user_full_name: ~,
user_geo_country_code: ~,
user_geo_city: ~,
user_geo_subdivision: ~,
user_geo_region: ~,
user_hash: ~,
user_id: ~,
user_name: ~,
user_roles: ~,
replay_id: ~,
sdk_name: ~,
sdk_version: ~,
Expand Down Expand Up @@ -460,6 +470,16 @@ expression: "(&event.value().unwrap().spans, metrics)"
ui_component_name: ~,
url_scheme: ~,
user: ~,
user_email: ~,
user_full_name: ~,
user_geo_country_code: ~,
user_geo_city: ~,
user_geo_subdivision: ~,
user_geo_region: ~,
user_hash: ~,
user_id: ~,
user_name: ~,
user_roles: ~,
replay_id: ~,
sdk_name: ~,
sdk_version: ~,
Expand Down Expand Up @@ -568,6 +588,16 @@ expression: "(&event.value().unwrap().spans, metrics)"
ui_component_name: ~,
url_scheme: ~,
user: ~,
user_email: ~,
user_full_name: ~,
user_geo_country_code: ~,
user_geo_city: ~,
user_geo_subdivision: ~,
user_geo_region: ~,
user_hash: ~,
user_id: ~,
user_name: ~,
user_roles: ~,
replay_id: ~,
sdk_name: ~,
sdk_version: ~,
Expand Down Expand Up @@ -728,6 +758,16 @@ expression: "(&event.value().unwrap().spans, metrics)"
ui_component_name: ~,
url_scheme: ~,
user: ~,
user_email: ~,
user_full_name: ~,
user_geo_country_code: ~,
user_geo_city: ~,
user_geo_subdivision: ~,
user_geo_region: ~,
user_hash: ~,
user_id: ~,
user_name: ~,
user_roles: ~,
replay_id: ~,
sdk_name: ~,
sdk_version: ~,
Expand Down Expand Up @@ -836,6 +876,16 @@ expression: "(&event.value().unwrap().spans, metrics)"
ui_component_name: ~,
url_scheme: ~,
user: ~,
user_email: ~,
user_full_name: ~,
user_geo_country_code: ~,
user_geo_city: ~,
user_geo_subdivision: ~,
user_geo_region: ~,
user_hash: ~,
user_id: ~,
user_name: ~,
user_roles: ~,
replay_id: ~,
sdk_name: ~,
sdk_version: ~,
Expand Down
2 changes: 1 addition & 1 deletion relay-server/src/services/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1866,7 +1866,7 @@ impl EnvelopeProcessorService {
if_processing!(self.inner.config, {
let global_config = self.inner.global_config.current();

span::process(state, &global_config);
span::process(state, &global_config, self.inner.geoip_lookup.as_ref());

self.enforce_quotas(state)?;
});
Expand Down
Loading

0 comments on commit c6e3021

Please sign in to comment.