Skip to content

Commit c01f8e9

Browse files
committed
fix: onEnd accepts Context + TraceContext name
1 parent 51bf0a3 commit c01f8e9

File tree

7 files changed

+56
-54
lines changed

7 files changed

+56
-54
lines changed

src/main.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ export type * from './v3/hooksTypes'
5757
import * as match from './v3/matchSpan'
5858
export { match }
5959
export type {
60-
Context,
6160
NameMatcher,
6261
SpanMatch,
6362
SpanMatchDefinition,

src/v3/ActiveTrace.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
createCPUIdleProcessor,
1313
} from './firstCPUIdle'
1414
import { getSpanKey } from './getSpanKey'
15-
import { Context } from './matchSpan'
1615
import { createTraceRecording } from './recordingComputeUtils'
1716
import type {
1817
SpanAndAnnotation,
@@ -26,6 +25,7 @@ import type {
2625
SpanDeduplicationStrategy,
2726
TraceInterruptionReason,
2827
} from './types'
28+
import { TraceContext } from './types'
2929
import type {
3030
DistributiveOmit,
3131
KeysOfUnion,
@@ -111,7 +111,7 @@ type EntryType<AllPossibleScopesT> = PerformanceEntryLike & {
111111
interface StateMachineContext<
112112
TracerScopeKeysT extends KeysOfUnion<AllPossibleScopesT>,
113113
AllPossibleScopesT,
114-
> extends Context<TracerScopeKeysT, AllPossibleScopesT> {
114+
> extends TraceContext<TracerScopeKeysT, AllPossibleScopesT> {
115115
readonly requiredToEndIndexChecklist: Set<number>
116116
}
117117

@@ -766,7 +766,7 @@ export class ActiveTrace<
766766
},
767767
transition,
768768
)
769-
this.input.onEnd(traceRecording)
769+
this.input.onEnd(traceRecording, this)
770770

771771
// memory clean-up in case something retains the ActiveTrace instance
772772
this.recordedItems = []

src/v3/convertToRum.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/* eslint-disable @typescript-eslint/consistent-indexed-object-style */
22
import { getSpanKey } from './getSpanKey'
3-
import type { Context, SpanMatcherFn } from './matchSpan'
3+
import type { SpanMatcherFn } from './matchSpan'
44
import { SpanAndAnnotation } from './spanAnnotationTypes'
55
import { ComponentRenderSpan, Span } from './spanTypes'
66
import { TraceRecording, TraceRecordingBase } from './traceRecordingTypes'
7-
import type { SelectScopeByKey } from './types'
7+
import type { SelectScopeByKey, TraceContext } from './types'
88
import type { KeysOfUnion } from './typeUtils'
99

1010
export interface EmbeddedEntry {
@@ -94,7 +94,7 @@ export function convertTraceToRUM<
9494
AllPossibleScopesT,
9595
>(
9696
traceRecording: TraceRecording<TracerScopeKeysT, AllPossibleScopesT>,
97-
context: Context<TracerScopeKeysT, AllPossibleScopesT>,
97+
context: TraceContext<TracerScopeKeysT, AllPossibleScopesT>,
9898
embedSpanSelector: SpanMatcherFn<
9999
TracerScopeKeysT,
100100
AllPossibleScopesT

src/v3/matchSpan.ts

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,12 @@
11
import type { SpanAndAnnotation } from './spanAnnotationTypes'
2-
import type {
3-
ActiveTraceContext,
4-
Attributes,
5-
SpanStatus,
6-
SpanType,
7-
} from './spanTypes'
8-
import type { CompleteTraceDefinition, SelectScopeByKey } from './types'
2+
import type { Attributes, SpanStatus, SpanType } from './spanTypes'
3+
import type { SelectScopeByKey, TraceContext } from './types'
94
import type { KeysOfUnion } from './typeUtils'
105

116
export interface SpanMatcherTags {
127
isIdle?: boolean
138
}
149

15-
export interface Context<
16-
TracerScopeKeysT extends KeysOfUnion<AllPossibleScopesT>,
17-
AllPossibleScopesT,
18-
> {
19-
readonly definition: CompleteTraceDefinition<
20-
TracerScopeKeysT,
21-
AllPossibleScopesT
22-
>
23-
readonly input: ActiveTraceContext<
24-
SelectScopeByKey<TracerScopeKeysT, AllPossibleScopesT>
25-
>
26-
}
27-
2810
/**
2911
* Function type for matching performance entries.
3012
*/
@@ -34,7 +16,7 @@ export interface SpanMatcherFn<
3416
> extends SpanMatcherTags {
3517
(
3618
spanAndAnnotation: SpanAndAnnotation<AllPossibleScopesT>,
37-
context: Context<TracerScopeKeysT, AllPossibleScopesT>,
19+
context: TraceContext<TracerScopeKeysT, AllPossibleScopesT>,
3820
): boolean
3921
}
4022

src/v3/spanTypes.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import type { ErrorInfo } from 'react'
22
import type { BeaconConfig } from './hooksTypes'
3-
import type { TraceRecording } from './traceRecordingTypes'
4-
import type { ScopeOnASpan, SelectScopeByKey, Timestamp } from './types'
3+
import type {
4+
ScopeOnASpan,
5+
SelectScopeByKey,
6+
SingleTraceReportFn,
7+
Timestamp,
8+
} from './types'
59
import type { KeysOfUnion } from './typeUtils'
610

711
export type NativePerformanceEntryType =
@@ -37,12 +41,7 @@ export interface StartTraceConfig<TracerScopeT> {
3741
attributes?: Attributes
3842
}
3943

40-
export type OnEndFn<
41-
TracerScopeKeysT extends KeysOfUnion<AllPossibleScopesT>,
42-
AllPossibleScopesT,
43-
> = (trace: TraceRecording<TracerScopeKeysT, AllPossibleScopesT>) => void
44-
45-
export interface ActiveTraceContext<TracerScopeT>
44+
export interface ActiveTraceInput<TracerScopeT>
4645
extends StartTraceConfig<TracerScopeT> {
4746
id: string
4847
startTime: Timestamp
@@ -51,10 +50,10 @@ export interface ActiveTraceContext<TracerScopeT>
5150
export interface ActiveTraceConfig<
5251
TracerScopeKeysT extends KeysOfUnion<AllPossibleScopesT>,
5352
AllPossibleScopesT,
54-
> extends ActiveTraceContext<
53+
> extends ActiveTraceInput<
5554
SelectScopeByKey<TracerScopeKeysT, AllPossibleScopesT>
5655
> {
57-
onEnd: OnEndFn<TracerScopeKeysT, AllPossibleScopesT>
56+
onEnd: SingleTraceReportFn<TracerScopeKeysT, AllPossibleScopesT>
5857
}
5958

6059
// eslint-disable-next-line @typescript-eslint/consistent-indexed-object-style

src/v3/traceManager.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import {
77
import { ensureTimestamp } from './ensureTimestamp'
88
import { type SpanMatcherFn } from './matchSpan'
99
import type { SpanAnnotationRecord } from './spanAnnotationTypes'
10-
import type { Span, StartTraceConfig } from './spanTypes'
10+
import type { ActiveTraceInput, Span, StartTraceConfig } from './spanTypes'
1111
import type { TraceRecording } from './traceRecordingTypes'
1212
import type {
13+
type TraceContext,
1314
CompleteTraceDefinition,
1415
ComputedSpanDefinition,
1516
ComputedValueDefinition,
@@ -157,6 +158,18 @@ export class TraceManager<
157158

158159
const id = input.id ?? this.generateId()
159160

161+
const activeTraceContext: TraceContext<
162+
TracerScopeKeysT,
163+
AllPossibleScopesT
164+
> = {
165+
definition,
166+
input: {
167+
...input,
168+
startTime: ensureTimestamp(input.startTime),
169+
id,
170+
},
171+
}
172+
160173
const onEnd = (
161174
traceRecording: TraceRecording<TracerScopeKeysT, AllPossibleScopesT>,
162175
) => {
@@ -169,17 +182,12 @@ export class TraceManager<
169182
TracerScopeKeysT,
170183
AllPossibleScopesT
171184
>
172-
)(traceRecording)
185+
)(traceRecording, activeTraceContext)
173186
}
174187

175188
const activeTrace = new ActiveTrace<TracerScopeKeysT, AllPossibleScopesT>(
176189
definition,
177-
{
178-
...input,
179-
startTime: ensureTimestamp(input.startTime),
180-
id,
181-
onEnd,
182-
},
190+
{ ...activeTraceContext.input, onEnd },
183191
this.performanceEntryDeduplicationStrategy,
184192
)
185193

src/v3/types.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import type { CPUIdleProcessorOptions } from './firstCPUIdle'
2-
import type {
3-
Context,
4-
SpanMatch,
5-
SpanMatchDefinition,
6-
SpanMatcherFn,
7-
} from './matchSpan'
2+
import type { SpanMatch, SpanMatchDefinition, SpanMatcherFn } from './matchSpan'
83
import type { SpanAndAnnotation } from './spanAnnotationTypes'
9-
import type { Span, SpanStatus, SpanType, StartTraceConfig } from './spanTypes'
4+
import type {
5+
ActiveTraceInput,
6+
Span,
7+
SpanStatus,
8+
SpanType,
9+
StartTraceConfig,
10+
} from './spanTypes'
1011
import type { TraceRecording } from './traceRecordingTypes'
1112
import type {
1213
ArrayWithAtLeastOneElement,
@@ -52,7 +53,7 @@ export type SingleTraceReportFn<
5253
AllPossibleScopesT,
5354
> = (
5455
trace: TraceRecording<TracerScopeKeysT, AllPossibleScopesT>,
55-
context: Context<TracerScopeKeysT, AllPossibleScopesT>,
56+
context: TraceContext<TracerScopeKeysT, AllPossibleScopesT>,
5657
) => void
5758

5859
export type ReportFn<
@@ -372,3 +373,16 @@ export type SelectScopeByKey<
372373
export type DeriveScopeFromPerformanceEntryFn<AllPossibleScopesT> = (
373374
entry: PerformanceEntry,
374375
) => ScopeOnASpan<AllPossibleScopesT> | undefined
376+
377+
export interface TraceContext<
378+
TracerScopeKeysT extends KeysOfUnion<AllPossibleScopesT>,
379+
AllPossibleScopesT,
380+
> {
381+
readonly definition: CompleteTraceDefinition<
382+
TracerScopeKeysT,
383+
AllPossibleScopesT
384+
>
385+
readonly input: ActiveTraceInput<
386+
SelectScopeByKey<TracerScopeKeysT, AllPossibleScopesT>
387+
>
388+
}

0 commit comments

Comments
 (0)