Skip to content

Commit 62a17b2

Browse files
committed
fix: correct matchingRecordedEntries args
1 parent c01f8e9 commit 62a17b2

File tree

1 file changed

+30
-27
lines changed

1 file changed

+30
-27
lines changed

src/v3/recordingComputeUtils.ts

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,21 @@ export function getComputedValues<
5454
for (const definition of traceDefinition.computedValueDefinitions) {
5555
const { name, matches, computeValueFromMatches } = definition
5656

57-
const matchingRecordedEntries = recordedItems.filter((spanAndAnnotation) =>
58-
matches.some((matcher) =>
59-
matcher(spanAndAnnotation, { input, definition: traceDefinition }),
60-
),
61-
)
57+
// Initialize arrays to hold matches for each matcher
58+
const matchingEntriesByMatcher: SpanAndAnnotation<AllPossibleScopesT>[][] =
59+
Array.from({ length: matches.length }, () => [])
60+
61+
// Single pass through recordedItems
62+
for (const item of recordedItems) {
63+
matches.forEach((matcher, index) => {
64+
if (matcher(item, { input, definition: traceDefinition })) {
65+
matchingEntriesByMatcher[index]!.push(item)
66+
}
67+
})
68+
}
6269

63-
computedValues[name] = computeValueFromMatches(matchingRecordedEntries)
70+
computedValues[name] = computeValueFromMatches(...matchingEntriesByMatcher)
6471
}
65-
6672
return computedValues
6773
}
6874

@@ -177,21 +183,6 @@ export function getSpanSummaryAttributes<
177183
return spanAttributes
178184
}
179185

180-
// IMPLEMENTATION TODO: implementation of gathering Trace level attributes
181-
export function getAttributes<
182-
TracerScopeKeysT extends KeysOfUnion<AllPossibleScopesT>,
183-
AllPossibleScopesT,
184-
>({
185-
definition,
186-
recordedItems,
187-
input,
188-
}: ComputeRecordingData<TracerScopeKeysT, AllPossibleScopesT>): TraceRecording<
189-
TracerScopeKeysT,
190-
AllPossibleScopesT
191-
>['attributes'] {
192-
return {}
193-
}
194-
195186
function getComputedRenderBeaconSpans<
196187
TracerScopeKeysT extends KeysOfUnion<AllPossibleScopesT>,
197188
AllPossibleScopesT,
@@ -218,7 +209,14 @@ function getComputedRenderBeaconSpans<
218209

219210
// Group render spans by beacon and compute firstStart and lastEnd
220211
for (const entry of recordedItems) {
221-
if (entry.span.type !== 'component-render') continue
212+
if (
213+
entry.span.type !== 'component-render' &&
214+
entry.span.type !== 'component-render-start'
215+
) {
216+
// need to look at component-render-start too, because react might discard some renders as optimization
217+
// ratio of component-render-start to component-render isn't always 1:1
218+
continue
219+
}
222220
const { name, startTime, duration, scope, renderedOutput } = entry.span
223221
// accept any span that either matches scope or doesn't share any of the scope values
224222
const scopeMatch = scopeKeys.every(
@@ -238,19 +236,23 @@ function getComputedRenderBeaconSpans<
238236
renderSpansByBeacon.set(name, {
239237
firstStart: start,
240238
lastEnd: contentEnd,
241-
renderCount: 1,
239+
renderCount: entry.span.type === 'component-render' ? 1 : 0,
242240
sumOfDurations: duration,
243-
firstLoadingEnd:
244-
renderedOutput === 'loading' ? start + duration : undefined,
245241
firstContentStart: renderedOutput === 'content' ? start : undefined,
242+
firstLoadingEnd:
243+
entry.span.type === 'component-render' && renderedOutput === 'loading'
244+
? start + duration
245+
: undefined,
246246
})
247247
} else {
248248
spanTimes.firstStart = Math.min(spanTimes.firstStart, start)
249249
spanTimes.lastEnd =
250250
contentEnd && spanTimes.lastEnd
251251
? Math.max(spanTimes.lastEnd, contentEnd)
252252
: contentEnd ?? spanTimes.lastEnd
253-
spanTimes.renderCount += 1
253+
if (entry.span.type === 'component-render') {
254+
spanTimes.renderCount += 1
255+
}
254256
spanTimes.sumOfDurations += duration
255257
if (
256258
spanTimes.firstContentStart === undefined &&
@@ -260,6 +262,7 @@ function getComputedRenderBeaconSpans<
260262
}
261263
if (
262264
spanTimes.firstLoadingEnd === undefined &&
265+
entry.span.type === 'component-render' &&
263266
renderedOutput === 'loading'
264267
) {
265268
spanTimes.firstLoadingEnd = start + duration

0 commit comments

Comments
 (0)