live-traces 0.1.0

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.
Files changed (63) hide show
  1. package/README.md +193 -0
  2. package/dist/index.d.ts +19 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +24 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/react/hooks.d.ts +22 -0
  7. package/dist/react/hooks.d.ts.map +1 -0
  8. package/dist/react/hooks.js +68 -0
  9. package/dist/react/hooks.js.map +1 -0
  10. package/dist/react/index.d.ts +26 -0
  11. package/dist/react/index.d.ts.map +1 -0
  12. package/dist/react/index.js +27 -0
  13. package/dist/react/index.js.map +1 -0
  14. package/dist/react/store.d.ts +77 -0
  15. package/dist/react/store.d.ts.map +1 -0
  16. package/dist/react/store.js +273 -0
  17. package/dist/react/store.js.map +1 -0
  18. package/dist/src/LiveTrace.d.ts +55 -0
  19. package/dist/src/LiveTrace.d.ts.map +1 -0
  20. package/dist/src/LiveTrace.js +66 -0
  21. package/dist/src/LiveTrace.js.map +1 -0
  22. package/dist/src/Logger.d.ts +3 -0
  23. package/dist/src/Logger.d.ts.map +1 -0
  24. package/dist/src/Logger.js +30 -0
  25. package/dist/src/Logger.js.map +1 -0
  26. package/dist/src/Schema.d.ts +97 -0
  27. package/dist/src/Schema.d.ts.map +1 -0
  28. package/dist/src/Schema.js +60 -0
  29. package/dist/src/Schema.js.map +1 -0
  30. package/dist/src/Sink.d.ts +36 -0
  31. package/dist/src/Sink.d.ts.map +1 -0
  32. package/dist/src/Sink.js +55 -0
  33. package/dist/src/Sink.js.map +1 -0
  34. package/dist/src/Tracer.d.ts +24 -0
  35. package/dist/src/Tracer.d.ts.map +1 -0
  36. package/dist/src/Tracer.js +154 -0
  37. package/dist/src/Tracer.js.map +1 -0
  38. package/dist/src/WrappedSpan.d.ts +44 -0
  39. package/dist/src/WrappedSpan.d.ts.map +1 -0
  40. package/dist/src/WrappedSpan.js +104 -0
  41. package/dist/src/WrappedSpan.js.map +1 -0
  42. package/dist/src/transports/sse.d.ts +26 -0
  43. package/dist/src/transports/sse.d.ts.map +1 -0
  44. package/dist/src/transports/sse.js +118 -0
  45. package/dist/src/transports/sse.js.map +1 -0
  46. package/dist/src/types.d.ts +73 -0
  47. package/dist/src/types.d.ts.map +1 -0
  48. package/dist/src/types.js +69 -0
  49. package/dist/src/types.js.map +1 -0
  50. package/index.ts +58 -0
  51. package/package.json +87 -0
  52. package/react/hooks.ts +73 -0
  53. package/react/index.ts +30 -0
  54. package/react/store.ts +357 -0
  55. package/src/LiveTrace.ts +99 -0
  56. package/src/Logger.ts +33 -0
  57. package/src/Schema.ts +70 -0
  58. package/src/Sink.ts +108 -0
  59. package/src/Tracer.ts +176 -0
  60. package/src/WrappedSpan.ts +138 -0
  61. package/src/__tests__/tracer.test.ts +238 -0
  62. package/src/transports/sse.ts +127 -0
  63. package/src/types.ts +151 -0
@@ -0,0 +1,273 @@
1
+ // ============================================================================
2
+ // Store
3
+ // ============================================================================
4
+ /** TTL for completed traces before eviction (ms) */
5
+ const COMPLETED_TTL_MS = 30_000;
6
+ /** Maximum events per span */
7
+ const MAX_SPAN_EVENTS = 50;
8
+ /** Replay filter: skip events older than 30 minutes */
9
+ const REPLAY_MAX_AGE_MS = 30 * 60 * 1000;
10
+ export class TraceStore {
11
+ traces = new Map();
12
+ listeners = new Set();
13
+ cleanupTimer = null;
14
+ constructor() {
15
+ this.cleanupTimer = setInterval(() => this.cleanup(), 5_000);
16
+ }
17
+ /** Subscribe to store changes (for useSyncExternalStore) */
18
+ subscribe = (listener) => {
19
+ this.listeners.add(listener);
20
+ return () => this.listeners.delete(listener);
21
+ };
22
+ /** Get snapshot (for useSyncExternalStore) */
23
+ getSnapshot = () => this.traces;
24
+ /** Dispatch a single trace event */
25
+ dispatch(event) {
26
+ // Skip ancient events on replay
27
+ if (Date.now() - event.timestamp > REPLAY_MAX_AGE_MS)
28
+ return;
29
+ switch (event._tag) {
30
+ case "TraceStart":
31
+ this.handleTraceStart(event);
32
+ break;
33
+ case "SpanStart":
34
+ this.handleSpanStart(event);
35
+ break;
36
+ case "SpanEnd":
37
+ this.handleSpanEnd(event);
38
+ break;
39
+ case "SpanEvent":
40
+ this.handleSpanEvent(event);
41
+ break;
42
+ case "TraceEnd":
43
+ this.handleTraceEnd(event);
44
+ break;
45
+ }
46
+ this.notify();
47
+ }
48
+ /** Dispatch a batch of events */
49
+ dispatchBatch(events) {
50
+ for (const event of events) {
51
+ // Inline without notify per event
52
+ if (Date.now() - event.timestamp > REPLAY_MAX_AGE_MS)
53
+ continue;
54
+ switch (event._tag) {
55
+ case "TraceStart":
56
+ this.handleTraceStart(event);
57
+ break;
58
+ case "SpanStart":
59
+ this.handleSpanStart(event);
60
+ break;
61
+ case "SpanEnd":
62
+ this.handleSpanEnd(event);
63
+ break;
64
+ case "SpanEvent":
65
+ this.handleSpanEvent(event);
66
+ break;
67
+ case "TraceEnd":
68
+ this.handleTraceEnd(event);
69
+ break;
70
+ }
71
+ }
72
+ this.notify();
73
+ }
74
+ /** Get a single trace */
75
+ getTrace(traceId) {
76
+ return this.traces.get(traceId);
77
+ }
78
+ /** Get all traces as array, sorted by startedAt descending */
79
+ getAllTraces() {
80
+ return Array.from(this.traces.values()).toSorted((a, b) => b.startedAt - a.startedAt);
81
+ }
82
+ /** Get step spans (ui.step=true) for a trace, in order */
83
+ getSteps(traceId) {
84
+ const trace = this.traces.get(traceId);
85
+ if (!trace)
86
+ return [];
87
+ return Array.from(trace.spans.values())
88
+ .filter((s) => s.isStep)
89
+ .toSorted((a, b) => a.startedAt - b.startedAt);
90
+ }
91
+ /** Build the span tree for a trace */
92
+ getSpanTree(traceId) {
93
+ const trace = this.traces.get(traceId);
94
+ if (!trace || !trace.rootSpanId)
95
+ return undefined;
96
+ return trace.spans.get(trace.rootSpanId);
97
+ }
98
+ /** Destroy the store (stop cleanup timer) */
99
+ destroy() {
100
+ if (this.cleanupTimer) {
101
+ clearInterval(this.cleanupTimer);
102
+ this.cleanupTimer = null;
103
+ }
104
+ this.listeners.clear();
105
+ }
106
+ // -- Event handlers --
107
+ handleTraceStart(event) {
108
+ const existing = this.traces.get(event.traceId);
109
+ if (existing)
110
+ return; // idempotent
111
+ this.traces = new Map(this.traces);
112
+ this.traces.set(event.traceId, {
113
+ traceId: event.traceId,
114
+ label: event.label,
115
+ scope: event.scope,
116
+ status: "running",
117
+ spans: new Map(),
118
+ startedAt: event.timestamp,
119
+ updatedAt: event.timestamp,
120
+ });
121
+ }
122
+ handleSpanStart(event) {
123
+ const trace = this.traces.get(event.traceId);
124
+ if (!trace)
125
+ return;
126
+ const span = {
127
+ spanId: event.spanId,
128
+ parentSpanId: event.parentSpanId,
129
+ name: event.name,
130
+ status: "running",
131
+ attributes: event.attributes,
132
+ events: [],
133
+ children: [],
134
+ startedAt: event.timestamp,
135
+ isStep: event.attributes["ui.step"] === true,
136
+ };
137
+ const newSpans = new Map(trace.spans);
138
+ newSpans.set(event.spanId, span);
139
+ // Add as child of parent span
140
+ if (event.parentSpanId) {
141
+ const parent = newSpans.get(event.parentSpanId);
142
+ if (parent) {
143
+ newSpans.set(event.parentSpanId, {
144
+ ...parent,
145
+ children: [...parent.children, span],
146
+ });
147
+ }
148
+ }
149
+ this.traces = new Map(this.traces);
150
+ this.traces.set(event.traceId, {
151
+ ...trace,
152
+ spans: newSpans,
153
+ rootSpanId: trace.rootSpanId ?? event.spanId,
154
+ updatedAt: event.timestamp,
155
+ });
156
+ }
157
+ handleSpanEnd(event) {
158
+ const trace = this.traces.get(event.traceId);
159
+ if (!trace)
160
+ return;
161
+ const span = trace.spans.get(event.spanId);
162
+ if (!span)
163
+ return;
164
+ const newSpans = new Map(trace.spans);
165
+ const updatedSpan = {
166
+ ...span,
167
+ status: event.status,
168
+ durationMs: event.durationMs,
169
+ };
170
+ newSpans.set(event.spanId, updatedSpan);
171
+ // Update in parent's children array too
172
+ if (span.parentSpanId) {
173
+ const parent = newSpans.get(span.parentSpanId);
174
+ if (parent) {
175
+ newSpans.set(span.parentSpanId, {
176
+ ...parent,
177
+ children: parent.children.map((c) => (c.spanId === event.spanId ? updatedSpan : c)),
178
+ });
179
+ }
180
+ }
181
+ this.traces = new Map(this.traces);
182
+ this.traces.set(event.traceId, {
183
+ ...trace,
184
+ spans: newSpans,
185
+ updatedAt: event.timestamp,
186
+ });
187
+ }
188
+ handleSpanEvent(event) {
189
+ const trace = this.traces.get(event.traceId);
190
+ if (!trace)
191
+ return;
192
+ const span = trace.spans.get(event.spanId);
193
+ if (!span)
194
+ return;
195
+ const entry = {
196
+ name: event.name,
197
+ level: event.level,
198
+ attributes: event.attributes,
199
+ timestamp: event.timestamp,
200
+ };
201
+ const newEvents = span.events.length >= MAX_SPAN_EVENTS ? [...span.events.slice(-MAX_SPAN_EVENTS + 1), entry] : [...span.events, entry];
202
+ const newSpans = new Map(trace.spans);
203
+ newSpans.set(event.spanId, { ...span, events: newEvents });
204
+ this.traces = new Map(this.traces);
205
+ this.traces.set(event.traceId, {
206
+ ...trace,
207
+ spans: newSpans,
208
+ updatedAt: event.timestamp,
209
+ });
210
+ }
211
+ handleTraceEnd(event) {
212
+ const trace = this.traces.get(event.traceId);
213
+ if (!trace)
214
+ return;
215
+ // Close any still-running spans (handles lost SpanEnd events)
216
+ const finalStatus = event.status === "completed" ? "ok" : "error";
217
+ let newSpans = trace.spans;
218
+ let hasRunningSpans = false;
219
+ for (const span of trace.spans.values()) {
220
+ if (span.status === "running") {
221
+ hasRunningSpans = true;
222
+ break;
223
+ }
224
+ }
225
+ if (hasRunningSpans) {
226
+ newSpans = new Map(trace.spans);
227
+ for (const [id, span] of newSpans) {
228
+ if (span.status === "running") {
229
+ newSpans.set(id, { ...span, status: finalStatus, durationMs: event.timestamp - span.startedAt });
230
+ }
231
+ }
232
+ }
233
+ this.traces = new Map(this.traces);
234
+ this.traces.set(event.traceId, {
235
+ ...trace,
236
+ spans: newSpans,
237
+ status: event.status === "completed" ? "completed" : "failed",
238
+ completedAt: event.timestamp,
239
+ durationMs: event.durationMs,
240
+ error: event.error,
241
+ updatedAt: event.timestamp,
242
+ });
243
+ }
244
+ cleanup() {
245
+ const now = Date.now();
246
+ let changed = false;
247
+ for (const [traceId, trace] of this.traces) {
248
+ if (trace.completedAt && now - trace.completedAt > COMPLETED_TTL_MS) {
249
+ if (!changed) {
250
+ this.traces = new Map(this.traces);
251
+ changed = true;
252
+ }
253
+ this.traces.delete(traceId);
254
+ }
255
+ }
256
+ if (changed)
257
+ this.notify();
258
+ }
259
+ notify() {
260
+ for (const listener of this.listeners) {
261
+ listener();
262
+ }
263
+ }
264
+ }
265
+ /** Singleton store instance */
266
+ let _store = null;
267
+ export function getTraceStore() {
268
+ if (!_store) {
269
+ _store = new TraceStore();
270
+ }
271
+ return _store;
272
+ }
273
+ //# sourceMappingURL=store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.js","sourceRoot":"","sources":["../../react/store.ts"],"names":[],"mappings":"AAmDA,+EAA+E;AAC/E,QAAQ;AACR,+EAA+E;AAE/E,oDAAoD;AACpD,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAEhC,8BAA8B;AAC9B,MAAM,eAAe,GAAG,EAAE,CAAC;AAE3B,uDAAuD;AACvD,MAAM,iBAAiB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAIzC,MAAM,OAAO,UAAU;IACX,MAAM,GAAG,IAAI,GAAG,EAAsB,CAAC;IACvC,SAAS,GAAG,IAAI,GAAG,EAAY,CAAC;IAChC,YAAY,GAA0C,IAAI,CAAC;IAEnE;QACI,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,KAAK,CAAC,CAAC;IACjE,CAAC;IAED,4DAA4D;IAC5D,SAAS,GAAG,CAAC,QAAkB,EAAgB,EAAE;QAC7C,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC7B,OAAO,GAAG,EA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,CAAC,CAAC;IACP,CAAC;IAEO,OAAO;QACX,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,IAAI,OAAO,GAAG,KAAK,CAAC;QAEpB,KAAK,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YACzC,IAAI,KAAK,CAAC,WAAW,IAAI,GAAG,GAAG,KAAK,CAAC,WAAW,GAAG,gBAAgB,EAAE,CAAC;gBAClE,IAAI,CAAC,OAAO,EAAE,CAAC;oBACX,IAAI,CAAC,MAAM,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;oBACnC,OAAO,GAAG,IAAI,CAAC;gBACnB,CAAC;gBACD,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAChC,CAAC;QACL,CAAC;QAED,IAAI,OAAO;YAAE,IAAI,CAAC,MAAM,EAAE,CAAC;IAC/B,CAAC;IAEO,MAAM;QACV,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACpC,QAAQ,EAAE,CAAC;QACf,CAAC;IACL,CAAC;CACJ;AAED,+BAA+B;AAC/B,IAAI,MAAM,GAAsB,IAAI,CAAC;AAErC,MAAM,UAAU,aAAa;IACzB,IAAI,CAAC,MAAM,EAAE,CAAC;QACV,MAAM,GAAG,IAAI,UAAU,EAAE,CAAC;IAC9B,CAAC;IACD,OAAO,MAAM,CAAC;AAClB,CAAC"}
@@ -0,0 +1,55 @@
1
+ import type { AnySpan } from "effect/Tracer";
2
+ /**
3
+ * LiveTrace — User-facing API for starting traced scopes.
4
+ *
5
+ * Usage:
6
+ * ```ts
7
+ * yield* pipe(
8
+ * myWorkflow,
9
+ * LiveTrace.withTrace({
10
+ * traceId: `doc:${documentId}`,
11
+ * label: "Processing report.pdf",
12
+ * scope: { type: "team", id: teamId },
13
+ * }),
14
+ * )
15
+ * ```
16
+ *
17
+ * Inside the scope, all `Effect.withSpan` and `Effect.log` calls
18
+ * are automatically captured and streamed to the frontend.
19
+ */
20
+ import * as Effect from "effect/Effect";
21
+ import * as FiberRef from "effect/FiberRef";
22
+ import { type TraceScope } from "./types.js";
23
+ export interface LiveTraceConfig {
24
+ /** Logical trace ID for stream routing (e.g., "doc:abc123") */
25
+ readonly traceId: string;
26
+ /** Human-readable label (e.g., filename) */
27
+ readonly label: string;
28
+ /** Stream routing scope */
29
+ readonly scope: TraceScope;
30
+ /** Optional provider key for source-page filtering (e.g. "notion", "google-drive") */
31
+ readonly provider?: string;
32
+ }
33
+ /**
34
+ * FiberRef that holds the current WrappedSpan (if inside a withTrace/step scope).
35
+ * Used by LiveTraceLogger to bridge Effect.log() → SpanEvent automatically.
36
+ * Inherited by child fibers so forked work stays attributed to the correct span.
37
+ */
38
+ export declare const LiveSpanRef: FiberRef.FiberRef<AnySpan | null>;
39
+ /**
40
+ * Wrap an effect in a live-traced scope.
41
+ *
42
+ * All `Effect.withSpan` and `Effect.log` calls within this scope
43
+ * are captured by the LiveTraceLayer and streamed to the sink.
44
+ */
45
+ export declare const withTrace: (config: LiveTraceConfig) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
46
+ /**
47
+ * Create a traced step span. Shows as a top-level section in the UI.
48
+ *
49
+ * ```ts
50
+ * yield* LiveTrace.step("Parsing")(parseDocument(doc))
51
+ * yield* LiveTrace.step("Embedding")(embedChunks(chunks))
52
+ * ```
53
+ */
54
+ export declare const step: (name: string, attributes?: Record<string, unknown>) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
55
+ //# sourceMappingURL=LiveTrace.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LiveTrace.d.ts","sourceRoot":"","sources":["../../src/LiveTrace.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAE7C;;;;;;;;;;;;;;;;;GAiBG;AACH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processing report.pdf",
11
+ * scope: { type: "team", id: teamId },
12
+ * }),
13
+ * )
14
+ * ```
15
+ *
16
+ * Inside the scope, all `Effect.withSpan` and `Effect.log` calls
17
+ * are automatically captured and streamed to the frontend.
18
+ */
19
+ import * as Effect from "effect/Effect";
20
+ import * as FiberRef from "effect/FiberRef";
21
+ import { LIVE_TRACE, LIVE_TRACE_ID, LIVE_TRACE_LABEL, LIVE_TRACE_PROVIDER, LIVE_TRACE_SCOPE_ID, LIVE_TRACE_SCOPE_TYPE, UI_STEP, } from "./types.js";
22
+ /**
23
+ * FiberRef that holds the current WrappedSpan (if inside a withTrace/step scope).
24
+ * Used by LiveTraceLogger to bridge Effect.log() → SpanEvent automatically.
25
+ * Inherited by child fibers so forked work stays attributed to the correct span.
26
+ */
27
+ export const LiveSpanRef = FiberRef.unsafeMake(null);
28
+ /**
29
+ * After Effect.withSpan creates the span, read it via Effect.currentSpan
30
+ * and store it in LiveSpanRef so the Logger can access it synchronously.
31
+ */
32
+ const propagateSpan = (effect) => Effect.gen(function* () {
33
+ const span = yield* Effect.currentSpan.pipe(Effect.orElseSucceed(() => null));
34
+ if (span) {
35
+ yield* FiberRef.set(LiveSpanRef, span);
36
+ }
37
+ return yield* effect;
38
+ });
39
+ /**
40
+ * Wrap an effect in a live-traced scope.
41
+ *
42
+ * All `Effect.withSpan` and `Effect.log` calls within this scope
43
+ * are captured by the LiveTraceLayer and streamed to the sink.
44
+ */
45
+ export const withTrace = (config) => (effect) => Effect.withSpan(propagateSpan(effect), config.label, {
46
+ attributes: {
47
+ [LIVE_TRACE]: true,
48
+ [LIVE_TRACE_ID]: config.traceId,
49
+ [LIVE_TRACE_LABEL]: config.label,
50
+ [LIVE_TRACE_SCOPE_TYPE]: config.scope.type,
51
+ [LIVE_TRACE_SCOPE_ID]: config.scope.id,
52
+ ...(config.provider !== undefined ? { [LIVE_TRACE_PROVIDER]: config.provider } : {}),
53
+ },
54
+ });
55
+ /**
56
+ * Create a traced step span. Shows as a top-level section in the UI.
57
+ *
58
+ * ```ts
59
+ * yield* LiveTrace.step("Parsing")(parseDocument(doc))
60
+ * yield* LiveTrace.step("Embedding")(embedChunks(chunks))
61
+ * ```
62
+ */
63
+ export const step = (name, attributes) => (effect) => Effect.withSpan(propagateSpan(effect), name, {
64
+ attributes: { [UI_STEP]: true, ...attributes },
65
+ });
66
+ //# sourceMappingURL=LiveTrace.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LiveTrace.js","sourceRoot":"","sources":["../../src/LiveTrace.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EACH,UAAU,EACV,aAAa,EACb,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,EACnB,qBAAqB,EAErB,OAAO,GACV,MAAM,YAAY,CAAC;AAapB;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAsC,QAAQ,CAAC,UAAU,CAAiB,IAAI,CAAC,CAAC;AAExG;;;GAGG;AACH,MAAM,aAAa,GAAG,CAAU,MAA8B,EAA0B,EAAE,CACtF,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAChB,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;IAC9E,IAAI,IAAI,EAAE,CAAC;QACP,KAAK,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;IAC3C,CAAC;IACD,OAAO,KAAK,CAAC,CAAC,MAAM,CAAC;AACzB,CAAC,CAA2B,CAAC;AAEjC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,SAAS,GAClB,CAAC,MAAuB,EAAE,EAAE,CAC5B,CAAU,MAA8B,EAA0B,EAAE,CAChE,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,KAAK,EAAE;IACjD,UAAU,EAAE;QACR,CAAC,UAAU,CAAC,EAAE,IAAI;QAClB,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC,OAAO;QAC/B,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC,KAAK;QAChC,CAAC,qBAAqB,CAAC,EAAE,MAAM,CAAC,KAAK,CAAC,IAAI;QAC1C,CAAC,mBAAmB,CAAC,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE;QACtC,GAAG,CAAC,MAAM,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,mBAAmB,CAAC,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACvF;CACJ,CAAC,CAAC;AAEX;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,IAAI,GACb,CAAC,IAAY,EAAE,UAAoC,EAAE,EAAE,CACvD,CAAU,MAA8B,EAA0B,EAAE,CAChE,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE;IACzC,UAAU,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,GAAG,UAAU,EAAE;CACjD,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import * as Logger from "effect/Logger";
2
+ export declare const liveTraceLogger: Logger.Logger<unknown, void>;
3
+ //# sourceMappingURL=Logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../src/Logger.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAKxC,eAAO,MAAM,eAAe,8BAa1B,CAAC"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * LiveTraceLogger — Bridges Effect.log() → SpanEvent automatically.
3
+ *
4
+ * When inside a `withTrace()` or `step()` scope, this Logger reads
5
+ * the current WrappedSpan from LiveSpanRef and calls span.event()
6
+ * so the log message appears in the trace card's step event list.
7
+ *
8
+ * Outside a traced scope, this Logger is a no-op (other loggers
9
+ * like Logger.pretty still handle the log normally).
10
+ *
11
+ * Wire via `Logger.add(liveTraceLogger)` in the services layer.
12
+ */
13
+ import * as FiberRefs from "effect/FiberRefs";
14
+ import * as HashMap from "effect/HashMap";
15
+ import * as Logger from "effect/Logger";
16
+ import { LiveSpanRef } from "./LiveTrace.js";
17
+ import { isWrappedSpan } from "./WrappedSpan.js";
18
+ export const liveTraceLogger = Logger.make(({ message, logLevel, context: fiberRefs, annotations }) => {
19
+ const span = FiberRefs.getOrDefault(fiberRefs, LiveSpanRef);
20
+ if (!span || !isWrappedSpan(span))
21
+ return;
22
+ // Flatten message to string
23
+ const msg = Array.isArray(message) ? message.join(" ") : String(message);
24
+ const attrs = { "effect.logLevel": logLevel.label };
25
+ for (const [k, v] of HashMap.entries(annotations)) {
26
+ attrs[k] = v;
27
+ }
28
+ span.event(msg, BigInt(Date.now()) * 1000000n, attrs);
29
+ });
30
+ //# sourceMappingURL=Logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Logger.js","sourceRoot":"","sources":["../../src/Logger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,SAAS,MAAM,kBAAkB,CAAC;AAC9C,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,EAAE,EAAE;IAClG,MAAM,IAAI,GAAG,SAAS,CAAC,YAAY,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;IAC5D,IAAI,CAAC,IAAI,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC;QAAE,OAAO;IAE1C,4BAA4B;IAC5B,MAAM,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAEzE,MAAM,KAAK,GAA4B,EAAE,iBAAiB,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC;IAC7E,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC;QAChD,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IACjB,CAAC;IAED,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,GAAG,QAAU,EAAE,KAAK,CAAC,CAAC;AAC5D,CAAC,CAAC,CAAC"}
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Effect Schema wrappers for TraceEvent types.
3
+ *
4
+ * Used for runtime NDJSON validation. Optional — consumers
5
+ * can use plain types from "./types" if they don't need validation.
6
+ */
7
+ import * as Schema from "effect/Schema";
8
+ export declare const TraceScopeSchema: Schema.Struct<{
9
+ type: Schema.Literal<["team", "org", "user"]>;
10
+ id: typeof Schema.String;
11
+ }>;
12
+ export declare const TraceStartSchema: Schema.Struct<{
13
+ _tag: Schema.Literal<["TraceStart"]>;
14
+ traceId: typeof Schema.String;
15
+ label: typeof Schema.String;
16
+ scope: Schema.Struct<{
17
+ type: Schema.Literal<["team", "org", "user"]>;
18
+ id: typeof Schema.String;
19
+ }>;
20
+ timestamp: typeof Schema.Number;
21
+ }>;
22
+ export declare const SpanStartSchema: Schema.Struct<{
23
+ _tag: Schema.Literal<["SpanStart"]>;
24
+ traceId: typeof Schema.String;
25
+ spanId: typeof Schema.String;
26
+ parentSpanId: Schema.optional<typeof Schema.String>;
27
+ name: typeof Schema.String;
28
+ attributes: Schema.Record$<typeof Schema.String, typeof Schema.Unknown>;
29
+ timestamp: typeof Schema.Number;
30
+ }>;
31
+ export declare const SpanEndSchema: Schema.Struct<{
32
+ _tag: Schema.Literal<["SpanEnd"]>;
33
+ traceId: typeof Schema.String;
34
+ spanId: typeof Schema.String;
35
+ status: Schema.Literal<["ok", "error"]>;
36
+ durationMs: typeof Schema.Number;
37
+ timestamp: typeof Schema.Number;
38
+ }>;
39
+ export declare const SpanEventSchema: Schema.Struct<{
40
+ _tag: Schema.Literal<["SpanEvent"]>;
41
+ traceId: typeof Schema.String;
42
+ spanId: typeof Schema.String;
43
+ name: typeof Schema.String;
44
+ level: Schema.optional<Schema.Literal<["Debug", "Info", "Warning", "Error"]>>;
45
+ attributes: Schema.optional<Schema.Record$<typeof Schema.String, typeof Schema.Unknown>>;
46
+ timestamp: typeof Schema.Number;
47
+ }>;
48
+ export declare const TraceEndSchema: Schema.Struct<{
49
+ _tag: Schema.Literal<["TraceEnd"]>;
50
+ traceId: typeof Schema.String;
51
+ status: Schema.Literal<["completed", "failed"]>;
52
+ durationMs: typeof Schema.Number;
53
+ error: Schema.optional<typeof Schema.String>;
54
+ timestamp: typeof Schema.Number;
55
+ }>;
56
+ export declare const TraceEventSchema: Schema.Union<[Schema.Struct<{
57
+ _tag: Schema.Literal<["TraceStart"]>;
58
+ traceId: typeof Schema.String;
59
+ label: typeof Schema.String;
60
+ scope: Schema.Struct<{
61
+ type: Schema.Literal<["team", "org", "user"]>;
62
+ id: typeof Schema.String;
63
+ }>;
64
+ timestamp: typeof Schema.Number;
65
+ }>, Schema.Struct<{
66
+ _tag: Schema.Literal<["SpanStart"]>;
67
+ traceId: typeof Schema.String;
68
+ spanId: typeof Schema.String;
69
+ parentSpanId: Schema.optional<typeof Schema.String>;
70
+ name: typeof Schema.String;
71
+ attributes: Schema.Record$<typeof Schema.String, typeof Schema.Unknown>;
72
+ timestamp: typeof Schema.Number;
73
+ }>, Schema.Struct<{
74
+ _tag: Schema.Literal<["SpanEnd"]>;
75
+ traceId: typeof Schema.String;
76
+ spanId: typeof Schema.String;
77
+ status: Schema.Literal<["ok", "error"]>;
78
+ durationMs: typeof Schema.Number;
79
+ timestamp: typeof Schema.Number;
80
+ }>, Schema.Struct<{
81
+ _tag: Schema.Literal<["SpanEvent"]>;
82
+ traceId: typeof Schema.String;
83
+ spanId: typeof Schema.String;
84
+ name: typeof Schema.String;
85
+ level: Schema.optional<Schema.Literal<["Debug", "Info", "Warning", "Error"]>>;
86
+ attributes: Schema.optional<Schema.Record$<typeof Schema.String, typeof Schema.Unknown>>;
87
+ timestamp: typeof Schema.Number;
88
+ }>, Schema.Struct<{
89
+ _tag: Schema.Literal<["TraceEnd"]>;
90
+ traceId: typeof Schema.String;
91
+ status: Schema.Literal<["completed", "failed"]>;
92
+ durationMs: typeof Schema.Number;
93
+ error: Schema.optional<typeof Schema.String>;
94
+ timestamp: typeof Schema.Number;
95
+ }>]>;
96
+ export type TraceEventEncoded = Schema.Schema.Encoded<typeof TraceEventSchema>;
97
+ //# sourceMappingURL=Schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAMxC,eAAO,MAAM,gBAAgB;;;EAG3B,CAAC;AAMH,eAAO,MAAM,gBAAgB;;;;;;;;;EAM3B,CAAC;AAEH,eAAO,MAAM,eAAe;;;;;;;;EAQ1B,CAAC;AAEH,eAAO,MAAM,aAAa;;;;;;;EAOxB,CAAC;AAEH,eAAO,MAAM,eAAe;;;;;;;;EAQ1B,CAAC;AAEH,eAAO,MAAM,cAAc;;;;;;;EAOzB,CAAC;AAEH,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAAkG,CAAC;AAEhI,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,gBAAgB,CAAC,CAAC"}
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Effect Schema wrappers for TraceEvent types.
3
+ *
4
+ * Used for runtime NDJSON validation. Optional — consumers
5
+ * can use plain types from "./types" if they don't need validation.
6
+ */
7
+ import * as Schema from "effect/Schema";
8
+ // ============================================================================
9
+ // Scope
10
+ // ============================================================================
11
+ export const TraceScopeSchema = Schema.Struct({
12
+ type: Schema.Literal("team", "org", "user"),
13
+ id: Schema.String,
14
+ });
15
+ // ============================================================================
16
+ // Events
17
+ // ============================================================================
18
+ export const TraceStartSchema = Schema.Struct({
19
+ _tag: Schema.Literal("TraceStart"),
20
+ traceId: Schema.String,
21
+ label: Schema.String,
22
+ scope: TraceScopeSchema,
23
+ timestamp: Schema.Number,
24
+ });
25
+ export const SpanStartSchema = Schema.Struct({
26
+ _tag: Schema.Literal("SpanStart"),
27
+ traceId: Schema.String,
28
+ spanId: Schema.String,
29
+ parentSpanId: Schema.optional(Schema.String),
30
+ name: Schema.String,
31
+ attributes: Schema.Record({ key: Schema.String, value: Schema.Unknown }),
32
+ timestamp: Schema.Number,
33
+ });
34
+ export const SpanEndSchema = Schema.Struct({
35
+ _tag: Schema.Literal("SpanEnd"),
36
+ traceId: Schema.String,
37
+ spanId: Schema.String,
38
+ status: Schema.Literal("ok", "error"),
39
+ durationMs: Schema.Number,
40
+ timestamp: Schema.Number,
41
+ });
42
+ export const SpanEventSchema = Schema.Struct({
43
+ _tag: Schema.Literal("SpanEvent"),
44
+ traceId: Schema.String,
45
+ spanId: Schema.String,
46
+ name: Schema.String,
47
+ level: Schema.optional(Schema.Literal("Debug", "Info", "Warning", "Error")),
48
+ attributes: Schema.optional(Schema.Record({ key: Schema.String, value: Schema.Unknown })),
49
+ timestamp: Schema.Number,
50
+ });
51
+ export const TraceEndSchema = Schema.Struct({
52
+ _tag: Schema.Literal("TraceEnd"),
53
+ traceId: Schema.String,
54
+ status: Schema.Literal("completed", "failed"),
55
+ durationMs: Schema.Number,
56
+ error: Schema.optional(Schema.String),
57
+ timestamp: Schema.Number,
58
+ });
59
+ export const TraceEventSchema = Schema.Union(TraceStartSchema, SpanStartSchema, SpanEndSchema, SpanEventSchema, TraceEndSchema);
60
+ //# sourceMappingURL=Schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Schema.js","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,+EAA+E;AAC/E,QAAQ;AACR,+EAA+E;AAE/E,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC1C,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC;IAC3C,EAAE,EAAE,MAAM,CAAC,MAAM;CACpB,CAAC,CAAC;AAEH,+EAA+E;AAC/E,SAAS;AACT,+EAA+E;AAE/E,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC1C,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC;IAClC,OAAO,EAAE,MAAM,CAAC,MAAM;IACtB,KAAK,EAAE,MAAM,CAAC,MAAM;IACpB,KAAK,EAAE,gBAAgB;IACvB,SAAS,EAAE,MAAM,CAAC,MAAM;CAC3B,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC;IACzC,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC;IACjC,OAAO,EAAE,MAAM,CAAC,MAAM;IACtB,MAAM,EAAE,MAAM,CAAC,MAAM;IACrB,YAAY,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC;IAC5C,IAAI,EAAE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