@workflow/web-shared 5.0.0-beta.46 → 5.0.0-beta.48
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/event-list-view.js +3 -3
- package/dist/components/trace-viewer/components/use-alt-held.d.ts +11 -0
- package/dist/components/trace-viewer/components/use-alt-held.d.ts.map +1 -0
- package/dist/components/trace-viewer/components/use-alt-held.js +48 -0
- package/dist/components/trace-viewer/trace-viewer.d.ts.map +1 -1
- package/dist/components/trace-viewer/trace-viewer.js +4 -17
- package/dist/components/trace-viewer.d.ts +4 -1
- package/dist/components/trace-viewer.d.ts.map +1 -1
- package/dist/components/trace-viewer.js +4 -3
- package/dist/components/ui/data-inspector.d.ts +3 -2
- package/dist/components/ui/data-inspector.d.ts.map +1 -1
- package/dist/components/ui/data-inspector.js +85 -8
- package/dist/components/workflow-traces/trace-span-construction.d.ts +2 -1
- package/dist/components/workflow-traces/trace-span-construction.d.ts.map +1 -1
- package/dist/components/workflow-traces/trace-span-construction.js +7 -3
- package/dist/lib/duplicate-events.d.ts.map +1 -1
- package/dist/lib/duplicate-events.js +14 -25
- package/dist/lib/hydration.d.ts.map +1 -1
- package/dist/lib/hydration.js +13 -1
- package/dist/lib/trace-builder.d.ts +3 -1
- package/dist/lib/trace-builder.d.ts.map +1 -1
- package/dist/lib/trace-builder.js +5 -5
- package/package.json +8 -8
- package/src/components/event-list-view.tsx +2 -2
- package/src/components/trace-viewer/components/use-alt-held.ts +54 -0
- package/src/components/trace-viewer/trace-viewer.tsx +3 -15
- package/src/components/trace-viewer.tsx +6 -1
- package/src/components/ui/data-inspector.tsx +105 -9
- package/src/components/workflow-traces/trace-span-construction.ts +14 -2
- package/src/lib/duplicate-events.ts +14 -26
- package/src/lib/hydration.ts +12 -0
- package/src/lib/trace-builder.test.ts +42 -1
- package/src/lib/trace-builder.ts +13 -4
|
@@ -9,7 +9,11 @@ let nextId = 0;
|
|
|
9
9
|
|
|
10
10
|
function event(
|
|
11
11
|
eventType: EventType,
|
|
12
|
-
options: {
|
|
12
|
+
options: {
|
|
13
|
+
correlationId?: string;
|
|
14
|
+
at: number;
|
|
15
|
+
externalAttemptId?: string;
|
|
16
|
+
}
|
|
13
17
|
): Event {
|
|
14
18
|
nextId += 1;
|
|
15
19
|
return {
|
|
@@ -20,6 +24,7 @@ function event(
|
|
|
20
24
|
createdAt: new Date(BASE_TIME + options.at * 1000),
|
|
21
25
|
occurredAt: new Date(BASE_TIME + options.at * 1000),
|
|
22
26
|
eventData: eventType === 'step_created' ? { stepName: 'doWork' } : {},
|
|
27
|
+
externalAttemptId: options.externalAttemptId,
|
|
23
28
|
} as unknown as Event;
|
|
24
29
|
}
|
|
25
30
|
|
|
@@ -31,6 +36,42 @@ const run = {
|
|
|
31
36
|
} as unknown as WorkflowRun;
|
|
32
37
|
|
|
33
38
|
describe('buildTrace', () => {
|
|
39
|
+
it('adds caller-derived attributes to step span data', () => {
|
|
40
|
+
const events = [
|
|
41
|
+
event('run_created', { at: 0 }),
|
|
42
|
+
event('run_started', { at: 0 }),
|
|
43
|
+
event('step_created', { correlationId: 'step_a', at: 1 }),
|
|
44
|
+
event('step_started', {
|
|
45
|
+
correlationId: 'step_a',
|
|
46
|
+
at: 2,
|
|
47
|
+
externalAttemptId: 'attempt_first',
|
|
48
|
+
}),
|
|
49
|
+
event('step_retrying', { correlationId: 'step_a', at: 3 }),
|
|
50
|
+
event('step_started', {
|
|
51
|
+
correlationId: 'step_a',
|
|
52
|
+
at: 4,
|
|
53
|
+
externalAttemptId: 'attempt_latest',
|
|
54
|
+
}),
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
const trace = buildTrace(run, events, new Date(BASE_TIME + 5000), {
|
|
58
|
+
getStepAttributes(stepEvents) {
|
|
59
|
+
const latestStart = stepEvents
|
|
60
|
+
.slice()
|
|
61
|
+
.reverse()
|
|
62
|
+
.find((candidate) => candidate.eventType === 'step_started') as
|
|
63
|
+
| (Event & { externalAttemptId?: string })
|
|
64
|
+
| undefined;
|
|
65
|
+
return { externalAttemptId: latestStart?.externalAttemptId };
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
const stepSpan = trace.spans.find((span) => span.resource === 'step');
|
|
69
|
+
|
|
70
|
+
expect(stepSpan?.attributes.data).toMatchObject({
|
|
71
|
+
externalAttemptId: 'attempt_latest',
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
34
75
|
it('ends a step span on the terminal event the run acted on', () => {
|
|
35
76
|
const events = [
|
|
36
77
|
event('run_created', { at: 0 }),
|
package/src/lib/trace-builder.ts
CHANGED
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
type WorkflowRun,
|
|
15
15
|
} from '@workflow/world';
|
|
16
16
|
import {
|
|
17
|
+
type GetStepAttributes,
|
|
17
18
|
getEventTimestamp,
|
|
18
19
|
hookToSpan,
|
|
19
20
|
runToSpan,
|
|
@@ -137,7 +138,8 @@ function buildSpans(
|
|
|
137
138
|
run: WorkflowRun,
|
|
138
139
|
groupedEvents: GroupedEvents,
|
|
139
140
|
now: Date,
|
|
140
|
-
latestKnownTime: Date
|
|
141
|
+
latestKnownTime: Date,
|
|
142
|
+
getStepAttributes?: GetStepAttributes
|
|
141
143
|
) {
|
|
142
144
|
// Active child spans cap at latestKnownTime so they don't extend into
|
|
143
145
|
// unknown territory. Even when the run is completed, we may not have loaded
|
|
@@ -146,7 +148,7 @@ function buildSpans(
|
|
|
146
148
|
const runMaxEnd = run.completedAt ?? now;
|
|
147
149
|
|
|
148
150
|
const stepSpans = Array.from(groupedEvents.eventsByStepId.values())
|
|
149
|
-
.map((events) => stepToSpan(events, childMaxEnd))
|
|
151
|
+
.map((events) => stepToSpan(events, childMaxEnd, getStepAttributes))
|
|
150
152
|
.filter((span): span is Span => span !== null);
|
|
151
153
|
|
|
152
154
|
const hookSpans = Array.from(groupedEvents.hookEvents.values())
|
|
@@ -208,7 +210,13 @@ export function buildTrace(
|
|
|
208
210
|
* from the only copy the caller was given, and dropping the wrong one moves
|
|
209
211
|
* a span. See {@link findDuplicateEventIds}.
|
|
210
212
|
*/
|
|
211
|
-
{
|
|
213
|
+
{
|
|
214
|
+
isCompleteHistory = false,
|
|
215
|
+
getStepAttributes,
|
|
216
|
+
}: {
|
|
217
|
+
isCompleteHistory?: boolean;
|
|
218
|
+
getStepAttributes?: GetStepAttributes;
|
|
219
|
+
} = {}
|
|
212
220
|
): TraceWithMeta {
|
|
213
221
|
// Span geometry comes from what the run acted on. A repeat of a class the
|
|
214
222
|
// log already records is read past by every replay, and letting one through
|
|
@@ -232,7 +240,8 @@ export function buildTrace(
|
|
|
232
240
|
run,
|
|
233
241
|
groupedEvents,
|
|
234
242
|
now,
|
|
235
|
-
latestKnownTime
|
|
243
|
+
latestKnownTime,
|
|
244
|
+
getStepAttributes
|
|
236
245
|
);
|
|
237
246
|
const sortedCascadingSpans = cascadeSpans(runSpan, spans);
|
|
238
247
|
|