Skip to content

Commit 2a921d4

Browse files
committed
fix: add cancelDraftTrace, add instance methods to tracer
1 parent 01b3326 commit 2a921d4

File tree

5 files changed

+18
-13
lines changed

5 files changed

+18
-13
lines changed

src/v3/recordingComputeUtils.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import {
55
getComputedSpans,
66
getComputedValues,
77
} from './recordingComputeUtils'
8+
import type { CompleteTraceDefinition } from './types'
89
import {
910
createMockSpanAndAnnotation,
1011
createTimestamp,
1112
} from './testUtility/createMockFactory'
12-
import type { CompleteTraceDefinition } from './types'
1313

1414
type AnyScope = Record<string, unknown>
1515

src/v3/traceManager.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export class TraceManager<
5858
// warn on miss?
5959
},
6060
getActiveTrace: () => this.activeTrace,
61+
cancelDraftTrace: () => this.activeTrace?.interrupt('draft-cancelled'),
6162
}
6263
}
6364

src/v3/traceManagerWithDraft.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,6 @@ describe('TraceManager', () => {
120120
`
121121
processSpans(spans, traceManager)
122122

123-
// tracer.transitionDraftToActive({ scope: { ticketId: '1' } })
124-
125123
expect(reportFn).toHaveBeenCalled()
126124

127125
const report: Parameters<ReportFn<TicketScope, TicketScope>>[0] =

src/v3/tracer.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,22 @@ export class Tracer<
4545
/**
4646
* @returns The ID of the trace.
4747
*/
48-
start(
48+
start = (
4949
input: StartTraceConfig<
5050
SelectScopeByKey<TracerScopeKeysT, AllPossibleScopesT>,
5151
OriginatedFromT
5252
>,
53-
): string | undefined {
53+
): string | undefined => {
5454
const traceId = this.createDraft(input)
5555
if (!traceId) return undefined
5656

5757
this.transitionDraftToActive({ scope: input.scope })
5858
return traceId
5959
}
6060

61-
createDraft(
61+
createDraft = (
6262
input: BaseStartTraceConfig<OriginatedFromT>,
63-
): string | undefined {
63+
): string | undefined => {
6464
const id = input.id ?? this.traceUtilities.generateId()
6565

6666
// Verify that the originatedFrom value is valid and has a corresponding timeout
@@ -100,17 +100,21 @@ export class Tracer<
100100
return id
101101
}
102102

103+
cancelDraft = () => {
104+
this.traceUtilities.cancelDraftTrace()
105+
}
106+
103107
// can have config changed until we move into active
104108
// from input: scope (required), attributes (optional, merge into)
105109
// from definition, can add items to: requiredSpans (additionalRequiredSpans), debounceOn (additionalDebounceOnSpans)
106110
// documentation: interruption still works and all the other events are buffered
107-
transitionDraftToActive(
111+
transitionDraftToActive = (
108112
inputAndDefinitionModifications: TraceModifications<
109113
TracerScopeKeysT,
110114
AllPossibleScopesT,
111115
OriginatedFromT
112116
>,
113-
): void {
117+
): void => {
114118
const activeTrace = this.traceUtilities.getActiveTrace()
115119
if (!activeTrace) {
116120
this.traceUtilities.reportErrorFn(
@@ -140,13 +144,13 @@ export class Tracer<
140144
typedActiveTrace.transitionDraftToActive(inputAndDefinitionModifications)
141145
}
142146

143-
defineComputedSpan(
147+
defineComputedSpan = (
144148
definition: ComputedSpanDefinitionInput<
145149
TracerScopeKeysT,
146150
AllPossibleScopesT,
147151
OriginatedFromT
148152
>,
149-
): void {
153+
): void => {
150154
this.definition.computedSpanDefinitions.push({
151155
...definition,
152156
startSpan:
@@ -168,7 +172,7 @@ export class Tracer<
168172
})
169173
}
170174

171-
defineComputedValue<
175+
defineComputedValue = <
172176
MatchersT extends (
173177
| SpanMatcherFn<TracerScopeKeysT, AllPossibleScopesT, OriginatedFromT>
174178
| SpanMatchDefinition<TracerScopeKeysT, AllPossibleScopesT>
@@ -180,7 +184,7 @@ export class Tracer<
180184
MatchersT,
181185
OriginatedFromT
182186
>,
183-
): void {
187+
): void => {
184188
this.definition.computedValueDefinitions.push({
185189
...definition,
186190
matches: definition.matches.map((m) =>

src/v3/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export type TraceInterruptionReason =
4848
| 'idle-component-no-longer-idle'
4949
| 'matched-on-interrupt'
5050
| 'invalid-state-transition'
51+
| 'draft-cancelled'
5152

5253
export type SingleTraceReportFn<
5354
TracerScopeKeysT extends KeysOfUnion<AllPossibleScopesT>,
@@ -102,6 +103,7 @@ export interface TraceManagerUtilities<AllPossibleScopesT>
102103
traceToCleanUp: AllPossibleActiveTraces<AllPossibleScopesT>,
103104
) => void
104105
getActiveTrace: () => AllPossibleActiveTraces<AllPossibleScopesT> | undefined
106+
cancelDraftTrace: () => void
105107
}
106108

107109
export interface TraceModifications<

0 commit comments

Comments
 (0)