Skip to content

feat(traces): Use new slice quantization from backend #72034

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 4, 2024
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
8 changes: 6 additions & 2 deletions static/app/views/performance/traces/content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import usePageFilters from 'sentry/utils/usePageFilters';

import {type Field, FIELDS, SORTS} from './data';
import {
BREAKDOWN_SLICES,
ProjectRenderer,
SpanBreakdownSliceRenderer,
SpanDescriptionRenderer,
Expand Down Expand Up @@ -420,6 +421,7 @@ export interface TraceResult<F extends string> {
numOccurrences: number;
numSpans: number;
project: string | null;
slices: number;
spans: SpanResult<F>[];
start: number;
trace: string;
Expand All @@ -430,6 +432,9 @@ interface TraceBreakdownBase {
end: number;
opCategory: string | null;
sdkName: string | null;
sliceEnd: number;
sliceStart: number;
sliceWidth: number;
start: number;
}

Expand Down Expand Up @@ -494,8 +499,7 @@ function useTraces<F extends string>({
suggestedQuery,
sort,
per_page: limit,
breakdownSlices: 40,
minBreakdownPercentage: 1 / 40,
breakdownSlices: BREAKDOWN_SLICES,
maxSpansPerTrace: 10,
mri,
metricsMax,
Expand Down
38 changes: 27 additions & 11 deletions static/app/views/performance/traces/fieldRenderers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ export function TraceBreakdownRenderer({
sliceEnd={breakdown.end}
sliceDurationReal={breakdown.duration}
sliceSecondaryName={breakdown.sdkName}
sliceNumberStart={breakdown.sliceStart}
sliceNumberWidth={breakdown.sliceWidth}
trace={trace}
theme={theme}
offset={index}
Expand All @@ -146,16 +148,22 @@ export function TraceBreakdownRenderer({
);
}

const BREAKDOWN_BAR_SIZE = 200;
const BREAKDOWN_QUANTIZE_STEP = 1;
const BREAKDOWN_NUM_SLICES = BREAKDOWN_BAR_SIZE / BREAKDOWN_QUANTIZE_STEP; // 200
const BREAKDOWN_SIZE_PX = 200;
export const BREAKDOWN_SLICES = 40;

/**
* This renders slices in two different ways;
* - Slices in the breakdown for the trace. These have slice numbers returned for quantization from the backend.
* - Slices derived from span timings. Spans aren't quantized into slices.
*/
export function SpanBreakdownSliceRenderer({
trace,
theme,
sliceName,
sliceStart,
sliceEnd,
sliceNumberStart,
sliceNumberWidth,
sliceDurationReal,
sliceSecondaryName,
onMouseEnter,
Expand All @@ -170,26 +178,34 @@ export function SpanBreakdownSliceRenderer({
trace: TraceResult<Field>;
offset?: number;
sliceDurationReal?: number;
sliceNumberStart?: number;
sliceNumberWidth?: number;
}) {
const traceSliceSize = (trace.end - trace.start) / BREAKDOWN_NUM_SLICES;
const traceDuration = BREAKDOWN_NUM_SLICES * traceSliceSize;
const traceDuration = trace.end - trace.start;

const sliceDuration = sliceEnd - sliceStart;

if (sliceDuration <= 0) {
if (sliceNumberWidth === 0 && sliceNumberWidth === undefined && sliceDuration <= 0) {
Copy link
Member

Choose a reason for hiding this comment

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

sliceNumberWidth === 0 && sliceNumberWidth === undefined

Isn't that always false?

Copy link
Member Author

Choose a reason for hiding this comment

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

Right, this should be sliceNumberWidth === 0 || (sliceNumberWidth === undefined && sliceDuration <= 0), I must have accidentally undone this.

Copy link
Member Author

Choose a reason for hiding this comment

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

This should just be entirely removed anyway actually, we have checks on the backend now, don't need this defensive code anymore.

// No slice width or no duration width if it's a regular span.
return null;
}

const pixelsPerSlice = BREAKDOWN_SIZE_PX / BREAKDOWN_SLICES;
const relativeSliceStart = sliceStart - trace.start;

const stylingSliceName = getStylingSliceName(sliceName, sliceSecondaryName);
const sliceColor = stylingSliceName ? pickBarColor(stylingSliceName) : theme.gray100;

const sliceWidth =
BREAKDOWN_QUANTIZE_STEP *
Math.ceil(BREAKDOWN_NUM_SLICES * (sliceDuration / traceDuration));
const relativeSliceStart = sliceStart - trace.start;
sliceNumberWidth !== undefined
? pixelsPerSlice * sliceNumberWidth
: pixelsPerSlice * Math.ceil(BREAKDOWN_SLICES * (sliceDuration / traceDuration));
const sliceOffset =
BREAKDOWN_QUANTIZE_STEP *
Math.floor((BREAKDOWN_NUM_SLICES * relativeSliceStart) / traceDuration);
sliceNumberStart !== undefined
? pixelsPerSlice * sliceNumberStart
: pixelsPerSlice *
Math.floor((BREAKDOWN_SLICES * relativeSliceStart) / traceDuration);

return (
<BreakdownSlice
sliceName={sliceName}
Expand Down
Loading