Skip to content
Merged
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
23 changes: 19 additions & 4 deletions relay-server/src/actors/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,16 @@ fn track_sampling_metrics(
None => return,
};

let last_change = changes.last().and_then(|a| a.value());
let last_change = changes
.iter()
.rev()
// skip all broken change records
.filter_map(|a| a.value())
// skip records without a timestamp
.filter(|c| c.timestamp.value().is_some())
// take the last that did not occur when the event was sent
.find(|c| c.timestamp.value() != event.timestamp.value());

let source = event.get_transaction_source().as_str();
let platform = event.platform.as_str().unwrap_or("other");
let sdk_name = event.sdk_name();
Expand Down Expand Up @@ -399,7 +408,11 @@ fn track_sampling_metrics(
sdk_version = sdk_version,
);

let percentage = ((change as f64) / (total as f64)).min(1.0);
let percentage = match (change, total) {
(0, 0) => 0.0, // 0% indicates no premature changes.
_ => ((change as f64) / (total as f64)).min(1.0) * 100.0,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: Doing the x100 here instead of on the presentation layer seems wrong.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Agreed, though I have not found a way to do this in Datadog. If you prefer, we can also keep it between 0-1

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it's fine - the name says "percentage", so multiplying by 100 does make the number consistent with the metric name.

};

metric!(
histogram(RelayHistograms::DynamicSamplingPropagationPercentage) = percentage,
source = source,
Expand All @@ -411,7 +424,9 @@ fn track_sampling_metrics(

if let (Some(&start), Some(&change), Some(&end)) = (
event.start_timestamp.value(),
last_change.and_then(|c| c.timestamp.value()),
last_change
.and_then(|c| c.timestamp.value())
.or_else(|| event.start_timestamp.value()), // default to start if there was no change
event.timestamp.value(),
) {
let delay_ms = (change - start).num_milliseconds();
Expand All @@ -427,7 +442,7 @@ fn track_sampling_metrics(

let duration_ms = (end - start).num_milliseconds() as f64;
if delay_ms >= 0 && duration_ms >= 0.0 {
let percentage = ((delay_ms as f64) / duration_ms).min(1.0);
let percentage = ((delay_ms as f64) / duration_ms).min(1.0) * 100.0;
metric!(
histogram(RelayHistograms::DynamicSamplingChangePercentage) = percentage,
source = source,
Expand Down
6 changes: 3 additions & 3 deletions relay-server/src/statsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ pub enum RelayHistograms {
/// number of propagations.
///
/// Tracks the same as `dynamic_sampling.propagations`, except that the value of this metric is
/// a percentage between `0.0` and `1.0`. A value of `0` means that no propagations occurred,
/// and `1` means that all propagations occurred with the wrong transaction name.
/// a percentage between `0.0` and `100.0`. A value of `0` means that no propagations occurred,
/// and `100` means that all propagations occurred with the wrong transaction name.
///
/// This metric is tagged with:
///
Expand All @@ -200,7 +200,7 @@ pub enum RelayHistograms {

/// Timing relative to the transaction duration until the final name is determined.
///
/// This is a percentage between `0.0` and `1.0`.
/// This is a percentage between `0.0` and `100.0`.
///
/// This metric is tagged with:
///
Expand Down