Skip to content

v0.2.0

Choose a tag to compare

@github-actions github-actions released this 19 Oct 07:28
08d736f

Security

  • Behavior change: symbolizeStackFrames now confines reads to the working directory when roots
    is left out. Frames whose built file or source map lies outside the working directory are no
    longer read; they come back unchanged unless you pass roots naming the directories to read
    from, or roots: null for the old unconfined behavior.
  • Dashboard login no longer puts the token in a request line. Open /login#token=<token>: the
    token is in the URL fragment, which the browser never sends; the public login page removes it
    from the address bar and history, then posts it as JSON to the new POST /session (4096-byte
    cap, JSON only, constant-time compare), which answers 204 with the same HttpOnly,
    SameSite=Strict session cookie, or 401 with none. phargus serve and the dashboard script
    now point at this link. /?token=<token> still works but is deprecated and will be removed in a
    later release; the first use emits a PHARGUS_DEP_TOKEN_QUERY deprecation warning.

Added

  • PHARGUS_CONFIG pins the agent's config file. When set, the agent loads exactly that .json
    or .js file (a relative path resolves against the working directory) and does not look for
    phargus.config.json or phargus.config.js there. An empty value, a missing or unreadable
    file, something that is not a regular file, or any other extension rejects with a
    PhargusConfigError naming PHARGUS_CONFIG, and never falls back to the working-directory
    lookup. docs/THREAT-MODEL.md gains row I1 for the config file as code-execution surface.

  • phargus serve, a command-line way to get the dashboard without writing a collector. The
    package now has a bin, so node --import @pharn-dev/phargus/agent app.mjs | npx phargus serve
    reads the agent's NDJSON from stdin (or -), replays a capture file given as an argument,
    aggregates it into windows and serves the dashboard. Flags: --port (default 7070), --host
    (default 127.0.0.1), --token, --window-ms (default 1000) and --max-line-bytes, plus
    --help and --version. PHARGUS_TOKEN supplies the token, and a non-loopback --host
    without one is refused with exit code 2 before anything binds. Diagnostics go to stderr only:
    the dashboard URL, an input-ended line and a counts: line (decoder.invalid,
    decoder.oversized, collector.ignored, dashboard.droppedEvents). The server keeps running
    after the input ends. SIGINT and SIGTERM close the server and the collector and exit 0; a stuck
    shutdown is forced out with exit code 1 after 5 seconds. Exit codes: 0 success, 1 runtime error
    (unreadable file, port in use), 2 usage error. Errors print without a stack unless
    PHARGUS_DEBUG is set. The CLI is ESM-only and is not an exports subpath.
    @pharn-dev/phargus/dashboard now also exports isLoopbackHost. npm run check:exports,
    check:package and check:install verify the bin.

  • phargus serve --allowed-host <host>, repeatable, passed to the dashboard's allowedHosts.
    It lets a browser reach a server bound with --host 0.0.0.0 (for example in a container) by
    IP or hostname instead of getting 421. A bare name matches on any port; host:port matches
    exactly. An empty value, or one with whitespace or /, is a usage error (exit code 2). It does
    not lift the token requirement for a non-loopback --host.

  • Webhook alert sinks take an optional headers option, for example
    { authorization: 'Bearer …' }, sent with every request (review finding F23). It works on
    createWebhookSink and on a { type: 'webhook' } sink config. Headers are copied and checked
    when the sink is created: a name must be an HTTP token, a value must be a string with no control
    characters (tab aside) and nothing above U+00FF, and the same name twice in different case is
    rejected. content-type is reserved for the sink's own application/json, so supplying it is a
    TypeError rather than a silent override. __proto__ is rejected too, because Node's fetch
    drops it. Errors name the header, never its value.

  • OTLP metrics export (@pharn-dev/phargus/otel) now carries every window field (review finding
    F22). New gauges phargus.gc.pause.max and phargus.backpressure.stall.max (ns); new delta
    monotonic sums phargus.gc.pause.total and phargus.backpressure.stall.total (ns),
    phargus.backpressure.events ({event}), phargus.window.samples and
    phargus.window.late_samples ({sample}, from the window's count and late). The metrics
    resource now carries service.instance.id, host.name and process.pid beside
    service.name, so several instances no longer merge into one series. service.instance.id
    defaults to a random UUID generated once per process; the new serviceInstanceId option on
    createOtlpMetricsExporter and toOtlpMetrics overrides it, and an empty or non-string value
    throws a TypeError. The trace exporter is unchanged.

  • docs/API.md, a reference of every supported export per subpath. npm run check:exports now
    also compares each subpath's runtime export names with an exact expected list, through import
    and require, and fails on a name added or missing.

Fixed

  • Lower memory cost of HTTP tracing under load. The tracer's span buffer kept each of its 1024
    most recent spans as an object plus four strings, and under load each lived long enough to be
    promoted by V8 and die in the old generation (about 3× the agent-off promotion rate on a
    promise-heavy server, and about 25 MiB more RSS after a minute). Spans are now stored as bytes
    in preallocated slots, which take about 280 KiB for the default 1024 spans. Promotion and
    steady-state RSS now match the agent-off run. What is buffered, dropped and exported is
    unchanged.
  • Lower per-request CPU cost of HTTP tracing. Trace and span ids are now cut from a 4 KiB buffer
    of CSPRNG bytes refilled as it runs out, instead of one randomBytes() call (and Buffer) per
    id; a CPU profile of the overhead benchmark put those calls at about 16% of the busy time of a
    traced server. Ids keep their format (lowercase hex, never all zeros) and no byte is used twice.
  • The dashboard no longer reports a normal SSE client disconnect as a server error. A write to a
    connection the client had already closed (EPIPE) is now treated like ECONNRESET: the client
    is cleaned up and onError (or the process warning) is not called. Other errors on an SSE
    response or socket are still reported, and cleanup stays idempotent.
  • summarizeHeapSnapshot and diffHeapSnapshots (@pharn-dev/phargus/analyzer) no longer time
    out on large snapshots within a raised maxSnapshotBytes (review finding F27). The task timeout
    is now max(30 s, size / 20 MB/s), summed over both files for a diff, computed by the new
    heapSnapshotTimeoutMs(bytes) export. It applies when no timeoutMs is passed and the pool is
    the one the call makes or one from createHeapSnapshotPool() without taskTimeoutMs. An
    explicit timeoutMs always wins, and a pool made with taskTimeoutMs, createWorkerPool or
    anything else keeps its own timeout. At the default 256 MiB cap the timeout stays 30 s.
  • Collector persistence no longer backpressures consume() (review finding F25). A slow disk used
    to hold every window up behind the append, all the way back to the source. Windows now go
    through a bounded queue and are appended one at a time, in emission order, off the pipeline.
    persist.maxQueueSize sets how many wait (default 1024); it must be a positive safe integer,
    or createCollector throws a RangeError. When the queue is full the oldest window is dropped.
    collector.persistence.dropped counts those drops and collector.persistence.failed counts
    windows whose append failed (both integers). A failed append still rejects consume() with the
    append error, now without waiting for the source to end. close() and the end of consume()
    wait for the queue to drain, with no time limit, so a disk that never completes an append
    stalls close(). close() stops accepting windows before it drains, so a consume() still
    running cannot hold it open; a window that arrives after it is counted in failed.
  • OTLP exporters (@pharn-dev/phargus/otel) no longer lose spans and windows under load (review
    finding F2). They used to send one request per exported span or window, with one request in
    flight, and silently dropped the newest batch once 64 were queued. They now batch: pending
    items go out in one request when maxBatchSize (default 512) items are pending or after
    flushIntervalMs (default 1000 ms), one request at a time. At most maxQueueSize (default 2048) items are held; when full, the OLDEST pending items are dropped, counted and reported
    through onError as aggregated "dropped" reports. New counters droppedItems, exportedItems
    and failedItems sit beside droppedBatches and failedBatches. The flush timer is
    unref()ed and armed only while items are pending. A record that cannot be encoded fails only
    itself. Behaviour change: one export call is no longer one request, and the first send waits up
    to flushIntervalMs unless a full batch is pending; call close() or flush() before exit.
    queueCapacity is deprecated: still accepted and validated, but it no longer bounds anything
    (the queue holds items, not batches); use maxQueueSize.
  • Dashboard: a client that connects to /events now receives the collector's whole history
    (every buffered alert, window and span) instead of losing part of it to the live-event drop
    queue; with full buffers it previously got no alerts and a truncated window history. The replay
    is written in one call outside that queue, alerts first, then windows, then spans.
    maxBufferedEvents and droppedEvents now cover live events only.
  • Dashboard: a request whose Host is not allowed still gets 421, but now with a short
    text/plain body naming the allowedHosts option and phargus serve --allowed-host (review
    finding F24). It used to be bodyless, so behind a proxy or a container port map the browser
    showed a blank page. The rejected Host is not echoed back.
  • The collector no longer dies on non-agent stdout lines. collector.consume() now accepts any
    parsed records: foreign records (not agent data) and malformed ones (agent-shaped but unusable)
    are skipped and counted in collector.ignored, with an optional onIgnored hook, instead of
    rejecting consume(). Malformed agent records are skipped rather than thrown. The new
    createNdjsonDecoder export turns the byte stream into objects with bounded line memory and
    counts non-object (invalid) and over-long (oversized) lines.
  • Event loop figures no longer include the 10 ms timer interval (review finding F16). The
    sampler's histogram records the whole interval on every tick, so an idle process reported a min
    of about 10 ms and a p50 of about 11 ms, the dashboard showed that as lag, and any alert
    threshold below about 12 ms always fired. createEventLoopSampler now passes an explicit
    resolution to monitorEventLoopDelay and subtracts it from min, max, mean, p50 and p99,
    clamped at 0 in integer nanoseconds, so the values are delay beyond the timer interval and an
    idle loop reads close to 0. It takes an optional { resolution } (whole milliseconds, default
    10; anything else throws a RangeError), and the agent exports the EventLoopSamplerOptions
    type. Behaviour change: every event loop value, and every window and OTLP metric built from it,
    is about 10 ms lower. The bundled phargus/event-loop-lag rule (100 ms default) and the
    example app's 50 ms alert are unchanged; a threshold you set close to 10 ms now fires only on
    real delay.

Changed

  • The agent no longer warns about PHARGUS_TOKEN and PHARGUS_DEBUG. They belong to
    phargus serve, and the agent now ignores them silently, so a shell or container that runs
    both sides of the pipe can set them once. Other unknown PHARGUS_* variables still warn.
  • Releases now publish on merge: a PR that bumps the version (with its lockfile and a
    ## [X.Y.Z] section here) is the release. Every push to main runs the jobs gate, build,
    publish and release, which release only when package.json's version has no tag yet; the GitHub
    Release notes are that version's section of this file. NPM_PUBLISH_ENABLED still has to be
    true for the publish and release jobs to run. Checks for the release notes, the version files
    and the workflow run under npm test.
  • CI: the non-required node-latest workflow now also runs Platform smoke jobs on
    windows-latest and macos-latest (review finding F21). On the .nvmrc Node floor they run
    npm ci, build, check:exports and npm test, so platform-specific code paths (plugin child
    script paths, the symbolizer worker, process groups) get some CI coverage. The required checks
    still run on Linux only. .gitattributes now checks text files out with LF on every platform.
    On Windows, the tests for signal-driven graceful shutdown, a non-writable heap snapshot
    directory, the packed bin's execute bit and the release-workflow check are skipped;
    docs/LIMITS.md records these limits. The idle event loop tests now bound p50 by the sampler's
    resolution instead of 5 ms, because Windows timers leave an idle loop at about 5 ms.

Removed

  • The public entry points of @pharn-dev/phargus/agent, /collector, /dashboard and
    /plugin-runner no longer export internals and scaffold placeholders (review findings F18,
    F19). This is breaking for 0.x consumers that imported them. What is left is the list in
    docs/API.md. Removed:
    • agent: encodeNdjsonLine, createSpanExport, SpanExport, enable, disable,
      drainSpans, DEFAULT_SPAN_BUFFER_SIZE, HttpTracingOptions, SpanDrain, toSpanRecord,
      isSpanRecord, PhargusAgentPlaceholder
    • collector: createWindowAggregator, WindowAggregatorOptions, createSpanRouter,
      parseWindowLine, serializeWindow, CollectorPlaceholder
    • dashboard: DashboardPlaceholder
    • plugin-runner: PluginRunnerPlaceholder