Skip to content

Commit

Permalink
fix: improve consistency of naming
Browse files Browse the repository at this point in the history
  • Loading branch information
bbrzoska committed Feb 12, 2025
1 parent a0e430a commit c1c2335
Show file tree
Hide file tree
Showing 15 changed files with 139 additions and 124 deletions.
8 changes: 4 additions & 4 deletions src/stories/mockComponentsv3/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ const ticketOperationTracer = traceManager.createTracer({
],
scopes: ['ticketId'],
variants: {
click: { timeoutDuration: 45_000 },
click: { timeout: 45_000 },
},
// debounceDuration: 1_000,
debounceOn: [
// debounceWindow: 1_000,
debounceOnSpans: [
{
name: 'TicketView',
matchScopes: ['ticketId'],
},
],
interruptOn: [
interruptOnSpans: [
{
name: 'TicketView',
matchScopes: ['ticketId'],
Expand Down
48 changes: 25 additions & 23 deletions src/v3/ActiveTrace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ export class TraceStateMachine<
this.setGlobalDeadline(
this.context.input.startTime.epoch +
this.context.definition.variants[this.context.input.variant]!
.timeoutDuration,
.timeout,
)
},

Expand All @@ -299,10 +299,11 @@ export class TraceStateMachine<
}
}

// if the entry matches any of the interruptOn criteria,
// if the entry matches any of the interruptOnSpans criteria,
// transition to complete state with the 'matched-on-interrupt' interruptionReason
if (this.context.definition.interruptOn) {
for (const doesSpanMatch of this.context.definition.interruptOn) {
if (this.context.definition.interruptOnSpans) {
for (const doesSpanMatch of this.context.definition
.interruptOnSpans) {
if (doesSpanMatch(spanAndAnnotation, this.context)) {
return {
transitionToState: 'complete',
Expand Down Expand Up @@ -361,9 +362,9 @@ export class TraceStateMachine<
}
}

// does span satisfy any of the "interruptOn" definitions
if (this.context.definition.interruptOn) {
for (const match of this.context.definition.interruptOn) {
// does span satisfy any of the "interruptOnSpans" definitions
if (this.context.definition.interruptOnSpans) {
for (const match of this.context.definition.interruptOnSpans) {
if (match(spanAndAnnotation, this.context)) {
return {
transitionToState: 'interrupted',
Expand Down Expand Up @@ -441,15 +442,15 @@ export class TraceStateMachine<
this.lastRequiredSpan = this.lastRelevant
this.lastRequiredSpan.annotation.markedRequirementsMet = true

if (!this.context.definition.debounceOn) {
if (!this.context.definition.debounceOnSpans) {
return { transitionToState: 'waiting-for-interactive' }
}
// set the first debounce deadline
this.setDeadline(
'debounce',
this.lastRelevant.span.startTime.epoch +
this.lastRelevant.span.duration +
(this.context.definition.debounceDuration ??
(this.context.definition.debounceWindow ??
DEFAULT_DEBOUNCE_DURATION),
)

Expand Down Expand Up @@ -527,8 +528,8 @@ export class TraceStateMachine<
this.sideEffectFns.addSpanToRecording(spanAndAnnotation)

// does span satisfy any of the "debouncedOn" and if so, restart our debounce timer
if (this.context.definition.debounceOn) {
for (const doesSpanMatch of this.context.definition.debounceOn) {
if (this.context.definition.debounceOnSpans) {
for (const doesSpanMatch of this.context.definition.debounceOnSpans) {
if (doesSpanMatch(spanAndAnnotation, this.context)) {
// Sometimes spans are processed out of order, we update the lastRelevant if this span ends later
if (
Expand All @@ -543,7 +544,7 @@ export class TraceStateMachine<
'debounce',
this.lastRelevant.span.startTime.epoch +
this.lastRelevant.span.duration +
(this.context.definition.debounceDuration ??
(this.context.definition.debounceWindow ??
DEFAULT_DEBOUNCE_DURATION),
)
}
Expand Down Expand Up @@ -746,10 +747,11 @@ export class TraceStateMachine<
}
}

// if the entry matches any of the interruptOn criteria,
// if the entry matches any of the interruptOnSpans criteria,
// transition to complete state with the 'matched-on-interrupt' interruptionReason
if (this.context.definition.interruptOn) {
for (const doesSpanMatch of this.context.definition.interruptOn) {
if (this.context.definition.interruptOnSpans) {
for (const doesSpanMatch of this.context.definition
.interruptOnSpans) {
if (doesSpanMatch(spanAndAnnotation, this.context)) {
return {
transitionToState: 'complete',
Expand Down Expand Up @@ -959,13 +961,13 @@ export class ActiveTrace<
computedSpanDefinitions: [...definition.computedSpanDefinitions],
computedValueDefinitions: [...definition.computedValueDefinitions],

interruptOn: definition.interruptOn
? [...definition.interruptOn]
interruptOnSpans: definition.interruptOnSpans
? [...definition.interruptOnSpans]
: undefined,
debounceOn: definition.debounceOn
? [...definition.debounceOn]
debounceOnSpans: definition.debounceOnSpans
? [...definition.debounceOnSpans]
: undefined,
debounceDuration: definition.debounceDuration,
debounceWindow: definition.debounceWindow,
captureInteractive: definition.captureInteractive
? typeof definition.captureInteractive === 'boolean'
? definition.captureInteractive
Expand Down Expand Up @@ -1113,10 +1115,10 @@ export class ActiveTrace<
] as (typeof definition)['requiredSpans']
}
if (additionalDebounceOnSpans?.length) {
definition.debounceOn = [
...(this.sourceDefinition.debounceOn ?? []),
definition.debounceOnSpans = [
...(this.sourceDefinition.debounceOnSpans ?? []),
...additionalDebounceOnSpans,
] as (typeof definition)['debounceOn']
] as (typeof definition)['debounceOnSpans']
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/v3/convertToRum.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('convertTraceToRUM', () => {
computedSpanDefinitions: [],
computedValueDefinitions: [],
variants: {
origin: { timeoutDuration: 45_000 },
origin: { timeout: 45_000 },
},
}

Expand Down
4 changes: 2 additions & 2 deletions src/v3/idealApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ export const ticketActivationTracer = traceManager.createOperationTracer({
},
],
// we do not need to debounce on anything until 'requiredToEnd' is met
debounceOn: [
debounceOnSpans: [
{
match: { scope: { ticket: { id } } },
}
],
interruptOn: [
interruptOnSpans: [
{
match: {
type: 'mark',
Expand Down
2 changes: 1 addition & 1 deletion src/v3/matchSpan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const mockContext = {
computedSpanDefinitions: [],
computedValueDefinitions: [],
variants: {
origin: { timeoutDuration: 10_000 },
origin: { timeout: 10_000 },
},
} satisfies CompleteTraceDefinition<'ticketId', TicketScope, 'origin'>,
} as const
Expand Down
8 changes: 4 additions & 4 deletions src/v3/recordingComputeUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('recordingComputeUtils', () => {
computedSpanDefinitions: [],
computedValueDefinitions: [],
variants: {
origin: { timeoutDuration: 45_000 },
origin: { timeout: 45_000 },
},
}

Expand Down Expand Up @@ -159,7 +159,7 @@ describe('recordingComputeUtils', () => {
],
computedValueDefinitions: [],
variants: {
origin: { timeoutDuration: 45_000 },
origin: { timeout: 45_000 },
},
}

Expand Down Expand Up @@ -241,7 +241,7 @@ describe('recordingComputeUtils', () => {
},
],
variants: {
origin: { timeoutDuration: 45_000 },
origin: { timeout: 45_000 },
},
}

Expand Down Expand Up @@ -297,7 +297,7 @@ describe('recordingComputeUtils', () => {
computedSpanDefinitions: [],
computedValueDefinitions: [],
variants: {
origin: { timeoutDuration: 45_000 },
origin: { timeout: 45_000 },
},
},
recordedItems: [
Expand Down
6 changes: 3 additions & 3 deletions src/v3/testUtility/fixtures/ticket.activation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const ticketActivationDefinition: TraceDefinition<
type: 'operation',
scopes: ['ticketId'],
variants: {
cold_boot: { timeoutDuration: 60_000 },
cold_boot: { timeout: 60_000 },
},
captureInteractive: true,
requiredSpans: [
Expand All @@ -32,7 +32,7 @@ export const ticketActivationDefinition: TraceDefinition<
isIdle: true,
},
],
interruptOn: [
interruptOnSpans: [
{
type: 'mark',
name: TICKET_DISPOSE_EVENT_NAME,
Expand All @@ -44,7 +44,7 @@ export const ticketActivationDefinition: TraceDefinition<
matchScopes: ['ticketId'],
},
],
debounceOn: [
debounceOnSpans: [
// debounce on anything that has matching ticketId scope:
{ matchScopes: ['ticketId'] },
// TODO: { type: 'measure', name: (name, scope) => `ticket/${scope.ticketId}/open` },
Expand Down
44 changes: 23 additions & 21 deletions src/v3/traceManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('TraceManager', () => {
scopes: ['ticketId'],
requiredSpans: [{ name: 'end' }],
variants: {
cold_boot: { timeoutDuration: DEFAULT_COLDBOOT_TIMEOUT_DURATION },
cold_boot: { timeout: DEFAULT_COLDBOOT_TIMEOUT_DURATION },
},
})
const traceId = tracer.start({
Expand Down Expand Up @@ -101,7 +101,7 @@ describe('TraceManager', () => {
scopes: [],
requiredSpans: [{ name: 'end' }],
variants: {
cold_boot: { timeoutDuration: DEFAULT_COLDBOOT_TIMEOUT_DURATION },
cold_boot: { timeout: DEFAULT_COLDBOOT_TIMEOUT_DURATION },
},
})

Expand Down Expand Up @@ -161,7 +161,7 @@ describe('TraceManager', () => {
scopes: [],
requiredSpans: [{ name: 'end' }],
variants: {
cold_boot: { timeoutDuration: DEFAULT_COLDBOOT_TIMEOUT_DURATION },
cold_boot: { timeout: DEFAULT_COLDBOOT_TIMEOUT_DURATION },
},
})

Expand Down Expand Up @@ -221,7 +221,7 @@ describe('TraceManager', () => {
scopes: [],
requiredSpans: [{ name: 'Component', isIdle: true }],
variants: {
cold_boot: { timeoutDuration: DEFAULT_COLDBOOT_TIMEOUT_DURATION },
cold_boot: { timeout: DEFAULT_COLDBOOT_TIMEOUT_DURATION },
},
})

Expand Down Expand Up @@ -281,7 +281,7 @@ describe('TraceManager', () => {
scopes: ['ticketId'],
requiredSpans: [{ name: 'end', matchScopes: true }],
variants: {
cold_boot: { timeoutDuration: DEFAULT_COLDBOOT_TIMEOUT_DURATION },
cold_boot: { timeout: DEFAULT_COLDBOOT_TIMEOUT_DURATION },
},
})
const scope = {
Expand Down Expand Up @@ -332,9 +332,9 @@ describe('TraceManager', () => {
type: 'operation',
scopes: [],
requiredSpans: [{ name: 'end' }],
debounceOn: [{ name: 'debounce' }],
debounceOnSpans: [{ name: 'debounce' }],
variants: {
cold_boot: { timeoutDuration: DEFAULT_COLDBOOT_TIMEOUT_DURATION },
cold_boot: { timeout: DEFAULT_COLDBOOT_TIMEOUT_DURATION },
},
})
const traceId = tracer.start({
Expand Down Expand Up @@ -381,10 +381,12 @@ describe('TraceManager', () => {
type: 'operation',
scopes: [],
requiredSpans: [matchSpan.withName('end')],
debounceOn: [matchSpan.withName((n: string) => n.endsWith('debounce'))],
debounceDuration: 300,
debounceOnSpans: [
matchSpan.withName((n: string) => n.endsWith('debounce')),
],
debounceWindow: 300,
variants: {
cold_boot: { timeoutDuration: DEFAULT_COLDBOOT_TIMEOUT_DURATION },
cold_boot: { timeout: DEFAULT_COLDBOOT_TIMEOUT_DURATION },
},
})
tracer.start({
Expand Down Expand Up @@ -423,7 +425,7 @@ describe('TraceManager', () => {
})

describe('interrupts', () => {
it('interrupts a basic trace when interruptOn criteria is met', () => {
it('interrupts a basic trace when interruptOnSpans criteria is met', () => {
const traceManager = new TraceManager<TicketScope>({
reportFn,
generateId,
Expand All @@ -434,9 +436,9 @@ describe('TraceManager', () => {
type: 'operation',
scopes: [],
requiredSpans: [matchSpan.withName('end')],
interruptOn: [matchSpan.withName('interrupt')],
interruptOnSpans: [matchSpan.withName('interrupt')],
variants: {
cold_boot: { timeoutDuration: DEFAULT_COLDBOOT_TIMEOUT_DURATION },
cold_boot: { timeout: DEFAULT_COLDBOOT_TIMEOUT_DURATION },
},
})
tracer.start({
Expand Down Expand Up @@ -484,9 +486,9 @@ describe('TraceManager', () => {
type: 'operation',
scopes: [],
requiredSpans: [{ name: 'end' }],
debounceOn: [{ name: 'debounce' }],
debounceOnSpans: [{ name: 'debounce' }],
variants: {
cold_boot: { timeoutDuration: DEFAULT_COLDBOOT_TIMEOUT_DURATION },
cold_boot: { timeout: DEFAULT_COLDBOOT_TIMEOUT_DURATION },
},
})
const traceId = tracer.start({
Expand Down Expand Up @@ -543,9 +545,9 @@ describe('TraceManager', () => {
type: 'operation',
scopes: [],
requiredSpans: [{ name: 'end', isIdle: true }],
debounceOn: [{ name: 'end' }],
debounceOnSpans: [{ name: 'end' }],
variants: {
cold_boot: { timeoutDuration: DEFAULT_COLDBOOT_TIMEOUT_DURATION },
cold_boot: { timeout: DEFAULT_COLDBOOT_TIMEOUT_DURATION },
},
})
tracer.start({
Expand Down Expand Up @@ -595,7 +597,7 @@ describe('TraceManager', () => {
type: 'operation',
scopes: ['ticketId'],
requiredSpans: [{ name: 'timed-out-render' }],
variants: { cold_boot: { timeoutDuration: 500 } },
variants: { cold_boot: { timeout: 500 } },
})
const traceId = tracer.start({
startTime: { now: 0, epoch: 0 },
Expand Down Expand Up @@ -650,7 +652,7 @@ describe('TraceManager', () => {
scopes: [],
requiredSpans: [{ name: 'timed-out-render' }],
variants: {
cold_boot: { timeoutDuration: CUSTOM_TIMEOUT_DURATION },
cold_boot: { timeout: CUSTOM_TIMEOUT_DURATION },
},
})
const traceId = tracer.start({
Expand Down Expand Up @@ -701,9 +703,9 @@ describe('TraceManager', () => {
type: 'operation',
scopes: [],
requiredSpans: [{ name: 'end' }],
debounceOn: [{ name: 'debounce' }],
debounceOnSpans: [{ name: 'debounce' }],
variants: {
cold_boot: { timeoutDuration: CUSTOM_TIMEOUT_DURATION },
cold_boot: { timeout: CUSTOM_TIMEOUT_DURATION },
},
})
const traceId = tracer.start({
Expand Down
Loading

0 comments on commit c1c2335

Please sign in to comment.