Skip to content

Commit da96122

Browse files
committed
fix: expose getCurrentTrace on the Tracer
1 parent b39f720 commit da96122

File tree

4 files changed

+30
-10
lines changed

4 files changed

+30
-10
lines changed

src/v3/Trace.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1173,7 +1173,7 @@ export class Trace<
11731173
onEnd(
11741174
traceRecording: TraceRecording<SelectedRelationNameT, RelationSchemasT>,
11751175
): void {
1176-
this.traceUtilities.cleanupCurrentTrace(this)
1176+
this.traceUtilities.onEndTrace(this)
11771177
this.traceUtilities.reportFn(traceRecording, this)
11781178
}
11791179

src/v3/TraceManager.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type { Span } from './spanTypes'
99
import type { AllPossibleTraces } from './Trace'
1010
import { Tracer } from './Tracer'
1111
import type {
12+
AllPossibleTraceContexts,
1213
CompleteTraceDefinition,
1314
ComputedValueDefinitionInput,
1415
RelationSchemasBase,
@@ -28,12 +29,11 @@ export class TraceManager<
2829
private currentTrace: AllPossibleTraces<RelationSchemasT> | undefined =
2930
undefined
3031

31-
get currentTracerContext() {
32+
get currentTracerContext():
33+
| AllPossibleTraceContexts<RelationSchemasT, string>
34+
| undefined {
3235
if (!this.currentTrace) return undefined
33-
return {
34-
definition: this.currentTrace.definition,
35-
input: this.currentTrace.input,
36-
}
36+
return this.currentTrace
3737
}
3838

3939
constructor(
@@ -52,7 +52,7 @@ export class TraceManager<
5252
}
5353
this.currentTrace = newTrace
5454
},
55-
cleanupCurrentTrace: (traceToCleanUp) => {
55+
onEndTrace: (traceToCleanUp) => {
5656
if (traceToCleanUp === this.currentTrace) {
5757
this.currentTrace = undefined
5858
}

src/v3/Tracer.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
type CompleteTraceDefinition,
99
type ComputedSpanDefinitionInput,
1010
type ComputedValueDefinitionInput,
11+
type DraftTraceContext,
1112
type RelationSchemasBase,
1213
type TraceDefinitionModifications,
1314
type TraceManagerUtilities,
@@ -219,6 +220,16 @@ export class Tracer<
219220
trace.transitionDraftToActive(inputAndDefinitionModifications)
220221
}
221222

223+
getCurrentTrace = ():
224+
| DraftTraceContext<SelectedRelationNameT, RelationSchemasT, VariantsT>
225+
| undefined => {
226+
const trace = this.traceUtilities.getCurrentTrace()
227+
if (!trace || trace.sourceDefinition !== this.definition) {
228+
return undefined
229+
}
230+
return trace
231+
}
232+
222233
defineComputedSpan = (
223234
definition: ComputedSpanDefinitionInput<
224235
SelectedRelationNameT,

src/v3/types.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,7 @@ export interface TraceManagerUtilities<
171171
newTrace: AllPossibleTraces<RelationSchemasT>,
172172
reason: TraceReplaceInterruptionReason,
173173
) => void
174-
cleanupCurrentTrace: (
175-
traceToCleanUp: AllPossibleTraces<RelationSchemasT>,
176-
) => void
174+
onEndTrace: (traceToCleanUp: AllPossibleTraces<RelationSchemasT>) => void
177175
getCurrentTrace: () => AllPossibleTraces<RelationSchemasT> | undefined
178176
}
179177

@@ -574,6 +572,17 @@ export interface DraftTraceContext<
574572
>
575573
}
576574

575+
export type AllPossibleTraceContexts<
576+
RelationSchemasT,
577+
VariantsT extends string,
578+
> = {
579+
[SelectedRelationNameT in keyof RelationSchemasT]: DraftTraceContext<
580+
SelectedRelationNameT,
581+
RelationSchemasT,
582+
VariantsT
583+
>
584+
}[keyof RelationSchemasT]
585+
577586
export interface TraceContext<
578587
SelectedRelationNameT extends keyof RelationSchemasT,
579588
RelationSchemasT,

0 commit comments

Comments
 (0)