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
package/src/types.ts ADDED
@@ -0,0 +1,151 @@
1
+ /**
2
+ * live-traces — Wire Format Types
3
+ *
4
+ * Plain TypeScript types with zero dependencies.
5
+ * Any backend (Go, Python, Rust, Node) can emit these as JSON
6
+ * and the React frontend will render them.
7
+ *
8
+ * Import from "live-traces/types" — no Effect required.
9
+ */
10
+
11
+ // ============================================================================
12
+ // Scope — routing target for trace events
13
+ // ============================================================================
14
+
15
+ export interface TraceScope {
16
+ readonly type: "team" | "org" | "user";
17
+ readonly id: string;
18
+ }
19
+
20
+ // ============================================================================
21
+ // Trace Events — discriminated union on _tag
22
+ // ============================================================================
23
+
24
+ export interface TraceStart {
25
+ readonly _tag: "TraceStart";
26
+ readonly traceId: string;
27
+ readonly label: string;
28
+ readonly scope: TraceScope;
29
+ readonly timestamp: number;
30
+ }
31
+
32
+ export interface SpanStart {
33
+ readonly _tag: "SpanStart";
34
+ readonly traceId: string;
35
+ readonly spanId: string;
36
+ readonly parentSpanId?: string | undefined;
37
+ readonly name: string;
38
+ readonly attributes: Record<string, unknown>;
39
+ readonly timestamp: number;
40
+ }
41
+
42
+ export interface SpanEnd {
43
+ readonly _tag: "SpanEnd";
44
+ readonly traceId: string;
45
+ readonly spanId: string;
46
+ readonly status: "ok" | "error";
47
+ readonly durationMs: number;
48
+ readonly timestamp: number;
49
+ }
50
+
51
+ export interface SpanEvent {
52
+ readonly _tag: "SpanEvent";
53
+ readonly traceId: string;
54
+ readonly spanId: string;
55
+ readonly name: string;
56
+ readonly level?: "Debug" | "Info" | "Warning" | "Error" | undefined;
57
+ readonly attributes?: Record<string, unknown> | undefined;
58
+ readonly timestamp: number;
59
+ }
60
+
61
+ export interface TraceEnd {
62
+ readonly _tag: "TraceEnd";
63
+ readonly traceId: string;
64
+ readonly status: "completed" | "failed";
65
+ readonly durationMs: number;
66
+ readonly error?: string | undefined;
67
+ readonly timestamp: number;
68
+ }
69
+
70
+ export type TraceEvent = TraceStart | SpanStart | SpanEnd | SpanEvent | TraceEnd;
71
+
72
+ // ============================================================================
73
+ // Factory helpers — plain functions, no Effect import
74
+ // ============================================================================
75
+
76
+ export const traceStart = (traceId: string, label: string, scope: TraceScope): TraceStart => ({
77
+ _tag: "TraceStart",
78
+ traceId,
79
+ label,
80
+ scope,
81
+ timestamp: Date.now(),
82
+ });
83
+
84
+ export const spanStart = (
85
+ traceId: string,
86
+ spanId: string,
87
+ name: string,
88
+ attributes: Record<string, unknown> = {},
89
+ parentSpanId?: string,
90
+ ): SpanStart => ({
91
+ _tag: "SpanStart",
92
+ traceId,
93
+ spanId,
94
+ parentSpanId,
95
+ name,
96
+ attributes,
97
+ timestamp: Date.now(),
98
+ });
99
+
100
+ export const spanEnd = (traceId: string, spanId: string, status: "ok" | "error", durationMs: number): SpanEnd => ({
101
+ _tag: "SpanEnd",
102
+ traceId,
103
+ spanId,
104
+ status,
105
+ durationMs,
106
+ timestamp: Date.now(),
107
+ });
108
+
109
+ export const spanEvent = (
110
+ traceId: string,
111
+ spanId: string,
112
+ name: string,
113
+ level?: "Debug" | "Info" | "Warning" | "Error",
114
+ attributes?: Record<string, unknown>,
115
+ ): SpanEvent => ({
116
+ _tag: "SpanEvent",
117
+ traceId,
118
+ spanId,
119
+ name,
120
+ level,
121
+ attributes,
122
+ timestamp: Date.now(),
123
+ });
124
+
125
+ export const traceEnd = (traceId: string, status: "completed" | "failed", durationMs: number, error?: string): TraceEnd => ({
126
+ _tag: "TraceEnd",
127
+ traceId,
128
+ status,
129
+ durationMs,
130
+ error,
131
+ timestamp: Date.now(),
132
+ });
133
+
134
+ // ============================================================================
135
+ // Attribute constants — use with Effect.withSpan
136
+ // ============================================================================
137
+
138
+ /** Mark a span as a user-visible step in the trace UI */
139
+ export const UI_STEP = "ui.step" as const;
140
+
141
+ /** Mark a span as internal (excluded from live trace capture) */
142
+ export const TRACE_INTERNAL = "trace.internal" as const;
143
+
144
+ /** Root marker — set automatically by LiveTrace.withTrace() */
145
+ export const LIVE_TRACE = "live-trace" as const;
146
+ export const LIVE_TRACE_ID = "live-trace.id" as const;
147
+ export const LIVE_TRACE_LABEL = "live-trace.label" as const;
148
+ export const LIVE_TRACE_SCOPE_TYPE = "live-trace.scope.type" as const;
149
+ export const LIVE_TRACE_SCOPE_ID = "live-trace.scope.id" as const;
150
+ /** Optional provider key for source/integration filtering (e.g. "notion", "google-drive") */
151
+ export const LIVE_TRACE_PROVIDER = "live-trace.provider" as const;