Skip to content

Commit 8746202

Browse files
committed
fix: address review
1 parent 104d5a6 commit 8746202

File tree

4 files changed

+39
-32
lines changed

4 files changed

+39
-32
lines changed

src/v3/ActiveTrace.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -658,24 +658,20 @@ export class ActiveTrace<
658658
occurrence,
659659
recordedInState: this.stateMachine
660660
.currentState as NonTerminalTraceStates,
661+
labels: [],
661662
}
662663

663-
const labels = this.getSpanLabels({
664-
span,
665-
annotation,
666-
})
667-
668664
spanAndAnnotation = {
669665
span,
670-
annotation: {
671-
...annotation,
672-
labels,
673-
},
666+
annotation,
674667
}
675668

676669
this.deduplicationStrategy?.recordSpan(span, spanAndAnnotation)
677670
}
678671

672+
// make sure the labels are up-to-date
673+
spanAndAnnotation.annotation.labels = this.getSpanLabels(spanAndAnnotation)
674+
679675
const transition = this.stateMachine.emit(
680676
'onProcessSpan',
681677
spanAndAnnotation,

src/v3/ensureMatcherFn.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { type SpanMatch, type SpanMatcherFn, fromDefinition } from './matchSpan'
2+
import type { LabelMatchingFnsRecord, LabelMatchingInputRecord } from './types'
23
import type { ArrayWithAtLeastOneElement, KeysOfUnion } from './typeUtils'
34

45
export function ensureMatcherFn<
@@ -48,22 +49,22 @@ export function convertMatchersToFns<
4849
}
4950

5051
export function convertLabelMatchersToFns<
51-
TracerScopeT extends AllPossibleScopesT,
52+
TracerScopeKeysT extends KeysOfUnion<AllPossibleScopesT>,
5253
AllPossibleScopesT,
5354
>(
54-
definitionLabelMatchers: Record<
55-
string,
56-
SpanMatch<TracerScopeT, AllPossibleScopesT>
55+
definitionLabelMatchers: LabelMatchingInputRecord<
56+
TracerScopeKeysT,
57+
AllPossibleScopesT
5758
>,
58-
): Record<string, SpanMatcherFn<TracerScopeT, AllPossibleScopesT>> {
59-
return Object.keys(definitionLabelMatchers).reduce<
60-
Record<string, SpanMatcherFn<TracerScopeT, AllPossibleScopesT>>
61-
>((acc, key) => {
62-
if (!definitionLabelMatchers?.[key]) return acc
63-
const matchFn = convertMatchersToFns([definitionLabelMatchers[key]])
64-
if (matchFn) {
65-
acc[key] = matchFn[0]
66-
}
67-
return acc
68-
}, {})
59+
): LabelMatchingFnsRecord<TracerScopeKeysT, AllPossibleScopesT> {
60+
const matchers: LabelMatchingFnsRecord<TracerScopeKeysT, AllPossibleScopesT> =
61+
{}
62+
for (const key in definitionLabelMatchers) {
63+
// eslint-disable-next-line no-continue
64+
if (!definitionLabelMatchers?.[key]) continue
65+
matchers[key] = ensureMatcherFn<TracerScopeKeysT, AllPossibleScopesT>(
66+
definitionLabelMatchers[key],
67+
)
68+
}
69+
return matchers
6970
}

src/v3/spanAnnotationTypes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ export interface SpanAnnotation {
3434
*/
3535
markedInteractive?: boolean
3636
/**
37-
* Optional labels for the span based on label definitions from the Tracer.
37+
* Labels for the span based on label definitions from the Tracer. Empty if the span didn't match any of the label match definitions.
3838
*/
39-
labels?: string[]
39+
labels: string[]
4040
}
4141

4242
export interface SpanAnnotationRecord {

src/v3/types.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,16 @@ export interface CaptureInteractiveConfig extends CPUIdleProcessorOptions {
120120
timeout?: number
121121
}
122122

123+
export type LabelMatchingInputRecord<
124+
TracerScopeKeysT extends KeysOfUnion<AllPossibleScopesT>,
125+
AllPossibleScopesT,
126+
> = Record<string, SpanMatch<TracerScopeKeysT, AllPossibleScopesT>>
127+
128+
export type LabelMatchingFnsRecord<
129+
TracerScopeKeysT extends KeysOfUnion<AllPossibleScopesT>,
130+
AllPossibleScopesT,
131+
> = Record<string, SpanMatcherFn<TracerScopeKeysT, AllPossibleScopesT>>
132+
123133
/**
124134
* Definition of a trace that includes conditions on when to end, debounce, and interrupt.
125135
* The "input" version will be transformed into the standardized version internally,
@@ -139,9 +149,9 @@ export interface TraceDefinition<
139149
scopes: readonly TracerScopeKeysT[]
140150

141151
// TODO: typing this so that the labels are inferred?
142-
labelMatching?: Record<
143-
string,
144-
SpanMatch<NoInfer<TracerScopeT>, AllPossibleScopesT>
152+
labelMatching?: LabelMatchingInputRecord<
153+
NoInfer<TracerScopeKeysT>,
154+
AllPossibleScopesT
145155
>
146156

147157
/**
@@ -200,9 +210,9 @@ export interface CompleteTraceDefinition<
200210
SpanMatcherFn<NoInfer<TracerScopeKeysT>, AllPossibleScopesT>[]
201211
>[]
202212

203-
labelMatching?: Record<
204-
string,
205-
SpanMatcherFn<TracerScopeT, AllPossibleScopesT>
213+
labelMatching?: LabelMatchingFnsRecord<
214+
NoInfer<TracerScopeKeysT>,
215+
AllPossibleScopesT
206216
>
207217

208218
requiredToEnd: ArrayWithAtLeastOneElement<

0 commit comments

Comments
 (0)