Skip to content
Draft
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
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5015,6 +5015,7 @@ dependencies = [
"opentelemetry-proto",
"relay-conventions",
"relay-event-schema",
"relay-metrics",
"relay-otel",
"relay-protocol",
"serde",
Expand Down
4 changes: 4 additions & 0 deletions relay-server/src/processing/legacy_spans/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::Envelope;
use crate::envelope::{EnvelopeHeaders, Item, ItemContainer, ItemType, Items};
use crate::managed::{Counted, Managed, ManagedEnvelope, OutcomeError, Quantities, Rejected};
use crate::metrics_extraction::ExtractedMetrics;
use crate::processing::trace_metrics::produce_webvitals_metrics;
use crate::processing::{
self, Context, CountRateLimited, Forward, Output, QuotaRateLimiter, RateLimited,
};
Expand Down Expand Up @@ -202,6 +203,9 @@ impl Forward for LegacySpanOutput {

for span in spans.split(|spans| spans.spans.into_iter().map(IndexedOnly)) {
if let Ok(span) = span.try_map(|span, _| store::convert(span.0, retention)) {
if let Some(metrics) = relay_spans::extract_web_vital_metrics(&span.item) {
produce_webvitals_metrics(s, &span, metrics);
}
s.send_to_store(span)
};
}
Expand Down
4 changes: 4 additions & 0 deletions relay-server/src/processing/spans/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::metrics_extraction::ExtractedMetrics;
use crate::processing::trace_attachments::forward::attachment_to_item;
use crate::processing::trace_attachments::process::ScrubAttachmentError;
use crate::processing::trace_attachments::types::ExpandedAttachment;
use crate::processing::trace_metrics::produce_webvitals_metrics;
use crate::processing::{self, Context, Forward, Output, QuotaRateLimiter, RateLimited};
use crate::services::outcome::{DiscardReason, Outcome};

Expand Down Expand Up @@ -275,6 +276,9 @@ impl Forward for SpanOutput {
match either.transpose() {
Either::Left(span) => {
if let Ok(span) = span.try_map(|span, _| store::convert(span, &ctx)) {
if let Some(metrics) = relay_spans::extract_web_vital_metrics(&span.item) {
produce_webvitals_metrics(s, &span, metrics);
}
s.send_to_store(span);
}
}
Expand Down
48 changes: 44 additions & 4 deletions relay-server/src/processing/trace_metrics/mod.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
use std::sync::Arc;

use relay_cogs::{AppFeature, FeatureWeights};
use relay_event_schema::processor::ProcessingAction;
use relay_event_schema::protocol::TraceMetricHeader;
use relay_event_schema::protocol::{TraceMetric, trace_metric};
use relay_filter::FilterStatKey;
use relay_quotas::{DataCategory, RateLimits};
use smallvec::smallvec;
use std::collections::BTreeMap;
use std::sync::Arc;

use crate::Envelope;
use crate::envelope::{ContainerItems, EnvelopeHeaders, Item, ItemType, Items};
use crate::envelope::{ContainerWriteError, ItemContainer};
use crate::managed::{Counted, Managed, ManagedEnvelope, ManagedResult as _, Quantities, Rejected};
use crate::processing::{self, Context, CountRateLimited, Forward, Output, QuotaRateLimiter};
use crate::processing::trace_metrics;
use crate::processing::{
self, Context, CountRateLimited, Forward, Output, QuotaRateLimiter, Retention, StoreHandle,
};
use crate::services::outcome::{DiscardItemType, DiscardReason, Outcome};
use smallvec::smallvec;
use crate::services::store::StoreSpanV2;

mod filter;
mod process;
Expand All @@ -21,6 +26,41 @@ mod store;
mod utils;
mod validate;

/// Produce the supplied webvital trace metrics to kafka.
pub fn produce_webvitals_metrics(
s: StoreHandle<'_>,
span: &Managed<Box<StoreSpanV2>>,
metrics: Vec<TraceMetric>,
) {
for metric in metrics {
let trace_metric_headers = TraceMetricHeader {
byte_size: Some(trace_metrics::utils::calculate_size(&metric)),
other: BTreeMap::default(),
};

let wheader = crate::envelope::WithHeader {
header: trace_metric_headers.into(),
value: metric.into(),
};

if let Ok(mut item) = trace_metrics::store::convert(
wheader,
&trace_metrics::store::Context {
received_at: span.received_at(),
scoping: span.scoping(),
retention: Retention {
standard: span.retention_days,
downsampled: span.downsampled_retention_days,
},
},
) {
// Clear outcomes for these metrics, as we don't want them billed.
item.trace_item.outcomes = None;
s.send_to_store(span.wrap(item));
}
}
}

pub use self::utils::get_calculated_byte_size;

pub type Result<T, E = Error> = std::result::Result<T, E>;
Expand Down
7 changes: 6 additions & 1 deletion relay-server/src/processing/transactions/types/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::managed::{Managed, ManagedResult, Rejected};
#[cfg(feature = "processing")]
use crate::processing::StoreHandle;
use crate::processing::spans::Indexed;
use crate::processing::trace_metrics::produce_webvitals_metrics;
use crate::processing::transactions::types::{
ExpandedTransaction, ExtractedIndexedSpans, StandaloneProfile,
};
Expand Down Expand Up @@ -69,7 +70,6 @@ impl Forward for TransactionOutput {
}
TransactionOutput::Indexed { spans, transaction } => (spans, transaction),
};

let performance_issues_spans = ctx
.project_info
.has_feature(Feature::PerformanceIssuesSpans);
Expand All @@ -88,6 +88,11 @@ impl Forward for TransactionOutput {
span.performance_issues_spans = true;
});
}

if let Some(metrics) = relay_spans::extract_web_vital_metrics(&span.item) {
produce_webvitals_metrics(s, &span, metrics);
}

s.send_to_store(span)
};
}
Expand Down
1 change: 1 addition & 0 deletions relay-server/src/services/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use relay_threading::AsyncPool;
use crate::envelope::{AttachmentPlaceholder, AttachmentType, ContentType, Item, ItemType};
use crate::managed::{Counted, Managed, ManagedEnvelope, OutcomeError, Quantities, Rejected};
use crate::metrics::{ArrayEncoding, BucketEncoder, MetricOutcomes};

use crate::service::ServiceError;
use crate::services::global_config::GlobalConfigHandle;
use crate::services::objectstore::ObjectstoreKey;
Expand Down
1 change: 1 addition & 0 deletions relay-spans/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ opentelemetry-proto = { workspace = true, features = [
"with-serde",
"trace",
] }
relay-metrics = { workspace = true }
relay-conventions = { workspace = true }
relay-event-schema = { workspace = true }
relay-otel = { workspace = true }
Expand Down
2 changes: 2 additions & 0 deletions relay-spans/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub use crate::description::derive_description_for_v2_span;
pub use crate::op::derive_op_for_v2_span;
pub use crate::otel_to_sentry_v2::otel_to_sentry_span as otel_to_sentry_span_v2;
pub use crate::v1_to_v2::span_v1_to_span_v2;
pub use crate::web_vitals::extract_web_vital_metrics;

pub use opentelemetry_proto::tonic::trace::v1 as otel_trace;

Expand All @@ -18,3 +19,4 @@ mod name;
mod op;
mod otel_to_sentry_v2;
mod v1_to_v2;
mod web_vitals;
Loading
Loading