@timber-js/app 0.2.0-alpha.235 → 0.2.0-alpha.237
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/_chunks/{actions-CYjRMpZI.js → actions-Top9GftB.js} +3 -3
- package/dist/_chunks/{actions-CYjRMpZI.js.map → actions-Top9GftB.js.map} +1 -1
- package/dist/_chunks/{cache-api-BZJNt01a.js → cache-api-Bo8c7XVF.js} +6 -6
- package/dist/_chunks/{cache-api-BZJNt01a.js.map → cache-api-Bo8c7XVF.js.map} +1 -1
- package/dist/_chunks/{chains-D-RRc7CM.js → chains-BsGKkMTK.js} +2 -2
- package/dist/_chunks/{chains-D-RRc7CM.js.map → chains-BsGKkMTK.js.map} +1 -1
- package/dist/_chunks/chains-DHmoKxkO.js +1 -0
- package/dist/_chunks/{classify-_W0RWa5w.js → classify-cmE0Gins.js} +2 -2
- package/dist/_chunks/{classify-_W0RWa5w.js.map → classify-cmE0Gins.js.map} +1 -1
- package/dist/_chunks/{cli-check-Dl3yo3Zv.js → cli-check-BwiahbTC.js} +3 -3
- package/dist/_chunks/{cli-check-Dl3yo3Zv.js.map → cli-check-BwiahbTC.js.map} +1 -1
- package/dist/_chunks/{cli-schema-sync-CyrOHbAo.js → cli-schema-sync-B2ldclRO.js} +2 -2
- package/dist/_chunks/{cli-schema-sync-CyrOHbAo.js.map → cli-schema-sync-B2ldclRO.js.map} +1 -1
- package/dist/_chunks/{cli-schema-sync-CTWiBMZZ.js → cli-schema-sync-Brw7kTmm.js} +1 -1
- package/dist/_chunks/{client-dep-entries-C9hv-3k9.js → client-dep-entries-C1nMlLKV.js} +2 -2
- package/dist/_chunks/{client-dep-entries-C9hv-3k9.js.map → client-dep-entries-C1nMlLKV.js.map} +1 -1
- package/dist/_chunks/{cloudflare-_2fhxQE8.js → cloudflare-Dk5Hqo-O.js} +3 -3
- package/dist/_chunks/{cloudflare-_2fhxQE8.js.map → cloudflare-Dk5Hqo-O.js.map} +1 -1
- package/dist/_chunks/{convention-lint-D54k6uUM.js → convention-lint-CLpuzY5h.js} +3 -3
- package/dist/_chunks/{convention-lint-D54k6uUM.js.map → convention-lint-CLpuzY5h.js.map} +1 -1
- package/dist/_chunks/dev-server-BGGGhHXx.js +1 -0
- package/dist/_chunks/{dev-server-cmWVDgTf.js → dev-server-lrdpD7Ws.js} +121 -5
- package/dist/_chunks/dev-server-lrdpD7Ws.js.map +1 -0
- package/dist/_chunks/{dev-span-_NzMX-au.js → dev-span-RsVeYYc_.js} +5 -2
- package/dist/_chunks/dev-span-RsVeYYc_.js.map +1 -0
- package/dist/_chunks/{error-boundary-Cf1m-Ywk.js → error-boundary-Bh-egWUI.js} +6 -6
- package/dist/_chunks/{error-boundary-Cf1m-Ywk.js.map → error-boundary-Bh-egWUI.js.map} +1 -1
- package/dist/_chunks/{flight-source-node-BGanuoSS.js → flight-source-node-BsrlUjMO.js} +7 -3
- package/dist/_chunks/flight-source-node-BsrlUjMO.js.map +1 -0
- package/dist/_chunks/{href-BtspoNc9.js → href-8l5VD23D.js} +2 -2
- package/dist/_chunks/{href-BtspoNc9.js.map → href-8l5VD23D.js.map} +1 -1
- package/dist/_chunks/{json-lossy-check-BXM45k8p.js → json-lossy-check-D47R9Fp5.js} +2 -2
- package/dist/_chunks/{json-lossy-check-BXM45k8p.js.map → json-lossy-check-D47R9Fp5.js.map} +1 -1
- package/dist/_chunks/{live-graph-C7-yA8W9.js → live-graph-ChuFfmLi.js} +4 -4
- package/dist/_chunks/{live-graph-C7-yA8W9.js.map → live-graph-ChuFfmLi.js.map} +1 -1
- package/dist/_chunks/{logger-YtMSKfft.js → logger-DDLtp5e-.js} +16 -1
- package/dist/_chunks/logger-DDLtp5e-.js.map +1 -0
- package/dist/_chunks/navigation-root-Cvb7P1ud.js.map +1 -1
- package/dist/_chunks/{node-response-D3hXWb8y.js → node-response-omewa8e6.js} +21 -4
- package/dist/_chunks/node-response-omewa8e6.js.map +1 -0
- package/dist/_chunks/{poison-scan-CRSP06Es.js → poison-scan-CJ9QfJWb.js} +2 -2
- package/dist/_chunks/{poison-scan-CRSP06Es.js.map → poison-scan-CJ9QfJWb.js.map} +1 -1
- package/dist/_chunks/render-timeout-MrrqD1wd.js.map +1 -1
- package/dist/_chunks/{scanner-BNQ4qnLX.js → scanner-CrB_h6FA.js} +5 -5
- package/dist/_chunks/{scanner-BNQ4qnLX.js.map → scanner-CrB_h6FA.js.map} +1 -1
- package/dist/_chunks/{sizeof-Cmx6Fs-Y.js → sizeof-DVhEVN_y.js} +2 -2
- package/dist/_chunks/{sizeof-Cmx6Fs-Y.js.map → sizeof-DVhEVN_y.js.map} +1 -1
- package/dist/_chunks/{walkers-DFC9KsBL.js → walkers-BUvpsb2Q.js} +3 -3
- package/dist/_chunks/{walkers-DFC9KsBL.js.map → walkers-BUvpsb2Q.js.map} +1 -1
- package/dist/adapters/cloudflare-dev.js +1 -1
- package/dist/adapters/cloudflare-kv-cache.js +2 -2
- package/dist/adapters/cloudflare.js +1 -1
- package/dist/adapters/nitro.js +1 -1
- package/dist/analyze/crawl-entry.js +3 -3
- package/dist/analyze/graph-command.js +3 -3
- package/dist/cache/index.js +2 -2
- package/dist/cache/stores/memory.js +1 -1
- package/dist/cli.js +3 -3
- package/dist/client/dev-pill/index.d.ts +2 -1
- package/dist/client/dev-pill/index.d.ts.map +1 -1
- package/dist/client/dev-pill/view.d.ts.map +1 -1
- package/dist/client/error-boundary.js +1 -1
- package/dist/client/index.js +4 -4
- package/dist/client/internal.js +3 -3
- package/dist/cookies/index.js +1 -1
- package/dist/dev-tools/await-span.d.ts +7 -0
- package/dist/dev-tools/await-span.d.ts.map +1 -1
- package/dist/dev-tools/instrumentation.d.ts.map +1 -1
- package/dist/dev-tools/logger.d.ts +8 -2
- package/dist/dev-tools/logger.d.ts.map +1 -1
- package/dist/dev-tools/span-sink.d.ts +9 -1
- package/dist/dev-tools/span-sink.d.ts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +73 -31
- package/dist/index.js.map +1 -1
- package/dist/native/rsc/_react/chunks/{react-server-dom-webpack-server.node.development-hQ_odxIB.js → react-server-dom-webpack-server.node.development-CAttMzVD.js} +2 -2
- package/dist/native/rsc/_react/flight-client.js +2 -2
- package/dist/native/rsc/_react/flight-server.js +1 -1
- package/dist/native/rsc/_react/flight-static.js +1 -1
- package/dist/native/rsc/adapters/cloudflare-kv-cache.js +1 -1
- package/dist/native/rsc/adapters/cloudflare.js +2 -2
- package/dist/native/rsc/cache/cache-api.js +3 -3
- package/dist/native/rsc/cache/index.js +3 -3
- package/dist/native/rsc/cache/timber-cache.js +2 -2
- package/dist/native/rsc/cdn/index.js +1 -1
- package/dist/native/rsc/client/use-cookie.js +1 -1
- package/dist/native/rsc/dev-tools/404-page.js +1 -1
- package/dist/native/rsc/dev-tools/await-span.js +5 -2
- package/dist/native/rsc/dev-tools/await-span.js.map +1 -1
- package/dist/native/rsc/dev-tools/error-page.js +2 -2
- package/dist/native/rsc/dev-tools/instrumentation.js +38 -3
- package/dist/native/rsc/dev-tools/instrumentation.js.map +1 -1
- package/dist/native/rsc/dev-tools/logger.js +123 -80
- package/dist/native/rsc/dev-tools/logger.js.map +1 -1
- package/dist/native/rsc/dev-tools/span-sink.js +1 -0
- package/dist/native/rsc/dev-tools/span-sink.js.map +1 -1
- package/dist/native/rsc/dev-tools/terminal.js +1 -1
- package/dist/native/rsc/manifest.json +1 -0
- package/dist/native/rsc/params/index.js +1 -1
- package/dist/native/rsc/routing/collision-probe.js +1 -1
- package/dist/native/rsc/routing/interception.js +1 -1
- package/dist/native/rsc/search-params/define.js +2 -2
- package/dist/native/rsc/server/abort-scope.js +6 -2
- package/dist/native/rsc/server/abort-scope.js.map +1 -1
- package/dist/native/rsc/server/access-gate.js +1 -1
- package/dist/native/rsc/server/action-client.js +2 -2
- package/dist/native/rsc/server/action-handler.js +8 -8
- package/dist/native/rsc/server/actions.js +3 -3
- package/dist/native/rsc/server/children-interception.js +1 -1
- package/dist/native/rsc/server/deny-boundary.js +1 -1
- package/dist/native/rsc/server/deny-renderer.js +10 -10
- package/dist/native/rsc/server/fallback-error.js +1 -1
- package/dist/native/rsc/server/flight-injector-core.js +2 -2
- package/dist/native/rsc/server/flight-source-node.js +8 -4
- package/dist/native/rsc/server/flight-source-node.js.map +1 -1
- package/dist/native/rsc/server/index.js +4 -4
- package/dist/native/rsc/server/interception-gates.js +2 -2
- package/dist/native/rsc/server/internal.js +15 -15
- package/dist/native/rsc/server/logger.js +2 -2
- package/dist/native/rsc/server/metadata-route-links.js +1 -1
- package/dist/native/rsc/server/node-body-response.js +1 -1
- package/dist/native/rsc/server/param-coercion.js +1 -1
- package/dist/native/rsc/server/pipeline-helpers.js +11 -11
- package/dist/native/rsc/server/pipeline-helpers.js.map +1 -1
- package/dist/native/rsc/server/pipeline-interception.js +4 -4
- package/dist/native/rsc/server/pipeline-metadata-route.js +11 -11
- package/dist/native/rsc/server/pipeline-metadata-route.js.map +1 -1
- package/dist/native/rsc/server/pipeline-outcome.js +4 -4
- package/dist/native/rsc/server/pipeline-phases.js +11 -11
- package/dist/native/rsc/server/pipeline.js +10 -10
- package/dist/native/rsc/server/prebuilt/capture-render.js +1 -1
- package/dist/native/rsc/server/prebuilt/dev-store.js +1 -1
- package/dist/native/rsc/server/prebuilt/overlay.js +3 -3
- package/dist/native/rsc/server/prebuilt-builder.js +8 -8
- package/dist/native/rsc/server/prebuilt-runtime.js +15 -15
- package/dist/native/rsc/server/primitives.js +2 -2
- package/dist/native/rsc/server/publish-params.js +1 -1
- package/dist/native/rsc/server/render-timeout.js.map +1 -1
- package/dist/native/rsc/server/request-context.js +1 -1
- package/dist/native/rsc/server/route-element-builder.js +7 -7
- package/dist/native/rsc/server/route-element-helpers.js +1 -1
- package/dist/native/rsc/server/route-handler.js +1 -1
- package/dist/native/rsc/server/rsc-entry/action-dispatcher.js +1 -1
- package/dist/native/rsc/server/rsc-entry/action-middleware-runner.js +1 -1
- package/dist/native/rsc/server/rsc-entry/api-handler.js +1 -1
- package/dist/native/rsc/server/rsc-entry/deny-fallback.js +6 -6
- package/dist/native/rsc/server/rsc-entry/error-renderer.js +7 -7
- package/dist/native/rsc/server/rsc-entry/helpers.js +1 -1
- package/dist/native/rsc/server/rsc-entry/render-route.js +4 -4
- package/dist/native/rsc/server/rsc-entry/revalidate-renderer.js +7 -7
- package/dist/native/rsc/server/rsc-entry/rsc-payload.js +3 -3
- package/dist/native/rsc/server/rsc-entry/rsc-stream.js +6 -6
- package/dist/native/rsc/server/rsc-entry/ssr-renderer.js +10 -10
- package/dist/native/rsc/server/rsc-error-envelope.js +1 -1
- package/dist/native/rsc/server/safe-load.js +14 -2
- package/dist/native/rsc/server/safe-load.js.map +1 -1
- package/dist/native/rsc/server/sitemap-handler.js +1 -1
- package/dist/native/rsc/server/skippable-prefix.js +2 -2
- package/dist/native/rsc/server/slot-interception.js +1 -1
- package/dist/native/rsc/server/slot-resolver.js +11 -11
- package/dist/native/rsc/server/static-generator.js +2 -2
- package/dist/native/rsc/server/traced-access.js +1 -1
- package/dist/native/rsc/server/tracing.js +10 -0
- package/dist/native/rsc/server/tracing.js.map +1 -1
- package/dist/native/rsc/shared/dev-span.js +8 -2
- package/dist/native/rsc/shared/dev-span.js.map +1 -1
- package/dist/native/rsc/shared/href.js +1 -1
- package/dist/native/rsc/shared/span-waterfall.js +90 -0
- package/dist/native/rsc/shared/span-waterfall.js.map +1 -0
- package/dist/native/ssr/adapters/cloudflare-kv-cache.js +1 -1
- package/dist/native/ssr/adapters/cloudflare.js +2 -2
- package/dist/native/ssr/cache/cache-api.js +3 -3
- package/dist/native/ssr/cache/guarded-read.js +1 -1
- package/dist/native/ssr/cache/index.js +3 -3
- package/dist/native/ssr/cache/timber-cache.js +3 -3
- package/dist/native/ssr/cdn/index.js +1 -1
- package/dist/native/ssr/client/error-boundary.js +1 -1
- package/dist/native/ssr/client/index.js +5 -5
- package/dist/native/ssr/client/link.js +5 -5
- package/dist/native/ssr/client/navigation-commit.js +2 -2
- package/dist/native/ssr/client/nuqs-adapter.js +2 -2
- package/dist/native/ssr/client/params-context.js +1 -1
- package/dist/native/ssr/client/router-skew.js +1 -1
- package/dist/native/ssr/client/rsc-fetch.js +2 -2
- package/dist/native/ssr/client/use-pending-navigation.js +1 -1
- package/dist/native/ssr/client/use-search-params.js +2 -2
- package/dist/native/ssr/client/use-segment-params.js +1 -1
- package/dist/native/ssr/client/use-selected-layout-segment.js +1 -1
- package/dist/native/ssr/dev-tools/await-span.js +5 -2
- package/dist/native/ssr/dev-tools/await-span.js.map +1 -1
- package/dist/native/ssr/dev-tools/instrumentation.js +38 -3
- package/dist/native/ssr/dev-tools/instrumentation.js.map +1 -1
- package/dist/native/ssr/dev-tools/logger.js +123 -80
- package/dist/native/ssr/dev-tools/logger.js.map +1 -1
- package/dist/native/ssr/dev-tools/span-sink.js +1 -0
- package/dist/native/ssr/dev-tools/span-sink.js.map +1 -1
- package/dist/native/ssr/manifest.json +1 -0
- package/dist/native/ssr/params/index.js +1 -1
- package/dist/native/ssr/search-params/define.js +2 -2
- package/dist/native/ssr/server/abort-scope.js +6 -2
- package/dist/native/ssr/server/abort-scope.js.map +1 -1
- package/dist/native/ssr/server/access-gate.js +1 -1
- package/dist/native/ssr/server/action-client.js +2 -2
- package/dist/native/ssr/server/actions.js +3 -3
- package/dist/native/ssr/server/deny-boundary.js +2 -2
- package/dist/native/ssr/server/flight-injector-core.js +1 -1
- package/dist/native/ssr/server/flight-source-node.js +8 -4
- package/dist/native/ssr/server/flight-source-node.js.map +1 -1
- package/dist/native/ssr/server/index.js +4 -4
- package/dist/native/ssr/server/internal.js +12 -12
- package/dist/native/ssr/server/logger.js +2 -2
- package/dist/native/ssr/server/node-body-response.js +1 -1
- package/dist/native/ssr/server/node-stream-transforms.js +2 -2
- package/dist/native/ssr/server/param-coercion.js +3 -3
- package/dist/native/ssr/server/pipeline-helpers.js +8 -8
- package/dist/native/ssr/server/pipeline-helpers.js.map +1 -1
- package/dist/native/ssr/server/pipeline-interception.js +4 -4
- package/dist/native/ssr/server/pipeline-metadata-route.js +11 -11
- package/dist/native/ssr/server/pipeline-metadata-route.js.map +1 -1
- package/dist/native/ssr/server/pipeline-outcome.js +4 -4
- package/dist/native/ssr/server/pipeline-phases.js +10 -10
- package/dist/native/ssr/server/pipeline.js +10 -10
- package/dist/native/ssr/server/prebuilt/capture-render.js +2 -2
- package/dist/native/ssr/server/prebuilt/dev-store.js +1 -1
- package/dist/native/ssr/server/prebuilt/overlay.js +4 -4
- package/dist/native/ssr/server/prebuilt-runtime.js +14 -14
- package/dist/native/ssr/server/primitives.js +2 -2
- package/dist/native/ssr/server/render-timeout.js +3 -4
- package/dist/native/ssr/server/render-timeout.js.map +1 -1
- package/dist/native/ssr/server/request-context.js +2 -2
- package/dist/native/ssr/server/route-handler.js +1 -1
- package/dist/native/ssr/server/rsc-error-envelope.js +1 -1
- package/dist/native/ssr/server/safe-load.js +10 -1
- package/dist/native/ssr/server/safe-load.js.map +1 -1
- package/dist/native/ssr/server/ssr-form-state.js +2 -2
- package/dist/native/ssr/server/ssr-wrappers.js +1 -1
- package/dist/native/ssr/server/traced-access.js +1 -1
- package/dist/native/ssr/server/tracing.js +10 -0
- package/dist/native/ssr/server/tracing.js.map +1 -1
- package/dist/native/ssr/shared/dev-span.js +8 -2
- package/dist/native/ssr/shared/dev-span.js.map +1 -1
- package/dist/native/ssr/shared/href.js +1 -1
- package/dist/native/ssr/shared/span-waterfall.js +90 -0
- package/dist/native/ssr/shared/span-waterfall.js.map +1 -0
- package/dist/plugins/dev-precompile.d.ts +84 -0
- package/dist/plugins/dev-precompile.d.ts.map +1 -0
- package/dist/plugins/dev-server.d.ts.map +1 -1
- package/dist/plugins/entries.d.ts.map +1 -1
- package/dist/plugins/virtual-ids.d.ts +16 -0
- package/dist/plugins/virtual-ids.d.ts.map +1 -0
- package/dist/routes/index.js +1 -1
- package/dist/routing/index.js +3 -3
- package/dist/search-params/index.js +2 -2
- package/dist/server/abort-scope.d.ts +7 -0
- package/dist/server/abort-scope.d.ts.map +1 -1
- package/dist/server/flight-source-node.d.ts.map +1 -1
- package/dist/server/index.js +2 -2
- package/dist/server/internal.js +57 -17
- package/dist/server/internal.js.map +1 -1
- package/dist/server/render-timeout.d.ts.map +1 -1
- package/dist/server/rsc-entry/index.d.ts.map +1 -1
- package/dist/server/safe-load.d.ts +22 -0
- package/dist/server/safe-load.d.ts.map +1 -1
- package/dist/server/tracing.d.ts.map +1 -1
- package/dist/shared/dev-span.d.ts +12 -1
- package/dist/shared/dev-span.d.ts.map +1 -1
- package/dist/shared/span-waterfall.d.ts +88 -0
- package/dist/shared/span-waterfall.d.ts.map +1 -0
- package/package.json +2 -2
- package/src/client/dev-pill/index.ts +5 -2
- package/src/client/dev-pill/store.ts +1 -1
- package/src/client/dev-pill/view.ts +15 -5
- package/src/dev-tools/await-span.ts +10 -0
- package/src/dev-tools/instrumentation.ts +44 -6
- package/src/dev-tools/logger.ts +230 -155
- package/src/dev-tools/span-sink.ts +34 -3
- package/src/index.ts +21 -11
- package/src/plugins/dev-precompile.ts +168 -0
- package/src/plugins/dev-server.ts +16 -3
- package/src/plugins/entries.ts +1 -11
- package/src/plugins/virtual-ids.ts +15 -0
- package/src/server/abort-scope.ts +20 -1
- package/src/server/flight-source-node.ts +11 -2
- package/src/server/pipeline-helpers.ts +2 -2
- package/src/server/pipeline-metadata-route.ts +2 -2
- package/src/server/render-timeout.ts +8 -5
- package/src/server/rsc-entry/index.ts +5 -0
- package/src/server/safe-load.ts +53 -1
- package/src/server/tracing.ts +29 -0
- package/src/shared/dev-span.ts +17 -2
- package/src/{client/dev-pill/waterfall.ts → shared/span-waterfall.ts} +84 -51
- package/dist/_chunks/chains-KblEfYzm.js +0 -1
- package/dist/_chunks/dev-server-DrYBIg66.js +0 -1
- package/dist/_chunks/dev-server-cmWVDgTf.js.map +0 -1
- package/dist/_chunks/dev-span-_NzMX-au.js.map +0 -1
- package/dist/_chunks/flight-source-node-BGanuoSS.js.map +0 -1
- package/dist/_chunks/logger-YtMSKfft.js.map +0 -1
- package/dist/_chunks/node-response-D3hXWb8y.js.map +0 -1
- package/dist/client/dev-pill/waterfall.d.ts +0 -64
- package/dist/client/dev-pill/waterfall.d.ts.map +0 -1
package/src/dev-tools/logger.ts
CHANGED
|
@@ -5,8 +5,9 @@
|
|
|
5
5
|
* the single source of truth — no separate event system needed.
|
|
6
6
|
*
|
|
7
7
|
* Supports five modes:
|
|
8
|
-
* - tree (default) — indented tree per request
|
|
9
|
-
*
|
|
8
|
+
* - tree (default) — indented tree per request; explained waits hidden,
|
|
9
|
+
* pass-through awaits folded (the dev pill's reading rules)
|
|
10
|
+
* - verbose — the same tree with every span as is
|
|
10
11
|
* - summary — one line per request
|
|
11
12
|
* - json — chronological NDJSON dump of all spans
|
|
12
13
|
* - quiet — no output
|
|
@@ -18,7 +19,14 @@ import { STATUS_CODES } from 'node:http';
|
|
|
18
19
|
import type { InspectColor } from 'node:util';
|
|
19
20
|
import { styleText } from 'node:util';
|
|
20
21
|
import type { ReadableSpan } from '@opentelemetry/sdk-trace-base';
|
|
21
|
-
import {
|
|
22
|
+
import {
|
|
23
|
+
AWAIT_SPAN_NAME,
|
|
24
|
+
devSpanLabel,
|
|
25
|
+
FETCH_BODY_SPAN_NAME,
|
|
26
|
+
FETCH_SPAN_NAME,
|
|
27
|
+
ROOT_SPAN_NAME,
|
|
28
|
+
} from '../shared/dev-span.ts';
|
|
29
|
+
import { buildWaterfall, type WaterfallRow, type WaterfallSpan } from '../shared/span-waterfall.ts';
|
|
22
30
|
|
|
23
31
|
// ─── Configuration ──────────────────────────────────────────────────────────
|
|
24
32
|
|
|
@@ -74,112 +82,106 @@ function relativeMs(time: HrTime, rootStart: HrTime): number {
|
|
|
74
82
|
return hrTimeToMs(time) - hrTimeToMs(rootStart);
|
|
75
83
|
}
|
|
76
84
|
|
|
77
|
-
// ─── Span →
|
|
85
|
+
// ─── Span → Rows ────────────────────────────────────────────────────────────
|
|
78
86
|
|
|
79
|
-
/**
|
|
80
|
-
|
|
81
|
-
return devSpanLabel(span.name, span.attributes);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// ─── Tree Node ──────────────────────────────────────────────────────────────
|
|
85
|
-
|
|
86
|
-
interface SpanTreeNode {
|
|
87
|
+
/** An OTEL span as the shared waterfall rules read it. */
|
|
88
|
+
interface LogSpan extends WaterfallSpan {
|
|
87
89
|
span: ReadableSpan;
|
|
88
|
-
children: SpanTreeNode[];
|
|
89
90
|
}
|
|
90
91
|
|
|
91
|
-
/**
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
if (!root) return { root: null, children: [] };
|
|
100
|
-
|
|
101
|
-
// Index spans by spanId for parent lookup
|
|
102
|
-
const bySpanId = new Map<string, SpanTreeNode>();
|
|
103
|
-
for (const span of spans) {
|
|
104
|
-
if (span === root) continue;
|
|
105
|
-
bySpanId.set(span.spanContext().spanId, { span, children: [] });
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// Build parent-child relationships
|
|
109
|
-
const rootChildren: SpanTreeNode[] = [];
|
|
110
|
-
for (const node of bySpanId.values()) {
|
|
111
|
-
const parentId = node.span.parentSpanContext?.spanId;
|
|
112
|
-
if (parentId === root.spanContext().spanId) {
|
|
113
|
-
rootChildren.push(node);
|
|
114
|
-
} else if (parentId && bySpanId.has(parentId)) {
|
|
115
|
-
bySpanId.get(parentId)!.children.push(node);
|
|
116
|
-
} else {
|
|
117
|
-
// Orphan — attach to root
|
|
118
|
-
rootChildren.push(node);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// Sort children by start time
|
|
123
|
-
const sortByStart = (a: SpanTreeNode, b: SpanTreeNode) =>
|
|
124
|
-
hrTimeToMs(a.span.startTime) - hrTimeToMs(b.span.startTime);
|
|
125
|
-
|
|
126
|
-
rootChildren.sort(sortByStart);
|
|
127
|
-
for (const node of bySpanId.values()) {
|
|
128
|
-
node.children.sort(sortByStart);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// Post-process: re-parent layout/page spans into a nested chain.
|
|
132
|
-
// React's concurrent rendering breaks OTEL parent chains — all layout/page
|
|
133
|
-
// spans end up as direct children of timber.render. Re-nest them based on
|
|
134
|
-
// start-time order to reflect the segment hierarchy.
|
|
135
|
-
for (const node of bySpanId.values()) {
|
|
136
|
-
if (node.span.name !== 'timber.render') continue;
|
|
137
|
-
reNestLayoutPageSpans(node);
|
|
92
|
+
/** Items by key, keys in first-seen order. (`Map.groupBy` is ES2024.) */
|
|
93
|
+
function groupBy<T, K>(items: readonly T[], keyOf: (item: T) => K): Map<K, T[]> {
|
|
94
|
+
const groups = new Map<K, T[]>();
|
|
95
|
+
for (const item of items) {
|
|
96
|
+
const key = keyOf(item);
|
|
97
|
+
const group = groups.get(key);
|
|
98
|
+
if (group) group.push(item);
|
|
99
|
+
else groups.set(key, [item]);
|
|
138
100
|
}
|
|
139
|
-
|
|
140
|
-
return { root, children: rootChildren };
|
|
101
|
+
return groups;
|
|
141
102
|
}
|
|
142
103
|
|
|
104
|
+
const LAYOUT = 'timber.layout';
|
|
105
|
+
const PAGE = 'timber.page';
|
|
106
|
+
|
|
143
107
|
/**
|
|
144
|
-
*
|
|
108
|
+
* Project the trace's spans for `buildWaterfall()`, with the parent links
|
|
109
|
+
* the tree should draw:
|
|
145
110
|
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
111
|
+
* - A span whose parent isn't in the trace hangs off the root.
|
|
112
|
+
* - Layout and page spans under a render are re-nested by segment. React's
|
|
113
|
+
* concurrent rendering breaks OTEL parent chains, so they all arrive as
|
|
114
|
+
* direct children of `timber.render`. The main route's layouts form a
|
|
115
|
+
* chain in start order, and its page hangs off the last one. Each parallel
|
|
116
|
+
* slot (`timber.slot`) is its own chain under that same layout: slots
|
|
117
|
+
* render beside the page, not inside each other. Which layout owns a slot
|
|
118
|
+
* isn't recorded, so a slot of an outer layout draws under the innermost
|
|
119
|
+
* one. Other render children (access gates, metadata) stay where they are.
|
|
153
120
|
*/
|
|
154
|
-
function
|
|
155
|
-
const
|
|
156
|
-
const
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
121
|
+
function toLogSpans(spans: ReadableSpan[], root: ReadableSpan): LogSpan[] {
|
|
122
|
+
const rootId = root.spanContext().spanId;
|
|
123
|
+
const ids = new Set(spans.map((s) => s.spanContext().spanId));
|
|
124
|
+
const nodes = spans.map((span): LogSpan => {
|
|
125
|
+
const parent = span.parentSpanContext?.spanId;
|
|
126
|
+
return {
|
|
127
|
+
span,
|
|
128
|
+
spanId: span.spanContext().spanId,
|
|
129
|
+
parentSpanId: span === root ? undefined : parent && ids.has(parent) ? parent : rootId,
|
|
130
|
+
name: span.name,
|
|
131
|
+
startMs: hrTimeToMs(span.startTime),
|
|
132
|
+
endMs: hrTimeToMs(span.endTime),
|
|
133
|
+
attributes: span.attributes,
|
|
134
|
+
};
|
|
135
|
+
});
|
|
136
|
+
for (const render of nodes) {
|
|
137
|
+
if (render.name !== 'timber.render') continue;
|
|
138
|
+
const segments = nodes
|
|
139
|
+
.filter((n) => n.parentSpanId === render.spanId && (n.name === LAYOUT || n.name === PAGE))
|
|
140
|
+
.sort((a, b) => a.startMs - b.startMs);
|
|
141
|
+
// Main route first (slot ''), so slots have its innermost layout to hang off.
|
|
142
|
+
const bySlot = groupBy(segments, (n) => String(n.attributes['timber.slot'] ?? ''));
|
|
143
|
+
let mainLayout = render.spanId;
|
|
144
|
+
for (const slot of ['', ...[...bySlot.keys()].filter((k) => k !== '')]) {
|
|
145
|
+
let parent = slot === '' ? render.spanId : mainLayout;
|
|
146
|
+
for (const node of bySlot.get(slot) ?? []) {
|
|
147
|
+
node.parentSpanId = parent;
|
|
148
|
+
if (node.name === LAYOUT) parent = node.spanId;
|
|
149
|
+
}
|
|
150
|
+
if (slot === '') mainLayout = parent;
|
|
164
151
|
}
|
|
165
152
|
}
|
|
153
|
+
return nodes;
|
|
154
|
+
}
|
|
166
155
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
156
|
+
/**
|
|
157
|
+
* Tree connectors for rows in tree order: each row's `├─`/`└─` and the rails
|
|
158
|
+
* of its ancestors. A row is its parent's last child when no sibling follows
|
|
159
|
+
* before the tree climbs back above it.
|
|
160
|
+
*/
|
|
161
|
+
function treeConnectors<T>(
|
|
162
|
+
items: readonly T[],
|
|
163
|
+
depthOf: (item: T) => number
|
|
164
|
+
): Array<{ item: T; prefix: string; connector: string }> {
|
|
165
|
+
const siblingBelow: boolean[] = [];
|
|
166
|
+
const isLast = [...items]
|
|
167
|
+
.reverse()
|
|
168
|
+
.map((item) => {
|
|
169
|
+
const d = depthOf(item);
|
|
170
|
+
const last = !siblingBelow[d];
|
|
171
|
+
siblingBelow[d] = true;
|
|
172
|
+
siblingBelow.length = d + 1;
|
|
173
|
+
return last;
|
|
174
|
+
})
|
|
175
|
+
.reverse();
|
|
176
|
+
const ancestorIsLast: boolean[] = [];
|
|
177
|
+
return items.map((item, i) => {
|
|
178
|
+
const d = depthOf(item);
|
|
179
|
+
let prefix = '';
|
|
180
|
+
for (let level = 0; level < d; level++) prefix += ancestorIsLast[level] ? ' ' : '│ ';
|
|
181
|
+
const last = isLast[i] === true;
|
|
182
|
+
ancestorIsLast[d] = last;
|
|
183
|
+
return { item, prefix, connector: last ? '└─' : '├─' };
|
|
184
|
+
});
|
|
183
185
|
}
|
|
184
186
|
|
|
185
187
|
// ─── Log Mode Resolution ────────────────────────────────────────────────────
|
|
@@ -200,11 +202,39 @@ export function resolveLogMode(config?: DevLoggerConfig): DevLogMode {
|
|
|
200
202
|
|
|
201
203
|
/**
|
|
202
204
|
* Format spans as a full indented tree string for stderr.
|
|
205
|
+
*
|
|
206
|
+
* Tree mode applies the dev pill's reading rules (shared/span-waterfall.ts):
|
|
207
|
+
* waits whose work other rows already show are left out, and an await that
|
|
208
|
+
* only wraps one other await or fetch folds into it. Verbose mode prints
|
|
209
|
+
* every span as is.
|
|
203
210
|
*/
|
|
204
211
|
export function formatSpanTree(spans: ReadableSpan[], config?: DevLoggerConfig): string {
|
|
205
212
|
const slowPhaseMs = config?.slowPhaseMs ?? 200;
|
|
206
|
-
const
|
|
213
|
+
const root = spans.find((s) => s.name === ROOT_SPAN_NAME);
|
|
207
214
|
if (!root) return '';
|
|
215
|
+
const readable = config?.mode !== 'verbose';
|
|
216
|
+
const logSpans = toLogSpans(spans, root);
|
|
217
|
+
// Body reads are drawn on their fetch's line, not as rows of their own.
|
|
218
|
+
const bodies = groupBy(
|
|
219
|
+
logSpans.filter((s) => s.name === FETCH_BODY_SPAN_NAME),
|
|
220
|
+
(s) => s.parentSpanId
|
|
221
|
+
);
|
|
222
|
+
const { rows, hiddenWaits } = buildWaterfall(logSpans, {
|
|
223
|
+
hideWaits: readable,
|
|
224
|
+
fold: readable,
|
|
225
|
+
// The root is the header line, not a row: anything folded into it would
|
|
226
|
+
// vanish. Codex review on #1290.
|
|
227
|
+
expanded: new Set([root.spanContext().spanId]),
|
|
228
|
+
skip: (s) =>
|
|
229
|
+
s.name === FETCH_BODY_SPAN_NAME ||
|
|
230
|
+
// A layout or page that returned at once says nothing; its children
|
|
231
|
+
// take its place. Unless it carries events (a cache HIT/MISS): those
|
|
232
|
+
// print under its own row. Codex review on #1290.
|
|
233
|
+
(readable &&
|
|
234
|
+
(s.name === LAYOUT || s.name === PAGE) &&
|
|
235
|
+
s.endMs - s.startMs < 1 &&
|
|
236
|
+
s.span.events.length === 0),
|
|
237
|
+
});
|
|
208
238
|
|
|
209
239
|
const rootStart = root.startTime;
|
|
210
240
|
const lines: string[] = [];
|
|
@@ -225,10 +255,10 @@ export function formatSpanTree(spans: ReadableSpan[], config?: DevLoggerConfig):
|
|
|
225
255
|
lines.push(`${colorMethod(method)} ${style('bold', path)} ${dimTrace}`);
|
|
226
256
|
}
|
|
227
257
|
|
|
228
|
-
//
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
258
|
+
// The root is the header line; everything else is at least one level in.
|
|
259
|
+
const body = rows.filter((r) => r.span.span !== root);
|
|
260
|
+
for (const { item, prefix, connector } of treeConnectors(body, (r) => r.depth - 1)) {
|
|
261
|
+
formatRow(item, lines, prefix, connector, bodies, slowPhaseMs, rootStart);
|
|
232
262
|
}
|
|
233
263
|
|
|
234
264
|
// Result line
|
|
@@ -244,26 +274,37 @@ export function formatSpanTree(spans: ReadableSpan[], config?: DevLoggerConfig):
|
|
|
244
274
|
? style('dim', ` (caused by deny(${denyInfo}) inside Suspense — status already committed)`)
|
|
245
275
|
: '';
|
|
246
276
|
|
|
277
|
+
// Say what tree mode left out, and how to see it.
|
|
278
|
+
const folded = body.reduce((n, r) => n + r.folded.length, 0);
|
|
279
|
+
const omitted = [
|
|
280
|
+
hiddenWaits > 0 ? `${hiddenWaits} wait${hiddenWaits === 1 ? '' : 's'} hidden` : '',
|
|
281
|
+
folded > 0 ? `${folded} await${folded === 1 ? '' : 's'} folded` : '',
|
|
282
|
+
].filter(Boolean);
|
|
283
|
+
const omittedNote =
|
|
284
|
+
omitted.length > 0 ? style('dim', ` · ${omitted.join(', ')} (TIMBER_DEV_LOG=verbose)`) : '';
|
|
285
|
+
|
|
247
286
|
lines.push(
|
|
248
|
-
`${style(statusFmt, `└─ ✓ ${statusText}`)}${style('dim', ` total ${totalMs}ms`)}${denyNote}`
|
|
287
|
+
`${style(statusFmt, `└─ ✓ ${statusText}`)}${style('dim', ` total ${totalMs}ms`)}${denyNote}${omittedNote}`
|
|
249
288
|
);
|
|
250
289
|
|
|
251
290
|
return lines.join('\n') + '\n';
|
|
252
291
|
}
|
|
253
292
|
|
|
293
|
+
/** A fetch line's times: the row's interval, plus the body read after it. */
|
|
294
|
+
interface FetchTiming {
|
|
295
|
+
startMs: number;
|
|
296
|
+
endMs: number;
|
|
297
|
+
durationMs: number;
|
|
298
|
+
/** Time spent reading the body, 0 when it was never read or took <1ms. */
|
|
299
|
+
bodyMs: number;
|
|
300
|
+
}
|
|
301
|
+
|
|
254
302
|
/**
|
|
255
303
|
* Format a fetch span line with method, URL, timing, duration, and cache status.
|
|
256
304
|
*
|
|
257
|
-
* Output: `├─ fetch GET https://api.example.com/data 12ms →
|
|
305
|
+
* Output: `├─ fetch GET https://api.example.com/data 12ms → 140ms (77ms + 51ms body) [cdn: HIT]`
|
|
258
306
|
*/
|
|
259
|
-
function formatFetchLine(
|
|
260
|
-
span: ReadableSpan,
|
|
261
|
-
prefix: string,
|
|
262
|
-
connector: string,
|
|
263
|
-
startMs: number,
|
|
264
|
-
endMs: number,
|
|
265
|
-
durationMs: number
|
|
266
|
-
): string {
|
|
307
|
+
function formatFetchLine(span: ReadableSpan, lead: string, timing: FetchTiming): string {
|
|
267
308
|
const method = String(span.attributes['http.request.method'] ?? 'GET');
|
|
268
309
|
const url = String(span.attributes['http.url'] ?? '');
|
|
269
310
|
const statusCode = span.attributes['http.response.status_code'] as number | undefined;
|
|
@@ -271,8 +312,10 @@ function formatFetchLine(
|
|
|
271
312
|
const fetchError = span.attributes['timber.fetch_error'] as string | undefined;
|
|
272
313
|
const isError = span.status.code === 2; // SpanStatusCode.ERROR
|
|
273
314
|
|
|
274
|
-
|
|
275
|
-
|
|
315
|
+
const { startMs, endMs, durationMs, bodyMs } = timing;
|
|
316
|
+
const body = bodyMs > 0 ? ` + ${bodyMs}ms body` : '';
|
|
317
|
+
let line = `${lead}${style('dim', `fetch ${method}`)} ${url}`;
|
|
318
|
+
line += ` ${style('dim', `${startMs}ms → ${endMs}ms (${durationMs}ms${body})`)}`;
|
|
276
319
|
|
|
277
320
|
if (cacheStatus) {
|
|
278
321
|
line += ` ${style('dim', `[cdn: ${cacheStatus}]`)}`;
|
|
@@ -288,53 +331,91 @@ function formatFetchLine(
|
|
|
288
331
|
return line;
|
|
289
332
|
}
|
|
290
333
|
|
|
334
|
+
/** An access gate's result from its span: ` → DENY 403 (app/admin/access.ts)`. */
|
|
335
|
+
function accessOutcome(span: ReadableSpan): string {
|
|
336
|
+
const result = span.attributes['timber.result'] as string | undefined;
|
|
337
|
+
if (!result) return '';
|
|
338
|
+
const status = span.attributes['timber.deny_status'] as number | undefined;
|
|
339
|
+
const denyFile = span.attributes['timber.deny_file'] as string | undefined;
|
|
340
|
+
return ` → ${result.toUpperCase()}${status ? ` ${status}` : ''}${denyFile ? ` (${denyFile})` : ''}`;
|
|
341
|
+
}
|
|
342
|
+
|
|
291
343
|
/**
|
|
292
|
-
* Format
|
|
344
|
+
* Format one row: its line, then its cache annotations.
|
|
345
|
+
*
|
|
346
|
+
* A folded row keeps the outer span's interval, which is the code that asked
|
|
347
|
+
* for the work, and reads as the fetch when the chain ends in one, since
|
|
348
|
+
* that is the I/O. Otherwise it reads as the outer span. Cache events from
|
|
349
|
+
* every span in the row are kept.
|
|
293
350
|
*/
|
|
294
|
-
function
|
|
295
|
-
|
|
351
|
+
function formatRow(
|
|
352
|
+
row: WaterfallRow<LogSpan>,
|
|
296
353
|
lines: string[],
|
|
297
354
|
prefix: string,
|
|
298
|
-
|
|
355
|
+
connector: string,
|
|
356
|
+
bodies: ReadonlyMap<string | undefined, readonly LogSpan[]>,
|
|
299
357
|
slowPhaseMs: number,
|
|
300
358
|
rootStart: HrTime
|
|
301
359
|
): void {
|
|
302
|
-
const
|
|
303
|
-
const
|
|
304
|
-
const
|
|
305
|
-
const
|
|
306
|
-
const
|
|
360
|
+
const childPrefix = prefix + (connector === '└─' ? ' ' : '│ ');
|
|
361
|
+
const outer = row.span.span;
|
|
362
|
+
const chain = [row.span, ...row.folded];
|
|
363
|
+
const leaf = row.folded.at(-1);
|
|
364
|
+
const startMs = Math.round(relativeMs(outer.startTime, rootStart));
|
|
365
|
+
const endMs = Math.round(relativeMs(outer.endTime, rootStart));
|
|
307
366
|
const durationMs = endMs - startMs;
|
|
308
|
-
const
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
const
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
if (
|
|
322
|
-
const
|
|
323
|
-
const
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
367
|
+
const slow = (text: string) => (durationMs > slowPhaseMs ? style('yellow', text) : text);
|
|
368
|
+
const envTag = (span: ReadableSpan) =>
|
|
369
|
+
`${style('cyan', `[${devSpanLabel(span.name, span.attributes).env}]`)} `;
|
|
370
|
+
|
|
371
|
+
// A framework span folded into its await keeps both names:
|
|
372
|
+
// `[proxy] proxy.ts → await next()`.
|
|
373
|
+
const frame =
|
|
374
|
+
outer.name !== AWAIT_SPAN_NAME && row.folded.length > 0
|
|
375
|
+
? `${envTag(outer)}${slow(devSpanLabel(outer.name, outer.attributes).label)} → `
|
|
376
|
+
: '';
|
|
377
|
+
const lead = `${prefix}${connector} ${frame}`;
|
|
378
|
+
const outcome = accessOutcome(outer);
|
|
379
|
+
|
|
380
|
+
if (leaf?.name === FETCH_SPAN_NAME || outer.name === FETCH_SPAN_NAME) {
|
|
381
|
+
const fetch = leaf?.name === FETCH_SPAN_NAME ? leaf : row.span;
|
|
382
|
+
const reads = bodies.get(fetch.spanId) ?? [];
|
|
383
|
+
// The reads' own time: work the app did between headers and reading
|
|
384
|
+
// the body is not body time. Codex review on #1290.
|
|
385
|
+
const bodyMs = Math.round(reads.reduce((ms, r) => ms + (r.endMs - r.startMs), 0));
|
|
386
|
+
const lastRead = reads.reduce<ReadableSpan | undefined>(
|
|
387
|
+
(last, r) => (last && hrTimeToMs(last.endTime) >= r.endMs ? last : r.span),
|
|
388
|
+
undefined
|
|
389
|
+
);
|
|
390
|
+
const end = lastRead
|
|
391
|
+
? Math.max(endMs, Math.round(relativeMs(lastRead.endTime, rootStart)))
|
|
392
|
+
: endMs;
|
|
393
|
+
// An access gate that folded into its fetch keeps its outcome. Codex
|
|
394
|
+
// review on #1290.
|
|
395
|
+
// The row keeps the outer interval, but the parenthesized time is the
|
|
396
|
+
// fetch's own: an outer loader's duration already includes the body read,
|
|
397
|
+
// so adding `+ body` to it counted the body twice. Codex review on #1290.
|
|
398
|
+
const fetchLine = formatFetchLine(fetch.span, lead, {
|
|
399
|
+
startMs,
|
|
400
|
+
endMs: end,
|
|
401
|
+
durationMs: Math.round(fetch.endMs - fetch.startMs),
|
|
402
|
+
bodyMs,
|
|
403
|
+
});
|
|
404
|
+
lines.push(outcome ? `${fetchLine}${style('dim', outcome)}` : fetchLine);
|
|
405
|
+
} else {
|
|
406
|
+
const timing = `${startMs}ms → ${endMs}ms${outcome}`;
|
|
407
|
+
// The row reads as its first await, the code that asked for the work.
|
|
408
|
+
// An await's label already starts with `await`; a tag would say it twice.
|
|
409
|
+
const named = (frame ? row.folded[0] : row.span)?.span ?? outer;
|
|
410
|
+
const { label } = devSpanLabel(named.name, named.attributes);
|
|
411
|
+
const tag = frame || named.name === AWAIT_SPAN_NAME ? '' : envTag(named);
|
|
412
|
+
lines.push(`${lead}${tag}${frame ? label : slow(label)} ${style('dim', timing)}`);
|
|
328
413
|
}
|
|
329
414
|
|
|
330
|
-
const styledLabel = isSlow ? style('yellow', label) : label;
|
|
331
|
-
const envTag = style('cyan', `[${env}]`);
|
|
332
|
-
const line = `${prefix}${connector} ${envTag} ${styledLabel} ${style('dim', timing)}`;
|
|
333
|
-
lines.push(line);
|
|
334
|
-
|
|
335
415
|
// Span events (cache hits/misses) as child annotations
|
|
336
|
-
for (const
|
|
337
|
-
|
|
416
|
+
for (const { span } of chain) {
|
|
417
|
+
for (const event of span.events) {
|
|
418
|
+
if (event.name !== 'timber.cache.hit' && event.name !== 'timber.cache.miss') continue;
|
|
338
419
|
const key = String(event.attributes?.['key'] ?? '');
|
|
339
420
|
const hitMiss = event.name === 'timber.cache.hit' ? 'HIT' : 'MISS';
|
|
340
421
|
const durMs = event.attributes?.['duration_ms'] as number | undefined;
|
|
@@ -345,12 +426,6 @@ function formatSpanNode(
|
|
|
345
426
|
);
|
|
346
427
|
}
|
|
347
428
|
}
|
|
348
|
-
|
|
349
|
-
// Render children
|
|
350
|
-
for (let i = 0; i < node.children.length; i++) {
|
|
351
|
-
const childIsLast = i === node.children.length - 1;
|
|
352
|
-
formatSpanNode(node.children[i]!, lines, childPrefix, childIsLast, slowPhaseMs, rootStart);
|
|
353
|
-
}
|
|
354
429
|
}
|
|
355
430
|
|
|
356
431
|
/**
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
* this is what keeps the browser channel gated to `vite dev`.
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
14
15
|
import type { ReadableSpan } from '@opentelemetry/sdk-trace-base';
|
|
15
16
|
import {
|
|
16
17
|
DEV_SPAN_ATTRIBUTES,
|
|
@@ -89,7 +90,15 @@ export interface SpanSinkChannel {
|
|
|
89
90
|
|
|
90
91
|
/**
|
|
91
92
|
* Install the sink that broadcasts spans on the dev server's HMR channel,
|
|
92
|
-
* and answers replay requests from it.
|
|
93
|
+
* and answers replay requests from it. Every message is an array of spans
|
|
94
|
+
* of one trace, in the order they ended.
|
|
95
|
+
*
|
|
96
|
+
* Spans are batched: one send per trace per event-loop turn, not one per
|
|
97
|
+
* span. The sink is called inside the request, and each `hot.send` makes
|
|
98
|
+
* promises there, for each of which React's dev async debug hook captures a
|
|
99
|
+
* stack (~6µs a span; ~6ms on a 213-span trace). So the flush is scheduled
|
|
100
|
+
* from an `AsyncLocalStorage.snapshot()` taken here, at install, where no
|
|
101
|
+
* request is in scope: the send runs outside every request (TIM-1627).
|
|
93
102
|
*
|
|
94
103
|
* Broadcasting alone loses most of a document load: the root span ends when
|
|
95
104
|
* the pipeline returns its Response, tens of milliseconds in, and the page's
|
|
@@ -104,6 +113,15 @@ export interface SpanSinkChannel {
|
|
|
104
113
|
export function installSpanSink(hot: SpanSinkChannel): () => void {
|
|
105
114
|
const globals = globalThis as Record<symbol, unknown>;
|
|
106
115
|
const recent = new Map<string, DevSpanPayload[]>();
|
|
116
|
+
const outsideRequests = AsyncLocalStorage.snapshot();
|
|
117
|
+
let pending = new Map<string, DevSpanPayload[]>();
|
|
118
|
+
let scheduled: NodeJS.Immediate | undefined;
|
|
119
|
+
const flush = () => {
|
|
120
|
+
const batches = pending;
|
|
121
|
+
pending = new Map();
|
|
122
|
+
scheduled = undefined;
|
|
123
|
+
for (const spans of batches.values()) hot.send(DEV_SPAN_EVENT, spans);
|
|
124
|
+
};
|
|
107
125
|
const sink: DevSpanSink = (span) => {
|
|
108
126
|
let spans = recent.get(span.traceId);
|
|
109
127
|
if (!spans) {
|
|
@@ -115,18 +133,31 @@ export function installSpanSink(hot: SpanSinkChannel): () => void {
|
|
|
115
133
|
recent.set(span.traceId, spans);
|
|
116
134
|
}
|
|
117
135
|
spans.push(span);
|
|
118
|
-
|
|
136
|
+
let batch = pending.get(span.traceId);
|
|
137
|
+
if (!batch) {
|
|
138
|
+
batch = [];
|
|
139
|
+
pending.set(span.traceId, batch);
|
|
140
|
+
}
|
|
141
|
+
batch.push(span);
|
|
142
|
+
scheduled ??= outsideRequests(() => setImmediate(flush));
|
|
119
143
|
};
|
|
120
144
|
const onReplay = (data: unknown, client: { send(event: string, data: unknown): void }) => {
|
|
121
145
|
if (typeof data !== 'object' || data === null || !('traceId' in data)) return;
|
|
122
146
|
const { traceId } = data;
|
|
123
147
|
if (typeof traceId !== 'string') return;
|
|
124
|
-
|
|
148
|
+
const spans = recent.get(traceId);
|
|
149
|
+
// A copy: the trace's own list keeps growing while the send is queued.
|
|
150
|
+
if (spans) client.send(DEV_SPAN_EVENT, spans.slice());
|
|
125
151
|
};
|
|
126
152
|
globals[DEV_SPAN_SINK_KEY] = sink;
|
|
127
153
|
hot.on(DEV_SPAN_REPLAY_EVENT, onReplay);
|
|
128
154
|
return () => {
|
|
129
155
|
hot.off(DEV_SPAN_REPLAY_EVENT, onReplay);
|
|
156
|
+
// Send what is queued now rather than drop it: the channel closes after.
|
|
157
|
+
if (scheduled) {
|
|
158
|
+
clearImmediate(scheduled);
|
|
159
|
+
flush();
|
|
160
|
+
}
|
|
130
161
|
if (globals[DEV_SPAN_SINK_KEY] === sink) delete globals[DEV_SPAN_SINK_KEY];
|
|
131
162
|
};
|
|
132
163
|
}
|
package/src/index.ts
CHANGED
|
@@ -199,19 +199,27 @@ function createRscOptions(
|
|
|
199
199
|
* output mode to be silently ignored. See TIM-451.
|
|
200
200
|
*/
|
|
201
201
|
/**
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
*
|
|
202
|
+
* Adjust plugin-react's `vite:react-compiler` plugin:
|
|
203
|
+
*
|
|
204
|
+
* - Its configResolved always sees `isProduction: true` during builds. The
|
|
205
|
+
* compiler plugin uses `!config.isProduction` to decide whether to emit
|
|
206
|
+
* jsxDEV calls, but Vite derives isProduction from process.env.NODE_ENV —
|
|
207
|
+
* which may be "development" in the shell. Rather than mutating the env,
|
|
208
|
+
* we pass a prototype-based view with the single property overridden.
|
|
209
|
+
* - In dev it runs on the client environment only. Its `shouldCompile`
|
|
210
|
+
* requires a client environment, so on rsc/ssr it only repeats the
|
|
211
|
+
* JSX/TS transform `vite:oxc` does next, plus a sourcemap: ~200ms of a
|
|
212
|
+
* ~2.4s cold kitchen-sink request. Output is the same except for a
|
|
213
|
+
* trailing semicolon in plugin-rsc's CSS stubs (TIM-1627).
|
|
214
|
+
* Builds keep it on every environment, unchanged.
|
|
208
215
|
*/
|
|
209
|
-
function
|
|
216
|
+
function patchReactCompiler(plugins: PluginOption[]): PluginOption[] {
|
|
210
217
|
for (const p of plugins) {
|
|
211
218
|
if (p && typeof p === 'object' && 'name' in p && p.name === 'vite:react-compiler') {
|
|
212
|
-
const
|
|
219
|
+
const plugin = p as Plugin;
|
|
220
|
+
const orig = plugin.configResolved;
|
|
213
221
|
if (typeof orig === 'function') {
|
|
214
|
-
|
|
222
|
+
plugin.configResolved = function (config) {
|
|
215
223
|
const view =
|
|
216
224
|
config.command === 'build' && !config.isProduction
|
|
217
225
|
? Object.create(config, { isProduction: { value: true } })
|
|
@@ -219,6 +227,8 @@ function patchReactCompilerForProdJsx(plugins: PluginOption[]): PluginOption[] {
|
|
|
219
227
|
return orig.call(this, view);
|
|
220
228
|
};
|
|
221
229
|
}
|
|
230
|
+
plugin.applyToEnvironment = (env) =>
|
|
231
|
+
env.config.command === 'build' || env.config.consumer === 'client';
|
|
222
232
|
}
|
|
223
233
|
}
|
|
224
234
|
return plugins;
|
|
@@ -331,7 +341,7 @@ export function timber(config?: TimberUserConfig): PluginOption[] {
|
|
|
331
341
|
// and Vite's built-in OXC transform emits jsxDEV calls (the
|
|
332
342
|
// production jsx-runtime doesn't export jsxDEV). The oxc.jsx
|
|
333
343
|
// override below fixes Vite's native path; plugin-react's compiler
|
|
334
|
-
// plugin is handled by
|
|
344
|
+
// plugin is handled by patchReactCompiler above.
|
|
335
345
|
// ── Resolve dev port (TIM-842) ───────────────────────────────
|
|
336
346
|
// Default port is 3000. Vite handles conflicts and honors server.strictPort.
|
|
337
347
|
// We start the holding server on the requested port when available.
|
|
@@ -567,7 +577,7 @@ export function timber(config?: TimberUserConfig): PluginOption[] {
|
|
|
567
577
|
// for client components via Babel transform. Placed before @vitejs/plugin-rsc
|
|
568
578
|
// following Vinext's convention — the RSC plugin's virtual browser entry
|
|
569
579
|
// coordinates with plugin-react via __vite_plugin_react_preamble_installed__.
|
|
570
|
-
...
|
|
580
|
+
...patchReactCompiler(
|
|
571
581
|
react({
|
|
572
582
|
compiler: (effectiveReactCompiler || false) as boolean | ReactCompilerOptions,
|
|
573
583
|
})
|