effect-inspect 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 (38) hide show
  1. package/README.md +122 -0
  2. package/app/dist/client/assets/index-smV05cfr.js +25 -0
  3. package/app/dist/client/assets/rolldown-runtime-CbXtAM7H.js +1 -0
  4. package/app/dist/client/assets/routes-TKgeFdSW.js +5 -0
  5. package/app/dist/client/assets/styles-B3rAZGvS.css +2 -0
  6. package/app/dist/server/assets/_tanstack-start-manifest_v-Co953HeC.js +20 -0
  7. package/app/dist/server/assets/empty-plugin-adapters-D9UWiqvJ.js +5 -0
  8. package/app/dist/server/assets/router-CN98Ramo.js +491 -0
  9. package/app/dist/server/assets/routes-eZ4XqxE9.js +3999 -0
  10. package/app/dist/server/assets/start-5Z2QO8AU.js +4 -0
  11. package/app/dist/server/server.js +1812 -0
  12. package/dist/cli.d.ts +3 -0
  13. package/dist/cli.js +29 -0
  14. package/dist/client/Client.d.ts +52 -0
  15. package/dist/client/Client.js +224 -0
  16. package/dist/client/Edge.d.ts +31 -0
  17. package/dist/client/Edge.js +108 -0
  18. package/dist/client/Inspect.d.ts +49 -0
  19. package/dist/client/Inspect.js +55 -0
  20. package/dist/client/Tracer.d.ts +31 -0
  21. package/dist/client/Tracer.js +119 -0
  22. package/dist/collector/Config.d.ts +8 -0
  23. package/dist/collector/Config.js +9 -0
  24. package/dist/collector/Server.d.ts +24 -0
  25. package/dist/collector/Server.js +172 -0
  26. package/dist/collector/Store.d.ts +86 -0
  27. package/dist/collector/Store.js +119 -0
  28. package/dist/collector/WebApp.d.ts +3 -0
  29. package/dist/collector/WebApp.js +36 -0
  30. package/dist/collector/main.d.ts +1 -0
  31. package/dist/collector/main.js +22 -0
  32. package/dist/index.d.ts +3 -0
  33. package/dist/index.js +3 -0
  34. package/dist/protocol/Codec.d.ts +575 -0
  35. package/dist/protocol/Codec.js +50 -0
  36. package/dist/protocol/Schema.d.ts +1237 -0
  37. package/dist/protocol/Schema.js +327 -0
  38. package/package.json +85 -0
package/README.md ADDED
@@ -0,0 +1,122 @@
1
+ # effect-inspect
2
+
3
+ A performance inspector for Effect programs. Add one layer to your app, open
4
+ localhost, and watch a live flame chart of its spans, events and logs.
5
+
6
+ Your program dials out to a long-lived **collector**, and the **webapp** reads
7
+ the trace back from it. The collector owns the history, so
8
+ restarting your program does not lose the trace.
9
+
10
+ The collector's history is in memory only, so restarting _the collector_ does
11
+ drop every trace it was holding. Save the ones you want to keep — see
12
+ [Saving and loading traces](#saving-and-loading-traces).
13
+
14
+ ## Quickstart
15
+
16
+ Install the package in an Effect project. The `effect-inspect` command runs on
17
+ Node.js 22 or newer and does not require Bun. The library import works in a
18
+ JavaScript runtime with a global `WebSocket` implementation.
19
+
20
+ ```bash
21
+ npm install effect-inspect effect
22
+ ```
23
+
24
+ Start the collector and bundled webapp, then open the URL it prints:
25
+
26
+ ```bash
27
+ npx effect-inspect start
28
+ # effect-inspect listening at http://localhost:34437
29
+ ```
30
+
31
+ Run your instrumented program in another terminal. The collector listens for
32
+ programs at `ws://localhost:34437/`. Run `npx effect-inspect --help` for
33
+ command help or `npx effect-inspect start --help` for start options.
34
+
35
+ When working from this repository, install its dependencies with `bun install`
36
+ and run an example:
37
+
38
+ ```bash
39
+ bun run example:webapp
40
+ ```
41
+
42
+ Its spans appear in the webapp within a second of being emitted. See
43
+ [`examples/README.md`](examples/README.md) for the other five and what each one
44
+ is worth looking at.
45
+
46
+ ## Instrumenting your own program
47
+
48
+ ```ts
49
+ import { Effect } from 'effect'
50
+ import { Inspect } from 'effect-inspect'
51
+
52
+ const program = Effect.gen(function* () {
53
+ yield* Effect.sleep('50 millis')
54
+ }).pipe(Effect.withSpan('my-work'))
55
+
56
+ Effect.runPromise(program.pipe(Effect.provide(Inspect.layer())))
57
+ ```
58
+
59
+ `Inspect.layer()` installs a tracer and a logger, so `Effect.withSpan`,
60
+ `Effect.annotateCurrentSpan` and `Effect.log*` all reach the collector. The
61
+ logger is merged with your existing ones, so console output is unchanged.
62
+
63
+ Options, all optional:
64
+
65
+ ```ts
66
+ Inspect.layer({
67
+ url: 'ws://localhost:34437', // where the collector listens
68
+ programName: 'my-service', // what the session list shows; defaults to the entry script's file name
69
+ bufferSize: 8192, // outbound queue, in messages
70
+ })
71
+ ```
72
+
73
+ ## Saving and loading traces
74
+
75
+ **save** in the header writes the selected session to a `.eitrace` file.
76
+ **open** — or dropping a file anywhere on the page — reads one back. A loaded
77
+ trace appears in the session list marked `file` and renders exactly like a live
78
+ one: chart, event log, filter and detail panel all work, and **no collector
79
+ needs to be running at all**.
80
+
81
+ The file is the protocol message stream itself — one JSON line per message,
82
+ with a small header carrying the session's clock — so a saved trace loses
83
+ nothing the live view had, and saving a loaded trace again is lossless.
84
+
85
+ This is also the answer to the collector's in-memory history: a trace you have
86
+ saved survives a collector restart, a machine restart, and being emailed to
87
+ someone else.
88
+
89
+ **Adding the layer is safe anywhere.** If no collector is listening, the program
90
+ runs exactly as it would have — no hang, no error, no delay. If the collector
91
+ goes away mid-run the program keeps going and reconnects in the background,
92
+ resuming the same session. If you outrun the socket, the oldest messages are
93
+ dropped and the gap is reported as a warning in the trace, rather than pushing
94
+ backpressure into your fibers.
95
+
96
+ The one consequence: when the collector is down you get silence, not an error.
97
+ The examples probe for it first and print a hint — worth copying if you hit
98
+ this while demoing.
99
+
100
+ ## Configuration
101
+
102
+ | Variable | Default | Effect |
103
+ | ------------------------- | -------- | -------------------------------------- |
104
+ | `EFFECT_INSPECT_PORT` | `34437` | Port the collector listens on |
105
+ | `EFFECT_INSPECT_CAPACITY` | `200000` | Messages the collector retains per run |
106
+
107
+ The collector serves both roles on one port, routed by path: programs dial
108
+ `ws://localhost:34437/`, the webapp `ws://localhost:34437/webapp`.
109
+
110
+ The installed command uses Node.js for its WebSocket server and bundled UI. The
111
+ library's `Inspect.layer()` uses the runtime's global `WebSocket`; use
112
+ `Inspect.layerWebSocket()` with a supplied Effect WebSocket constructor when
113
+ that global is unavailable.
114
+
115
+ ## Development
116
+
117
+ ```bash
118
+ bun run check # format, lint, typecheck — must pass before a commit
119
+ bun run check:write # auto-fix what it can
120
+ bun test src app # unit tests
121
+ bun run stub:collector # fake collector, for working on the webapp alone
122
+ ```