Skip to content

Commit

Permalink
instr(server): Count transactions by platform, source (#2230)
Browse files Browse the repository at this point in the history
Collect counts of transactions per `(platform, source,
contains_slashes)`. The goal of this metric is to verify a suspicion
that most `unknown` transactions from javascript projects are URL
transactions.

This metric replaces the now unused `transaction_source` metric, which
is unused and produced some high-cardinality tags.
  • Loading branch information
jjbayer committed Jun 20, 2023
1 parent dcad1bd commit ae7f9bf
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 10 deletions.
21 changes: 15 additions & 6 deletions relay-server/src/actors/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ use relay_filter::FilterStatKey;
use relay_general::pii::{PiiAttachmentsProcessor, PiiConfigError, PiiProcessor};
use relay_general::processor::{process_value, ProcessingState};
use relay_general::protocol::Context::Trace;
use relay_general::protocol::Contexts;
use relay_general::protocol::{
self, Breadcrumb, ClientReport, Csp, Event, EventType, ExpectCt, ExpectStaple, Hpkp, IpAddr,
LenientString, Metrics, RelayInfo, Replay, ReplayError, SecurityReportType, SessionAggregates,
SessionAttributes, SessionStatus, SessionUpdate, Timestamp, TraceContext, UserReport, Values,
};
use relay_general::protocol::{Contexts, TransactionSource};
use relay_general::store::{
ClockDriftProcessor, LightNormalizationConfig, MeasurementsConfig, TransactionNameConfig,
};
Expand Down Expand Up @@ -66,7 +66,7 @@ use crate::extractors::RequestMeta;
use crate::metrics_extraction::sessions::extract_session_metrics;
use crate::metrics_extraction::transactions::extract_transaction_metrics;
use crate::metrics_extraction::transactions::types::ExtractMetricsError;
use crate::statsd::{RelayCounters, RelayHistograms, RelayTimers};
use crate::statsd::{PlatformTag, RelayCounters, RelayHistograms, RelayTimers};
use crate::utils::{
self, get_sampling_key, log_transaction_name_metrics, ChunkedFormDataAggregator, FormDataIter,
ItemAction, ManagedEnvelope, SamplingResult,
Expand Down Expand Up @@ -1832,10 +1832,19 @@ impl EnvelopeProcessorService {
let source = event.get_transaction_source();

metric!(
counter(RelayCounters::EventTransactionSource) += 1,
source = &source.to_string(),
sdk = envelope.meta().client_name().unwrap_or("proprietary"),
platform = event.platform.as_str().unwrap_or("other"),
counter(RelayCounters::EventTransaction) += 1,
source = match &source {
TransactionSource::Other(_) => "other",
source => source.as_str(),
},
platform =
PlatformTag::from(event.platform.as_str().unwrap_or("other")).as_str(),
contains_slashes =
if event.transaction.as_str().unwrap_or_default().contains('/') {
"true"
} else {
"false"
}
);

let span_count = event.spans.value().map(Vec::len).unwrap_or(0) as u64;
Expand Down
74 changes: 70 additions & 4 deletions relay-server/src/statsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,12 +491,12 @@ pub enum RelayCounters {
///
/// This metric is tagged with:
/// - `platform`: The event's platform, such as `"javascript"`.
/// - `sdk`: The name of the Sentry SDK sending the transaction. This tag is only set for
/// Sentry's SDKs and defaults to "proprietary".
/// - `source`: The source of the transaction name on the client. See the [transaction source
/// documentation](https://develop.sentry.dev/sdk/event-payloads/properties/transaction_info/)
/// for all valid values.
EventTransactionSource,
/// - `contains_slashes`: Whether the transaction name contains `/`. We use this as a heuristic
/// to represent URL transactions.
EventTransaction,
/// The number of transaction events processed grouped by transaction name modifications.
/// This metric is tagged with:
/// - `source_in`: The source of the transaction name before normalization.
Expand Down Expand Up @@ -567,7 +567,7 @@ impl CounterMetric for RelayCounters {
#[cfg(feature = "processing")]
RelayCounters::ProcessingMessageProduced => "processing.event.produced",
RelayCounters::EventProtocol => "event.protocol",
RelayCounters::EventTransactionSource => "event.transaction_source",
RelayCounters::EventTransaction => "event.transaction",
RelayCounters::TransactionNameChanges => "event.transaction_name_changes",
RelayCounters::Requests => "requests",
RelayCounters::ResponsesStatusCodes => "responses.status_codes",
Expand All @@ -578,3 +578,69 @@ impl CounterMetric for RelayCounters {
}
}
}

/// Low-cardinality platform that can be used as a statsd tag.
pub enum PlatformTag {
Cocoa,
Csharp,
Edge,
Go,
Java,
Javascript,
Julia,
Native,
Node,
Objc,
Other,
Perl,
Php,
Python,
Ruby,
Swift,
}

impl PlatformTag {
pub fn as_str(&self) -> &str {
match self {
Self::Cocoa => "cocoa",
Self::Csharp => "csharp",
Self::Edge => "edge",
Self::Go => "go",
Self::Java => "java",
Self::Javascript => "javascript",
Self::Julia => "julia",
Self::Native => "native",
Self::Node => "node",
Self::Objc => "objc",
Self::Other => "other",
Self::Perl => "perl",
Self::Php => "php",
Self::Python => "python",
Self::Ruby => "ruby",
Self::Swift => "swift",
}
}
}

impl<S: AsRef<str>> From<S> for PlatformTag {
fn from(value: S) -> Self {
match value.as_ref() {
"cocoa" => Self::Cocoa,
"csharp" => Self::Csharp,
"edge" => Self::Edge,
"go" => Self::Go,
"java" => Self::Java,
"javascript" => Self::Javascript,
"julia" => Self::Julia,
"native" => Self::Native,
"node" => Self::Node,
"objc" => Self::Objc,
"perl" => Self::Perl,
"php" => Self::Php,
"python" => Self::Python,
"ruby" => Self::Ruby,
"swift" => Self::Swift,
_ => Self::Other,
}
}
}

0 comments on commit ae7f9bf

Please sign in to comment.