2.8 KiB
2.8 KiB
Deno Runtime Trace Shim (draft v0.1)
This document specifies how the Deno analyzer will generate deno-runtime.ndjson traces offline for tasks DENO-26-009/010/011.
Objectives
- Capture module loads, permission uses, npm resolutions, and wasm loads during harnessed execution.
- Operate offline, deterministic ordering, and path redaction via relative paths + SHA256.
- Emit NDJSON per
deno-runtime-signals.mdand store todeno-runtime.ndjsonat analyzer root.
Approach
-
Shim loader
- Entry file
trace-shim.tsinjected ahead of user entrypoint (via--import-mapor--unstable-preload-module). - Registers listeners:
Deno.permissions.query/deny/permitwrappers to observe grants.globalThis.__originalImport = WebAssembly.instantiateStreamingto observe wasm loads (fallback to buffer) and record importer URL.- Wraps dynamic import by monkeypatching
importviaglobalThis.__dynamicImportusingcreateDynamicImportProxyhelper (supported in Deno 1.42+).
- Hooks
Deno[Deno.internal].moduleLoader.load(where available) to observe resolved specifier and cache hit/miss reason; fallback toperformance.resourceTimingBuffernot used.
- Entry file
-
Event buffering
- Collects events in-memory; each event includes UTC timestamp and relative path (computed against analyzer root) plus
path_sha256. - Origin normalization: for remote specifiers, strip query/fragment; record registry host/version if npm.
- Collects events in-memory; each event includes UTC timestamp and relative path (computed against analyzer root) plus
-
Execution
- Analyzer runs
deno run --allow-read --allow-env --no-lock --no-npm --quiet --import-map trace-import-map.json trace-shim.ts <user-entry>. - Optional: respect
DENO_DIRfrom workspace normalization; no network fetch allowed (set--cached-only).
- Analyzer runs
-
Output
- After user code exits, shim writes buffered events as NDJSON sorted by timestamp then type to
<root>/deno-runtime.ndjson. - Also prints SHA256 to stdout for diagnostics; Analyzer reads file and stores payload in AnalysisStore + signals.
- After user code exits, shim writes buffered events as NDJSON sorted by timestamp then type to
-
Determinism & safety
- Timestamps:
Date.now()captured and converted to ISO-8601 UTC. - Paths: use analyzer root +
path.relative+ forward slashes; hash with SHA256(lowercase hex). - No module source or env values persisted; only paths + hashes.
- Timestamps:
Validation plan
- Add fixtures: simple import graph, dynamic import, wasm load, npm: chalk (cached), permission use via
Deno.permissions.request. - Golden NDJSON and hash comparison in tests; ensure stable ordering.
Open items
- Confirm
--unstable-preload-moduleavailability on target Deno version; fallback to import-map injection if unavailable. - Verify WASM load interception across
WebAssembly.instantiatevsinstantiateStreaming. - Ensure
--cached-onlyworks with npm cache; otherwise fallback to static npm graph without runtime fetch.