@timber-js/app 0.2.0-alpha.234 → 0.2.0-alpha.236
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-BAKOSTkg.js → cli-check-BwiahbTC.js} +5 -5
- package/dist/_chunks/{cli-check-BAKOSTkg.js.map → cli-check-BwiahbTC.js.map} +1 -1
- package/dist/_chunks/{cli-context-BPdyA7Fp.js → cli-context-BbwVqarO.js} +1 -1
- package/dist/_chunks/{cli-context-CwTKMjVe.js → cli-context-DZh5v0yd.js} +2 -2
- package/dist/_chunks/{cli-context-CwTKMjVe.js.map → cli-context-DZh5v0yd.js.map} +1 -1
- package/dist/_chunks/{cli-schema-sync-CAllbqRB.js → cli-schema-sync-B2ldclRO.js} +3 -3
- package/dist/_chunks/{cli-schema-sync-CAllbqRB.js.map → cli-schema-sync-B2ldclRO.js.map} +1 -1
- package/dist/_chunks/{cli-schema-sync-y_8ijmzO.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-Rq659RR1.js → dev-server-lrdpD7Ws.js} +122 -6
- 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-BO_xD9jC.js} +2 -2
- package/dist/_chunks/{flight-source-node-BGanuoSS.js.map → flight-source-node-BO_xD9jC.js.map} +1 -1
- 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-DNNnKnoS.js} +2 -2
- package/dist/_chunks/{node-response-D3hXWb8y.js.map → node-response-DNNnKnoS.js.map} +1 -1
- package/dist/_chunks/{plugin-context-FCkaNLUB.js → plugin-context-BtaQcMuh.js} +2 -2
- package/dist/_chunks/{plugin-context-FCkaNLUB.js.map → plugin-context-BtaQcMuh.js.map} +1 -1
- package/dist/_chunks/{plugin-context-BfSRKJfz.js → plugin-context-I1dvGccO.js} +1 -1
- 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/{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-D_QHR_nf.js → walkers-BUvpsb2Q.js} +3 -3
- package/dist/_chunks/{walkers-D_QHR_nf.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 +4 -4
- package/dist/analyze/graph-command.js +5 -5
- package/dist/cache/index.js +2 -2
- package/dist/cache/stores/memory.js +1 -1
- package/dist/cli.js +6 -6
- 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/store.d.ts +0 -18
- package/dist/client/dev-pill/store.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 +12 -1
- 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 +183 -40
- 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 +10 -7
- 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 +2 -2
- 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/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 +2 -2
- 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 +10 -10
- package/dist/native/rsc/server/pipeline-interception.js +4 -4
- package/dist/native/rsc/server/pipeline-metadata-route.js +10 -10
- 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/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/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 +11 -4
- 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 +10 -7
- 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/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 +2 -2
- 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 +7 -7
- package/dist/native/ssr/server/pipeline-interception.js +4 -4
- package/dist/native/ssr/server/pipeline-metadata-route.js +10 -10
- 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/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/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 +11 -4
- 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-await.d.ts +3 -0
- package/dist/plugins/dev-await.d.ts.map +1 -1
- 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/native-runtime.d.ts +2 -2
- package/dist/plugins/native-runtime.d.ts.map +1 -1
- package/dist/plugins/plugin-rsc-package.d.ts +35 -0
- package/dist/plugins/plugin-rsc-package.d.ts.map +1 -0
- 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/index.js +2 -2
- package/dist/server/internal.js +14 -14
- package/dist/server/tracing.d.ts.map +1 -1
- package/dist/shared/dev-span.d.ts +21 -3
- 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 +3 -3
- package/src/client/dev-pill/index.ts +5 -2
- package/src/client/dev-pill/store.ts +5 -64
- package/src/client/dev-pill/view.ts +175 -53
- package/src/dev-tools/await-span.ts +32 -13
- 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 +24 -21
- package/src/plugins/dev-await.ts +61 -3
- 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/native-runtime.ts +4 -3
- package/src/plugins/plugin-rsc-package.ts +81 -0
- package/src/plugins/virtual-ids.ts +15 -0
- package/src/server/tracing.ts +29 -0
- package/src/shared/dev-span.ts +29 -6
- package/src/shared/span-waterfall.ts +227 -0
- package/dist/_chunks/chains-KblEfYzm.js +0 -1
- package/dist/_chunks/dev-server-L8biS7Az.js +0 -1
- package/dist/_chunks/dev-server-Rq659RR1.js.map +0 -1
- package/dist/_chunks/dev-span-_NzMX-au.js.map +0 -1
- package/dist/_chunks/logger-YtMSKfft.js.map +0 -1
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Dev request pill — wiring. Feeds the store from three places:
|
|
3
3
|
*
|
|
4
|
-
* - HMR `timber:span` events:
|
|
4
|
+
* - HMR `timber:span` events: finished server spans, batched per trace and
|
|
5
|
+
* event-loop turn as they end, and a trace's buffered spans on replay.
|
|
5
6
|
* - The document's navigation timing entry, whose `serverTiming` carries the
|
|
6
7
|
* page's trace ID (the one response header page JS can read for the
|
|
7
8
|
* document itself).
|
|
@@ -89,7 +90,9 @@ export function setupDevPill(hot: Hot, options: { slowMs: number }): void {
|
|
|
89
90
|
};
|
|
90
91
|
hot.on('vite:ws:connect', () => claimed.forEach(requestReplay));
|
|
91
92
|
|
|
92
|
-
hot.on(DEV_SPAN_EVENT, (data) =>
|
|
93
|
+
hot.on(DEV_SPAN_EVENT, (data) => {
|
|
94
|
+
for (const span of data as DevSpanPayload[]) store.addSpan(span);
|
|
95
|
+
});
|
|
93
96
|
|
|
94
97
|
const nav = performance.getEntriesByType('navigation')[0] as
|
|
95
98
|
| PerformanceNavigationTiming
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
import { ROOT_SPAN_NAME, type DevSpanPayload } from '../../shared/dev-span.ts';
|
|
10
10
|
import { RSC_KEY_PARAM } from '../../shared/rsc-cache-key.ts';
|
|
11
|
+
import { explainedWaits } from '../../shared/span-waterfall.ts';
|
|
11
12
|
|
|
12
13
|
export type DevRequestKind = 'document' | 'navigation' | 'action' | 'fetch';
|
|
13
14
|
|
|
@@ -41,19 +42,6 @@ export interface TraceSummary {
|
|
|
41
42
|
error: boolean;
|
|
42
43
|
}
|
|
43
44
|
|
|
44
|
-
/** Every span, or only the I/O: awaits and fetches. */
|
|
45
|
-
export type WaterfallView = 'all' | 'awaits';
|
|
46
|
-
|
|
47
|
-
const IO_SPANS = new Set(['timber.await', 'timber.fetch']);
|
|
48
|
-
|
|
49
|
-
export interface WaterfallRow {
|
|
50
|
-
span: DevSpanPayload;
|
|
51
|
-
depth: number;
|
|
52
|
-
/** Milliseconds from the trace's start. */
|
|
53
|
-
offsetMs: number;
|
|
54
|
-
durationMs: number;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
45
|
/**
|
|
58
46
|
* The page a URL addresses, comparable across the address bar and a payload
|
|
59
47
|
* URL: `_rsc` dropped, and the query re-serialized by `URLSearchParams` on
|
|
@@ -160,68 +148,21 @@ export class DevPillStore {
|
|
|
160
148
|
const spans = this.spans(traceId);
|
|
161
149
|
const root = spans.find((s) => s.name === ROOT_SPAN_NAME);
|
|
162
150
|
const status = root?.attributes['http.response.status_code'];
|
|
151
|
+
// Explained waits waited on work other spans show; not new work.
|
|
152
|
+
const waits = explainedWaits(spans);
|
|
163
153
|
return {
|
|
164
154
|
fetches: spans.filter((s) => s.name === 'timber.fetch').length,
|
|
165
|
-
|
|
166
|
-
awaits: spans.filter(
|
|
167
|
-
(s) => s.name === 'timber.await' && s.attributes['timber.await_shared'] !== true
|
|
168
|
-
).length,
|
|
155
|
+
awaits: spans.filter((s) => s.name === 'timber.await' && !waits.has(s.spanId)).length,
|
|
169
156
|
durationMs: root
|
|
170
157
|
? Math.max(...spans.map((s) => s.endMs)) - Math.min(...spans.map((s) => s.startMs))
|
|
171
158
|
: null,
|
|
172
159
|
slow: spans.some(
|
|
173
|
-
(s) =>
|
|
174
|
-
s !== root &&
|
|
175
|
-
s.attributes['timber.await_shared'] !== true &&
|
|
176
|
-
s.endMs - s.startMs > this.slowMs
|
|
160
|
+
(s) => s !== root && !waits.has(s.spanId) && s.endMs - s.startMs > this.slowMs
|
|
177
161
|
),
|
|
178
162
|
error: spans.some((s) => s.error) || (typeof status === 'number' && status >= 500),
|
|
179
163
|
};
|
|
180
164
|
}
|
|
181
165
|
|
|
182
|
-
/**
|
|
183
|
-
* Spans in tree order (parent before children, siblings by start).
|
|
184
|
-
*
|
|
185
|
-
* `view: 'awaits'` keeps only awaits and fetches — the I/O — each nested
|
|
186
|
-
* under its nearest kept ancestor, so hiding framework phases leaves no
|
|
187
|
-
* gaps in the indentation. The time axis still starts at the request's
|
|
188
|
-
* first span.
|
|
189
|
-
*/
|
|
190
|
-
waterfall(traceId: string, view: WaterfallView = 'all'): WaterfallRow[] {
|
|
191
|
-
const spans = this.spans(traceId);
|
|
192
|
-
if (spans.length === 0) return [];
|
|
193
|
-
const ids = new Set(spans.map((s) => s.spanId));
|
|
194
|
-
const children = new Map<string | undefined, DevSpanPayload[]>();
|
|
195
|
-
for (const span of spans) {
|
|
196
|
-
// A span whose parent isn't here (the root still open, or a parent
|
|
197
|
-
// outside this trace's spans) sits at the top level.
|
|
198
|
-
const parent =
|
|
199
|
-
span.parentSpanId && ids.has(span.parentSpanId) ? span.parentSpanId : undefined;
|
|
200
|
-
const siblings = children.get(parent) ?? [];
|
|
201
|
-
siblings.push(span);
|
|
202
|
-
children.set(parent, siblings);
|
|
203
|
-
}
|
|
204
|
-
const origin = Math.min(...spans.map((s) => s.startMs));
|
|
205
|
-
const rows: WaterfallRow[] = [];
|
|
206
|
-
const visit = (parent: string | undefined, depth: number) => {
|
|
207
|
-
const siblings = (children.get(parent) ?? []).sort((a, b) => a.startMs - b.startMs);
|
|
208
|
-
for (const span of siblings) {
|
|
209
|
-
const shown = view === 'all' || IO_SPANS.has(span.name);
|
|
210
|
-
if (shown) {
|
|
211
|
-
rows.push({
|
|
212
|
-
span,
|
|
213
|
-
depth,
|
|
214
|
-
offsetMs: span.startMs - origin,
|
|
215
|
-
durationMs: span.endMs - span.startMs,
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
visit(span.spanId, shown ? depth + 1 : depth);
|
|
219
|
-
}
|
|
220
|
-
};
|
|
221
|
-
visit(undefined, 0);
|
|
222
|
-
return rows;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
166
|
/**
|
|
226
167
|
* Keep the newest requests, and always the selected one: a page that polls
|
|
227
168
|
* a route handler would otherwise push its own trace out, leaving the pill
|
|
@@ -5,8 +5,19 @@
|
|
|
5
5
|
* it and it can't reach the app. See design/50-dev-request-pill.md §"The pill".
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
|
|
8
|
+
import {
|
|
9
|
+
AWAIT_SPAN_NAME,
|
|
10
|
+
FETCH_BODY_SPAN_NAME,
|
|
11
|
+
devSpanLabel,
|
|
12
|
+
ROOT_SPAN_NAME,
|
|
13
|
+
type DevSpanPayload,
|
|
14
|
+
} from '../../shared/dev-span.ts';
|
|
15
|
+
import type { DevPillStore, DevRequest } from './store.ts';
|
|
16
|
+
import { buildWaterfall, type WaterfallRow } from '../../shared/span-waterfall.ts';
|
|
17
|
+
|
|
18
|
+
/** Every span, or only the I/O: awaits and fetches. */
|
|
19
|
+
type WaterfallView = 'all' | 'awaits';
|
|
20
|
+
type Row = WaterfallRow<DevSpanPayload>;
|
|
10
21
|
|
|
11
22
|
/** localStorage keys for per-browser choices, per dev origin. */
|
|
12
23
|
const MINIMIZED_KEY = 'timber:dev-pill:minimized';
|
|
@@ -67,16 +78,40 @@ select {
|
|
|
67
78
|
border-radius: 6px; padding: 4px 6px; font: inherit;
|
|
68
79
|
}
|
|
69
80
|
.rows { overflow: auto; padding: 4px 0; }
|
|
81
|
+
/* One line per row; rows touch, so the nesting rails run unbroken. */
|
|
70
82
|
.row {
|
|
71
|
-
display: grid; grid-template-columns: minmax(0, 1fr) minmax(80px,
|
|
72
|
-
align-items: center; gap:
|
|
83
|
+
display: grid; grid-template-columns: minmax(0, 1fr) minmax(80px, 30%) 48px;
|
|
84
|
+
align-items: center; gap: 10px; padding: 0 10px; height: 24px;
|
|
73
85
|
}
|
|
74
86
|
.row:hover { background: #20241e; }
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
87
|
+
/* Indentation with one rail per ancestor, under where its label starts. */
|
|
88
|
+
.label {
|
|
89
|
+
--indent: 14px;
|
|
90
|
+
display: flex; align-items: center; gap: 6px; min-width: 0; height: 100%;
|
|
91
|
+
padding-left: calc(var(--depth, 0) * var(--indent)); white-space: nowrap;
|
|
92
|
+
background: repeating-linear-gradient(to right, #343b30 0 1px, transparent 1px var(--indent))
|
|
93
|
+
4px 0 / calc(var(--depth, 0) * var(--indent)) 100% no-repeat;
|
|
94
|
+
}
|
|
95
|
+
.name { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
|
|
96
|
+
.row.root-row .name { font-weight: 600; }
|
|
97
|
+
.meta, .loc { flex: none; color: #9aa394; font-size: 11px; }
|
|
98
|
+
.loc { margin-left: auto; padding-left: 8px; }
|
|
99
|
+
.fold {
|
|
100
|
+
flex: none; padding: 0 5px; border: 1px solid #2f352c; border-radius: 4px;
|
|
101
|
+
background: transparent; color: #9aa394; font: 11px/16px ui-sans-serif, system-ui, sans-serif;
|
|
102
|
+
font-variant-numeric: tabular-nums; cursor: pointer;
|
|
103
|
+
}
|
|
104
|
+
.fold:hover { color: #e8ebe6; border-color: #4a5444; }
|
|
105
|
+
.fold:focus-visible, .foot button:focus-visible { outline: 2px solid #8fbf5a; outline-offset: 1px; }
|
|
106
|
+
.row.wait .name { color: #9aa394; }
|
|
107
|
+
.foot {
|
|
108
|
+
display: flex; justify-content: flex-end; padding: 6px 10px; border-top: 1px solid #2f352c;
|
|
109
|
+
color: #9aa394; font-size: 11px;
|
|
110
|
+
}
|
|
111
|
+
.foot button {
|
|
112
|
+
background: none; border: 0; padding: 0 0 0 6px; color: #8fbf5a; font: inherit; cursor: pointer;
|
|
113
|
+
}
|
|
114
|
+
.bar.wait {
|
|
80
115
|
background: repeating-linear-gradient(135deg, #3f9a8f55 0 3px, transparent 3px 6px);
|
|
81
116
|
outline: 1px solid #3f9a8f88; outline-offset: -1px;
|
|
82
117
|
}
|
|
@@ -135,21 +170,58 @@ function requestLabel(r: DevRequest): string {
|
|
|
135
170
|
return `${r.kind === 'action' ? 'action' : r.method} ${r.path}`;
|
|
136
171
|
}
|
|
137
172
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
return String(a['timber.await_location'] ?? '');
|
|
173
|
+
/** `GET /api/v4/shows`: the origin is on hover; the path is what tells fetches apart. */
|
|
174
|
+
function fetchLabel(span: DevSpanPayload): string {
|
|
175
|
+
const a = span.attributes;
|
|
176
|
+
const url = String(a['http.url'] ?? '');
|
|
177
|
+
let path = url;
|
|
178
|
+
try {
|
|
179
|
+
path = new URL(url).pathname;
|
|
180
|
+
} catch {
|
|
181
|
+
// Not absolute: show it as recorded.
|
|
148
182
|
}
|
|
149
|
-
|
|
150
|
-
|
|
183
|
+
return `${String(a['http.request.method'] ?? 'GET')} ${path}`;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** Status and cache result of a fetch; status of the request. */
|
|
187
|
+
function spanMeta(span: DevSpanPayload): string {
|
|
188
|
+
const a = span.attributes;
|
|
189
|
+
if (span.name === 'timber.fetch') {
|
|
190
|
+
return [a['http.response.status_code'], a['timber.cache_status']]
|
|
191
|
+
.filter((v) => v !== undefined)
|
|
192
|
+
.join(' · ');
|
|
151
193
|
}
|
|
152
|
-
|
|
194
|
+
if (span.name === ROOT_SPAN_NAME) return String(a['http.response.status_code'] ?? '');
|
|
195
|
+
return span.events.includes('timber.cache.hit') ? 'cache hit' : '';
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** In the pill an await row is its source text; the bar color says it's an await. */
|
|
199
|
+
function spanName(span: DevSpanPayload): string {
|
|
200
|
+
if (span.name === AWAIT_SPAN_NAME) return String(span.attributes['timber.await_label'] ?? '');
|
|
201
|
+
if (span.name === 'timber.fetch') return fetchLabel(span);
|
|
202
|
+
return devSpanLabel(span.name, span.attributes).label;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* `page.tsx:11`, with the parallel slot when there is one
|
|
207
|
+
* (`@songs page.tsx:11`): the full path is on hover.
|
|
208
|
+
*/
|
|
209
|
+
function shortLocation(location: string): string {
|
|
210
|
+
const parts = location.split('/');
|
|
211
|
+
const slot = parts.filter((p) => p.startsWith('@')).at(-1);
|
|
212
|
+
const file = parts.at(-1) ?? location;
|
|
213
|
+
return slot ? `${slot} ${file}` : file;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** Hover text: every span in the row, with its full location. */
|
|
217
|
+
function rowTitle(row: Row): string {
|
|
218
|
+
return [row.span, ...row.folded]
|
|
219
|
+
.map((span) => {
|
|
220
|
+
const where = span.attributes['timber.await_location'];
|
|
221
|
+
const { label: text } = devSpanLabel(span.name, span.attributes);
|
|
222
|
+
return where ? `${text} ${String(where)}` : text;
|
|
223
|
+
})
|
|
224
|
+
.join('\n');
|
|
153
225
|
}
|
|
154
226
|
|
|
155
227
|
export function mountDevPill(store: DevPillStore): void {
|
|
@@ -166,6 +238,9 @@ export function mountDevPill(store: DevPillStore): void {
|
|
|
166
238
|
// Awaits by default: the I/O is what the pill is for; framework phases are
|
|
167
239
|
// a click away.
|
|
168
240
|
let view: WaterfallView = readPref(VIEW_KEY) === 'all' ? 'all' : 'awaits';
|
|
241
|
+
// Per page load: which folded rows are open, and whether explained waits show.
|
|
242
|
+
const expanded = new Set<string>();
|
|
243
|
+
let showWaits = false;
|
|
169
244
|
let scheduled = false;
|
|
170
245
|
|
|
171
246
|
const setMinimized = (value: boolean) => {
|
|
@@ -262,48 +337,95 @@ export function mountDevPill(store: DevPillStore): void {
|
|
|
262
337
|
head.append(toggle);
|
|
263
338
|
|
|
264
339
|
const rows = el('div', 'rows');
|
|
265
|
-
const
|
|
340
|
+
const spans = store.spans(selected.traceId);
|
|
341
|
+
// Hiding and folding are the awaits view's; All shows every span as is.
|
|
342
|
+
const { rows: waterfall, hiddenWaits } = buildWaterfall(
|
|
343
|
+
spans,
|
|
344
|
+
view === 'awaits' ? { ioOnly: true, hideWaits: !showWaits, fold: true, expanded } : {}
|
|
345
|
+
);
|
|
266
346
|
if (waterfall.length === 0) {
|
|
267
347
|
const nothing =
|
|
268
|
-
view === 'awaits' &&
|
|
348
|
+
view === 'awaits' && spans.length > 0
|
|
269
349
|
? 'No awaits or fetches over 1ms. All shows every span.'
|
|
270
350
|
: 'Waiting for spans…';
|
|
271
351
|
rows.append(el('div', 'empty', nothing));
|
|
272
352
|
}
|
|
273
353
|
const total = Math.max(1, ...waterfall.map((r) => r.offsetMs + r.durationMs));
|
|
274
|
-
for (const row of waterfall)
|
|
275
|
-
const line = el('div', 'row');
|
|
276
|
-
const { label } = devSpanLabel(row.span.name, row.span.attributes);
|
|
277
|
-
const labelCell = el('div', 'label');
|
|
278
|
-
labelCell.style.paddingLeft = `${row.depth * 12}px`;
|
|
279
|
-
labelCell.append(document.createTextNode(label));
|
|
280
|
-
// Shared: this await waited on a promise another await already took
|
|
281
|
-
// (React.cache, an in-flight load) — no new work happened here.
|
|
282
|
-
const shared = row.span.attributes['timber.await_shared'] === true;
|
|
283
|
-
if (shared) line.classList.add('shared');
|
|
284
|
-
const sub = rowSubtitle(row);
|
|
285
|
-
if (sub) labelCell.append(el('span', 'sub', sub));
|
|
286
|
-
|
|
287
|
-
const track = el('div', 'track');
|
|
288
|
-
const bar = el('div', 'bar');
|
|
289
|
-
if (row.span.name === 'timber.fetch') bar.classList.add('fetch');
|
|
290
|
-
else if (row.span.name === 'timber.await') bar.classList.add(shared ? 'shared' : 'await');
|
|
291
|
-
if (row.span.error) bar.classList.add('error');
|
|
292
|
-
// The request's own row spans everything; judge it by name, not
|
|
293
|
-
// depth, which the awaits view flattens (Codex review on #1274).
|
|
294
|
-
else if (!shared && row.span.name !== ROOT_SPAN_NAME && row.durationMs > store.slowMs)
|
|
295
|
-
bar.classList.add('slow');
|
|
296
|
-
bar.style.left = `${(row.offsetMs / total) * 100}%`;
|
|
297
|
-
bar.style.width = `${(row.durationMs / total) * 100}%`;
|
|
298
|
-
track.append(bar);
|
|
299
|
-
|
|
300
|
-
line.append(labelCell, track, el('div', 'dur', formatMs(row.durationMs)));
|
|
301
|
-
rows.append(line);
|
|
302
|
-
}
|
|
354
|
+
for (const row of waterfall) rows.append(renderRow(row, total));
|
|
303
355
|
panel.append(head, rows);
|
|
356
|
+
|
|
357
|
+
// Hiding and folding are the awaits view's; All shows every span as is.
|
|
358
|
+
if (view === 'awaits' && (hiddenWaits > 0 || showWaits)) {
|
|
359
|
+
const foot = el('div', 'foot');
|
|
360
|
+
const toggleWaits = el('button', undefined, showWaits ? 'Hide waits' : 'Show');
|
|
361
|
+
toggleWaits.type = 'button';
|
|
362
|
+
toggleWaits.addEventListener('click', () => {
|
|
363
|
+
showWaits = !showWaits;
|
|
364
|
+
render();
|
|
365
|
+
});
|
|
366
|
+
if (!showWaits) {
|
|
367
|
+
foot.title = 'Awaits of a promise whose work is already on another row';
|
|
368
|
+
foot.append(`${hiddenWaits} wait${hiddenWaits === 1 ? '' : 's'} hidden ·`);
|
|
369
|
+
}
|
|
370
|
+
foot.append(toggleWaits);
|
|
371
|
+
panel.append(foot);
|
|
372
|
+
}
|
|
304
373
|
return panel;
|
|
305
374
|
};
|
|
306
375
|
|
|
376
|
+
const renderRow = (row: Row, total: number): HTMLElement => {
|
|
377
|
+
const line = el('div', 'row');
|
|
378
|
+
line.title = rowTitle(row);
|
|
379
|
+
if (row.wait) line.classList.add('wait');
|
|
380
|
+
if (row.span.name === ROOT_SPAN_NAME) line.classList.add('root-row');
|
|
381
|
+
|
|
382
|
+
// A folded chain that ends in a fetch reads as the fetch: that's the I/O.
|
|
383
|
+
// Otherwise the outer call, which is the code that asked for the work.
|
|
384
|
+
const leaf = row.folded.at(-1);
|
|
385
|
+
const named = leaf?.name === 'timber.fetch' ? leaf : row.span;
|
|
386
|
+
const labelCell = el('div', 'label');
|
|
387
|
+
labelCell.style.setProperty('--depth', String(row.depth));
|
|
388
|
+
labelCell.append(el('span', 'name', spanName(named)));
|
|
389
|
+
|
|
390
|
+
const id = row.span.spanId;
|
|
391
|
+
if (row.folded.length > 0 || (view === 'awaits' && expanded.has(id))) {
|
|
392
|
+
const open = expanded.has(id);
|
|
393
|
+
const fold = el('button', 'fold', open ? '−' : `+${row.folded.length}`);
|
|
394
|
+
fold.type = 'button';
|
|
395
|
+
fold.setAttribute('aria-expanded', String(open));
|
|
396
|
+
fold.setAttribute('aria-label', open ? 'Fold nested awaits' : 'Show nested awaits');
|
|
397
|
+
fold.addEventListener('click', (event) => {
|
|
398
|
+
event.stopPropagation();
|
|
399
|
+
if (open) expanded.delete(id);
|
|
400
|
+
else expanded.add(id);
|
|
401
|
+
render();
|
|
402
|
+
});
|
|
403
|
+
labelCell.append(fold);
|
|
404
|
+
}
|
|
405
|
+
const meta = spanMeta(named);
|
|
406
|
+
if (meta) labelCell.append(el('span', 'meta', meta));
|
|
407
|
+
const location = row.span.attributes['timber.await_location'];
|
|
408
|
+
if (location !== undefined)
|
|
409
|
+
labelCell.append(el('span', 'loc', shortLocation(String(location))));
|
|
410
|
+
|
|
411
|
+
const track = el('div', 'track');
|
|
412
|
+
const bar = el('div', 'bar');
|
|
413
|
+
if (named.name === 'timber.fetch' || named.name === FETCH_BODY_SPAN_NAME)
|
|
414
|
+
bar.classList.add('fetch');
|
|
415
|
+
else if (row.span.name === AWAIT_SPAN_NAME) bar.classList.add(row.wait ? 'wait' : 'await');
|
|
416
|
+
if ([row.span, ...row.folded].some((s) => s.error)) bar.classList.add('error');
|
|
417
|
+
// The request's own row spans everything; judge it by name, not
|
|
418
|
+
// depth, which the awaits view flattens (Codex review on #1274).
|
|
419
|
+
else if (!row.wait && row.span.name !== ROOT_SPAN_NAME && row.durationMs > store.slowMs)
|
|
420
|
+
bar.classList.add('slow');
|
|
421
|
+
bar.style.left = `${(row.offsetMs / total) * 100}%`;
|
|
422
|
+
bar.style.width = `${(row.durationMs / total) * 100}%`;
|
|
423
|
+
track.append(bar);
|
|
424
|
+
|
|
425
|
+
line.append(labelCell, track, el('div', 'dur', formatMs(row.durationMs)));
|
|
426
|
+
return line;
|
|
427
|
+
};
|
|
428
|
+
|
|
307
429
|
// Escape closes the panel.
|
|
308
430
|
document.addEventListener('keydown', (event) => {
|
|
309
431
|
if (event.key === 'Escape' && open) {
|
|
@@ -9,10 +9,19 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import { trace } from '@opentelemetry/api';
|
|
12
|
-
import { AWAIT_SPAN_NAME, DEV_AWAIT_KEY } from '../shared/dev-span.ts';
|
|
12
|
+
import { AWAIT_SPAN_NAME, AWAIT_WAIT_ATTRIBUTE, DEV_AWAIT_KEY } from '../shared/dev-span.ts';
|
|
13
13
|
import { traceCall } from '../server/tracing.ts';
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
/**
|
|
16
|
+
* `startsNoWork`: the transform saw an operand that only reads existing
|
|
17
|
+
* promises (`await call`, `await Promise.all([a, b])`).
|
|
18
|
+
*/
|
|
19
|
+
export type DevAwaitWrapper = (
|
|
20
|
+
thunk: () => unknown,
|
|
21
|
+
label: string,
|
|
22
|
+
location: string,
|
|
23
|
+
startsNoWork?: boolean
|
|
24
|
+
) => unknown;
|
|
16
25
|
|
|
17
26
|
/**
|
|
18
27
|
* Promises some await has already waited on. A later await of the same
|
|
@@ -25,22 +34,32 @@ export type DevAwaitWrapper = (thunk: () => unknown, label: string, location: st
|
|
|
25
34
|
const awaited = new WeakSet<object>();
|
|
26
35
|
|
|
27
36
|
/**
|
|
28
|
-
* Mark the active await span
|
|
29
|
-
* await already took
|
|
37
|
+
* Mark the active await span a wait — no new work happened under it — when
|
|
38
|
+
* its operand is a native promise that either another await already took or
|
|
39
|
+
* that existed before this await began (`startsNoWork`).
|
|
30
40
|
*
|
|
31
41
|
* Plain native promises only: one of those settles once, whoever awaits it.
|
|
32
42
|
* A thenable may start its work on every `then()` — Drizzle's query builders
|
|
33
|
-
* run the query each time they are awaited — so
|
|
34
|
-
*
|
|
43
|
+
* run the query each time they are awaited — so awaiting one is new work,
|
|
44
|
+
* not a wait (Codex review on #1274).
|
|
35
45
|
*/
|
|
36
|
-
function
|
|
46
|
+
function noteWait(value: unknown, startsNoWork: boolean): void {
|
|
37
47
|
if (typeof value !== 'object' || value === null) return;
|
|
38
48
|
if (Object.getPrototypeOf(value) !== Promise.prototype) return;
|
|
39
|
-
if (awaited.has(value)) {
|
|
40
|
-
trace.getActiveSpan()?.setAttribute(
|
|
41
|
-
} else {
|
|
42
|
-
awaited.add(value);
|
|
49
|
+
if (startsNoWork || awaited.has(value)) {
|
|
50
|
+
trace.getActiveSpan()?.setAttribute(AWAIT_WAIT_ATTRIBUTE, true);
|
|
43
51
|
}
|
|
52
|
+
awaited.add(value);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Record a promise whose work another span already shows, so an await of it
|
|
57
|
+
* is a wait. The dev fetch patch calls this for a body read
|
|
58
|
+
* (`res.text()`): the read is drawn as a `timber.fetch.body` span under
|
|
59
|
+
* the fetch, and `await res.text()` would draw the same time again.
|
|
60
|
+
*/
|
|
61
|
+
export function noteTracedWork(promise: Promise<unknown>): void {
|
|
62
|
+
awaited.add(promise);
|
|
44
63
|
}
|
|
45
64
|
|
|
46
65
|
/**
|
|
@@ -49,7 +68,7 @@ function noteShared(value: unknown): void {
|
|
|
49
68
|
* spans once it has. Idempotent: a repeat install replaces the wrapper.
|
|
50
69
|
*/
|
|
51
70
|
export function installDevAwait(): void {
|
|
52
|
-
const wrapper: DevAwaitWrapper = (thunk, label, location) => {
|
|
71
|
+
const wrapper: DevAwaitWrapper = (thunk, label, location, startsNoWork = false) => {
|
|
53
72
|
// Outside a request (module init, background work) there is no trace
|
|
54
73
|
// to nest under; a span would only become an orphan trace.
|
|
55
74
|
if (!trace.getActiveSpan()) return thunk();
|
|
@@ -60,7 +79,7 @@ export function installDevAwait(): void {
|
|
|
60
79
|
{ 'timber.await_label': label, 'timber.await_location': location },
|
|
61
80
|
() => {
|
|
62
81
|
const value = thunk();
|
|
63
|
-
|
|
82
|
+
noteWait(value, startsNoWork);
|
|
64
83
|
return value;
|
|
65
84
|
}
|
|
66
85
|
);
|
|
@@ -31,8 +31,13 @@ import {
|
|
|
31
31
|
type DevLoggerConfig,
|
|
32
32
|
} from './logger.ts';
|
|
33
33
|
import { forwardSpan } from './span-sink.ts';
|
|
34
|
-
import { installDevAwait } from './await-span.ts';
|
|
35
|
-
import {
|
|
34
|
+
import { installDevAwait, noteTracedWork } from './await-span.ts';
|
|
35
|
+
import {
|
|
36
|
+
AWAIT_SPAN_MIN_MS,
|
|
37
|
+
AWAIT_SPAN_NAME,
|
|
38
|
+
FETCH_BODY_SPAN_NAME,
|
|
39
|
+
FETCH_SPAN_NAME,
|
|
40
|
+
} from '../shared/dev-span.ts';
|
|
36
41
|
|
|
37
42
|
// ─── Fetch Instrumentation ──────────────────────────────────────────────────
|
|
38
43
|
|
|
@@ -68,7 +73,7 @@ export function instrumentDevFetch(): DevFetchCleanup {
|
|
|
68
73
|
const { method, url } = extractFetchInfo(input, init);
|
|
69
74
|
|
|
70
75
|
return tracer.startActiveSpan(
|
|
71
|
-
|
|
76
|
+
FETCH_SPAN_NAME,
|
|
72
77
|
{
|
|
73
78
|
attributes: {
|
|
74
79
|
'http.request.method': method,
|
|
@@ -90,6 +95,7 @@ export function instrumentDevFetch(): DevFetchCleanup {
|
|
|
90
95
|
|
|
91
96
|
span.setStatus({ code: api.SpanStatusCode.OK });
|
|
92
97
|
span.end();
|
|
98
|
+
traceBodyReads(response, api.trace.setSpan(api.context.active(), span), tracer);
|
|
93
99
|
return response;
|
|
94
100
|
} catch (error) {
|
|
95
101
|
span.setStatus({ code: api.SpanStatusCode.ERROR });
|
|
@@ -114,6 +120,39 @@ export function instrumentDevFetch(): DevFetchCleanup {
|
|
|
114
120
|
return cleanup;
|
|
115
121
|
}
|
|
116
122
|
|
|
123
|
+
/** The `Response` methods that read the whole body. */
|
|
124
|
+
const BODY_READERS = ['arrayBuffer', 'blob', 'bytes', 'formData', 'json', 'text'] as const;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Give each body read of `response` a `timber.fetch.body` span under the
|
|
128
|
+
* fetch span (`parent`), and tell the dev await wrapper the read is traced,
|
|
129
|
+
* so `await res.text()` is a wait that span explains rather than a second
|
|
130
|
+
* bar for the same time. Own properties on this one response; a clone, or a
|
|
131
|
+
* body read through `response.body`, is not traced.
|
|
132
|
+
*/
|
|
133
|
+
function traceBodyReads(response: Response, parent: Context, tracer: api.Tracer): void {
|
|
134
|
+
for (const reader of BODY_READERS) {
|
|
135
|
+
const read = response[reader];
|
|
136
|
+
if (typeof read !== 'function') continue;
|
|
137
|
+
const traced = (): Promise<unknown> => {
|
|
138
|
+
const span = tracer.startSpan(FETCH_BODY_SPAN_NAME, {}, parent);
|
|
139
|
+
const reading = (async () => {
|
|
140
|
+
try {
|
|
141
|
+
return await read.call(response);
|
|
142
|
+
} catch (error) {
|
|
143
|
+
span.setStatus({ code: api.SpanStatusCode.ERROR });
|
|
144
|
+
throw error;
|
|
145
|
+
} finally {
|
|
146
|
+
span.end();
|
|
147
|
+
}
|
|
148
|
+
})();
|
|
149
|
+
noteTracedWork(reading);
|
|
150
|
+
return reading;
|
|
151
|
+
};
|
|
152
|
+
Object.defineProperty(response, reader, { value: traced, configurable: true, writable: true });
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
117
156
|
/**
|
|
118
157
|
* Extract method and URL from the various fetch() call signatures.
|
|
119
158
|
*/
|
|
@@ -220,9 +259,8 @@ export class DevSpanProcessor implements SpanProcessor {
|
|
|
220
259
|
if (this.mode === 'quiet') return '';
|
|
221
260
|
if (this.mode === 'json') return formatJson(spans);
|
|
222
261
|
if (this.mode === 'summary') return formatSpanSummary(spans, this.config);
|
|
223
|
-
// Both 'tree' and 'verbose' use the tree formatter
|
|
224
|
-
//
|
|
225
|
-
// component-level spans are wired.
|
|
262
|
+
// Both 'tree' and 'verbose' use the tree formatter; tree hides
|
|
263
|
+
// explained waits and folds pass-through awaits, verbose prints every span.
|
|
226
264
|
return formatSpanTree(spans, this.config);
|
|
227
265
|
}
|
|
228
266
|
|