From 5658ab3afea4a0a27b223e2c90b6725b389f8777 Mon Sep 17 00:00:00 2001 From: Tony Xiao Date: Wed, 3 Nov 2021 17:03:28 -0400 Subject: [PATCH] fix(suspect-spans): Span frequency should never exceed 100% Because of the use of `count_unique(id)` to compute the number of transactions that contain the span, and that it is an approximation, it is possible that we will see some frequency values exceeding 100%. This clips the frequency value so that this never happens. --- .../transactionSpans/suspectSpanCard.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/static/app/views/performance/transactionSummary/transactionSpans/suspectSpanCard.tsx b/static/app/views/performance/transactionSummary/transactionSpans/suspectSpanCard.tsx index e824f7d80635af..f95011f2bc7d35 100644 --- a/static/app/views/performance/transactionSummary/transactionSpans/suspectSpanCard.tsx +++ b/static/app/views/performance/transactionSummary/transactionSpans/suspectSpanCard.tsx @@ -190,14 +190,22 @@ function SpanCount(props: HeaderItemProps) { ); } + // Because the frequency is computed using `count_unique(id)` internally, + // it is an approximate value. This means that it has the potential to be + // greater than `totals.count` when it shouldn't. So let's clip the + // frequency value to make sure we don't see values over 100%. + const frequency = defined(totals?.count) + ? Math.min(suspectSpan.frequency, totals!.count) + : suspectSpan.frequency; + const value = defined(totals?.count) ? ( - {formatPercentage(suspectSpan.frequency / totals!.count)} + {formatPercentage(frequency / totals!.count)} ) : ( String(suspectSpan.count)