Skip to content

v0.3.1

Latest

Choose a tag to compare

@github-actions github-actions released this 01 Dec 10:29
0780f44

Added

  • The pharn.dev link says how much traffic each commit served, so "no errors since the deploy" can
    be told from "no requests since the deploy" (CORE-527). Each interval's request now carries an
    optional traffic list: per commit, requests (spans the collector received, one per incoming
    HTTP request) and dropped (spans the agent dropped), with lowerBound: true when dropped is
    above 0. Counts only: no path, method or status. A commit that served requests and raised no
    error is still sent, once per interval, with an empty groups list; a process with no request
    data (no HTTP, or none in the interval) sends no traffic entry rather than 0. Counted in
    phargus serve from the spans and drop counters the agent already writes: no new work in the
    agent. docs/schema/production-errors.v1.json stays version 1: traffic is optional and
    groups may now be empty. New types PharnPayloadTraffic and PharnTrafficInput;
    buildPharnPayload takes the counts as an optional third argument.

  • A Next.js server error's frames can be mapped inside the function that threw (CORE-550). Next
    writes a .map next to every server chunk, but output: 'standalone' and a Vercel function leave
    them out; addNextServerSourceMapsToTraces(distDir), run from next.config's
    compiler.runAfterProductionCompile, adds each traced chunk's map to Next's file traces and strips
    its sourcesContent. mapErrorFramesInProcess(frames) then maps frames in the calling process
    (no worker pool, no phargus serve) to the repository path and line, and leaves a frame it cannot
    map at its built position with unmapped: true; reportNextError now maps its frames with it, so
    an error sent from a function names lib/thrower.ts and its line. Both are new exports of
    @pharn-dev/phargus/analyzer, with DEFAULT_MAX_IN_PROCESS_MAP_BYTES (8 MiB). Checked on Next.js
    16.4.6 under output: 'standalone' and on a Vercel preview deployment (docs/LIMITS.md section 8).

  • A Next.js error on a serverless function reaches pharn.dev. reportNextError(error, request, context) from @pharn-dev/phargus/pharn, called in onRequestError in instrumentation.ts,
    builds the allow-listed payload for that one error and starts one request without making the
    hook wait: the promise goes to the platform's waitUntil (@vercel/request-context, no
    dependency), else it runs on its own with a 5 s timeout, so a route handler's 500 is not delayed.
    It reads PHARGUS_PHARN_KEY (no key: nothing sent, no fetch), takes the commit from
    VERCEL_GIT_COMMIT_SHA (or PHARGUS_COMMIT), sends frames mapped in-process where the chunk's
    map was shipped and otherwise at their built position flagged unmapped, sends nothing from a
    non-production VERCEL_ENV unless PHARGUS_PHARN_PREVIEW_KEY is set, keeps at most 10 requests in flight, and never throws. It does not need
    @pharn-dev/phargus/agent, so no sampler or request tracing starts. examples/nextjs-app/serverless
    is a real Next.js 16 app showing it, installed on its own.

  • An optional link sends error groups to pharn.dev. It is off until a key is set: phargus serve
    reads PHARGUS_PHARN_KEY (and PHARGUS_PHARN_URL for a test intake) from the environment, and
    the agent ignores both. Every 10 seconds it sends one request with the errors seen since the last,
    grouped by signature: per group the class, code, origin, frames (repository-relative path, line,
    column, function, and unmapped; a frame that is not in-app is sent with its function name
    only), commit, count, first and last seen, and once the Node.js version. Never the message, stack
    text, request paths or absolute paths: the payload is built from an allow-list and matches
    docs/schema/production-errors.v1.json, the schema pharn.dev validates. HTTPS only (http: to
    loopback for tests), no redirects, the key only in an Authorization header, a bounded queue with
    retries and backoff, a 5-minute pause after a 401 or 403 (reported once), and pharn.dropped on
    the counts: line. New entry point @pharn-dev/phargus/pharn: createPharnExporter (the
    collector listener), createPharnSender and buildPharnPayload (for an in-process reporter),
    DEFAULT_PHARN_URL. A collector listener can now take an error callback, called for every error
    the collector keeps, not only the 10 a window lists. A test reads the built agent and fails if it
    holds code that opens a connection.

  • An error has a signature that survives a deploy. Every error a collector window lists carries
    signature: v1: and the SHA-256 of its class and the repository path and function name of its
    3 innermost in-app frames, with no line, column, message or code, so an edit above a frame keeps
    it and a renamed function gets a new one. Without in-app frames (a collector with no repository
    root) it falls back to file basenames. A weak signature carries signatureFlags (anonymous,
    unmapped, no-in-app-frames); windows read back from disk get it recomputed. The algorithm is
    specified in docs/API.md so a receiver can recompute it, and docs/LIMITS.md says when two
    bugs merge and one splits. New collector exports: errorSignature, groupErrors (count, first
    and last seen per signature) and types ErrorSignature, ErrorSignatureFlag, ErrorGroup,
    SignableError.

  • Error frames name the source file and line, not the built file. The collector maps each error's
    frames through source maps, off its stream pipeline: createCollector({ symbolizeErrorFrames })
    takes a function, and createErrorFrameSymbolizer({ repoRoot }) from
    @pharn-dev/phargus/analyzer builds one that runs on the symbolization worker, with its caps
    (32 MiB per built file or map by default, DEFAULT_MAX_ERROR_MAP_BYTES) and reads confined to the
    repository root. phargus serve --repo-root <dir> (or PHARGUS_REPO_ROOT) turns it on. Each
    frame then carries inApp, a repository-relative path (in-app frames only: never a full path)
    and, when it could not be mapped, unmapped: true with its built position kept. A map whose
    source lies outside the root is refused, a malformed map costs only its own file's frames, and a
    dependency, a file outside the root or a Node internal frame is inApp: false. A symbolizer
    failure keeps the error with the agent's frames and counts it (collector.symbolization,
    collector.symbolizeFailed on the counts: line). New exports: createErrorFrameSymbolizer,
    DEFAULT_MAX_ERROR_MAP_BYTES, ErrorFrameSymbolizer, ErrorFrameSymbolizerOptions (analyzer),
    and types ErrorFrame, SymbolizeErrorFrames, ErrorSymbolization (collector).

  • captureError(error) (agent) reports an error your application handled: it writes the same
    error line as an uncaught exception, with origin handled and the traceId of the request in
    progress, so a framework's 500 is tied to the error behind it. It accepts any value (a non-Error
    is recorded by its type), never throws, does nothing while the agent is not running, and queues
    the line in the agent's non-blocking output instead of writing it synchronously. At most 10
    handled error lines are written per second; the rest are counted in the sample line's
    dropped.errors (present once above 0), which collector windows keep and the dashboard shows.
    The collector accepts origin handled. docs/API.md and the README give recipes for an Express
    error middleware, a Fastify onError hook and a Next.js onRequestError in instrumentation.ts;
    examples/express-app now reports its GET /error through an Express-shaped error middleware,
    and new examples/fastify-app and examples/nextjs-app cover the other two, without installing
    any framework.

  • Every window and span names the commit its process runs. The agent reads PHARGUS_COMMIT once at
    start, or else the first of VERCEL_GIT_COMMIT_SHA, RENDER_GIT_COMMIT,
    RAILWAY_GIT_COMMIT_SHA, HEROKU_BUILD_COMMIT and HEROKU_SLUG_COMMIT that is set, and writes it
    in one header line ({"type":"header","pid":…,"commit":"…"}) before any other line. A value that
    is not 7 to 40 hexadecimal characters is ignored, counted (commitIgnored) and warned about on
    stderr; the agent never runs git or reads .git, and with no variable set no header line is
    written. The collector attaches the commit to windows and spans (commit), the dashboard header
    shows the short sha or "commit unknown", and OTLP resources carry it as vcs.ref.head.revision.

  • The agent records uncaught exceptions and unhandled rejections. Each one becomes one NDJSON line
    with type: "error": class, code (only when it is letters, digits and _), origin
    (uncaught or rejection), up to 32 frames (file, line, column, function) parsed from
    the stack string, the traceId of the request in progress, pid and timestamp. It is written
    synchronously, so it reaches the output before the process exits. The agent listens on
    uncaughtExceptionMonitor only: whether the process dies, its exit code and its stderr do not
    change. The message is left out unless PHARGUS_ERROR_MESSAGES=1 (config key errorMessages).
    Collector windows carry an errors field (count and the first 10 errors) when they received
    any (each error with the run's commit), persisted windows keep it, and the dashboard lists them. New types: ErrorRecord,
    ErrorFrame, ErrorOrigin (agent), WindowError, WindowErrors (collector).

Fixed

  • A process that was stopped and resumed (SIGSTOP, a paused container, a suspended serverless
    instance) no longer reports the stop as event-loop delay, and an event-loop alert no longer fires
    on every resume. When the time since the agent's previous sample is longer than
    max(5 × PHARGUS_INTERVAL_MS, 1 s), the event loop spent more than half of it idle and the
    process used less CPU time than half of it, the sample carries suspendedMs (the gap minus the
    interval) and zero eventLoop figures. A busy loop, however long, stays event-loop delay: its
    loop is not idle. The collector leaves such
    samples out of a window's event-loop figures and counts them in the window's new optional
    suspended: { count, totalMs } field, which persisted windows keep. See docs/LIMITS.md §9.
  • A stall that began right after a sampler tick, or was due with it, could vanish from every
    sample: reading the event-loop histogram resets the timestamp its own timer measures from, so a
    read that ran before that timer had recorded the stall dropped it. Above a 20 ms interval a tick
    now reads its samplers only once the histogram's timer has recorded after it (or after a stall
    that made the read late), checking every 20 ms for at most 200 ms.
  • On Windows with stdout a pipe, an uncaught exception that came while the agent's own stdout
    writer had a sample line in flight lost its error line: the line was queued behind the sample
    and the process exited first. Since the sampler change above, samples are written at the moment
    an app's timer is likely to throw, so this happened often. The error line is now written at once
    and lands whole before or after the line in flight; it is still queued behind a line only
    part-written. See docs/LIMITS.md §1 and §3 for what remains (process.stdout with bytes queued by a
    slow reader, and a Windows pipe whose reader has stopped).