Skip to content

feat(server): a request wide event for every route #37

Closed

Description

@allisonmahmood

Part of the launch (#416).

Problem

Most requests leave no trace. Wide events (one structured record per request, sent to stdout for CloudWatch and to PostHog) cover only the runtime routes today. Publish, the portal, sign-in and device login, discovery, connections and the SDK routes emit about fifteen bare Effect.log lines. When a partner says "publish failed", there's nothing to look at.

Do

  • One request wide event for every non-runtime route. Use the existing accumulator and sink in @patchy/analytics/wide-events (the RequestEvent shape, WideEvents.enrich), with the runtime path's field rules: ids, principal, route, outcome and refusal code, duration and sizes. Never tokens, request bodies, draft HTML, filenames or SQL. Every event already carries deploymentRevision, which is how a request is traced to the build that served it.
  • docs/OPERATIONS.md: how to find a request's event in CloudWatch.

Out

Done when

Every route emits one event per request, and a test pins that no event carries a token or a request body.

Activity

  1. added
    ready-for-agent
    area:server
    area:docs
    on Aug 26, 2026
  2. allisonmahmood commented on Sep 2, 2026

    @allisonmahmood
    OwnerAuthor

    Grouped with the llms.txt pair (#36, #108): do all three together once staging is up and running, since each only earns its keep with a deployed server to ask. When picked up, the Do list needs refreshing: the server is on Effect now (Fastify is gone, so this is Effect's built-in request logger with disableLogger turned off in production), and docs/SELF_HOSTING.md no longer exists, so the reading-logs paragraph goes in whatever doc staging produces.

  3. changed the title [-]feat(server): GET /api/version and production request logging[/-] [+]feat(server): a request wide event for every route, and GET /api/version[/+] on Oct 2, 2026
  4. allisonmahmood commented on Oct 2, 2026

    @allisonmahmood
    OwnerAuthor

    Rescoped 2026-10-02 for the launch. The old Do list predated Effect (Fastify) and the wide-events decision. This now takes #383's first bullet, a request event for every route on the existing wide-events machinery, so we don't ship a plain request logger that #383 would replace. It no longer waits for staging or for #36/#108.

  5. changed the title [-]feat(server): a request wide event for every route, and GET /api/version[/-] [+]feat(server): a request wide event for every route[/+] on Oct 2, 2026
  6. allisonmahmood commented on Oct 2, 2026

    @allisonmahmood
    OwnerAuthor

    Dropped GET /api/version (2026-10-02), after the agent picking this up asked whether /api/release already covers it. It doesn't: /api/release describes the CLI package, which a server-only deploy leaves unchanged. Neither route is needed, though. ECS confirms rollouts in #415's deploy workflow, every wide event carries deploymentRevision, and #415's deep health check now reports the revision for a quick outside check.

  7. allisonmahmood commented on Oct 2, 2026

    @allisonmahmood
    OwnerAuthor

    This was generated by AI during triage.

    Agent Brief

    Category: enhancement
    Summary: Every server request outside the runtime path emits exactly one RequestEvent wide event, following the runtime path's field rules.

    Current behavior:
    Only /api/runtime/* produces wide events. Each runtime handler wraps its work in WideEvents.withEvent({ type: "request" }, …) and enriches it with ids, outcome, refusal code, limits and sizes. The subscriptions route opens its own request events and the stream emits stream events. Every other route emits nothing:

    • the auth, device-login, patches (publish, list, inspect, lifecycle), connections and SDK API groups;
    • the portal; the auth, device and connection pages; patch serving (/:company/:name/*, /~content/…, /~shell/…); the SDK tarball;
    • the API guard's refusals and both 404 fallbacks.

    The server runs with Effect's request logger disabled (disableLogger: true), and nothing replaces it. There are 34 bare Effect.log call sites; they stay on #383.

    Desired behavior:
    Each request outside /api/runtime/* produces exactly one type: "request" event through the existing WideEvents service and sink (stdout JSON plus PostHog). That includes requests the API guard refuses and requests no route matches.

    • Runtime keeps its own events. Runtime events stay unchanged. Whatever opens the new event must not wrap /api/runtime/*, or every runtime call gains a second, parent-linked event. The patch dev server mounts the runtime routes without the server's middleware and must keep working as it does today.
    • Record the route template, never the path. The event names the matched route template (/api/patches/:patchId, /:company/:name/*, or the fallback's own pattern for unmatched requests), plus the method and HTTP status. The raw URL and query string never appear, because they carry company handles, patch names, file paths, codes and return URLs.
      • Effect's router resolves the route inside global middleware, so a global middleware alone only sees the raw URL. Recovering the template is part of the work. Don't fall back to the path.
    • The outcome reflects what the client received. HttpApiBuilder encodes an endpoint's typed errors into responses inside the route, and the shared refuse helper in @patchy/api returns 4xx responses directly. An outer layer therefore sees a successful exit for a refusal, and the exit alone would record success. The rules:
      • a 2xx or 3xx response is success;
      • a 4xx response is refused and carries the code from its body when the body has one;
      • a 5xx response or a defect is failure;
      • an interruption stays interrupted.
    • Principal and ids.
      • The acting user goes in viewerId and their company in companyId. Per the analytics glossary, the viewer is the principal; the machine token is provenance and is not recorded.
      • Record them where identity is already resolved: the API's bearer Authorization middleware and the session helpers the pages use. Individual routes shouldn't each have to add them.
      • Routes about one patch add patchId, plus versionId where one exists. A publish adds the version it created.
      • Anonymous requests carry no viewer and fall back to the instance distinct id, as they do today.
    • Sizes and duration. durationMs comes from withEvent as it does now. requestBytes comes from the declared length, without reading the body. responseBytes is the size of the response sent.
    • Never on an event: tokens, cookies or session values, device or invite codes, request or response bodies, draft HTML, filenames, SQL, credentials, source addresses, raw URLs or query strings. Per the analytics glossary, events carry ids, sizes, counts and states.
    • Health probes emit nothing. The load balancer and the uptime check poll /healthz and the deep check feat(infra): production infrastructure in AWS CDK and the deploy workflow #415 adds from several places. That traffic adds up to tens of thousands of requests a day, would swamp the event stream and the PostHog bill, and tells us nothing. Exclude health-probe routes explicitly.

    RequestEvent gains the fields this needs: route template, method and status. Choose names that read clearly in a CloudWatch query. Make the new fields optional, so runtime events and the patch repo's local runtime keep their shape.

    Key interfaces:

    Acceptance criteria:

    • Each of these emits exactly one type: "request" event with route template, method, status, outcome and duration:

      • an authenticated API call;
      • a publish;
      • a portal page;
      • a sign-in or device-login page;
      • a connection page;
      • a served patch page;
      • the SDK tarball;
      • a request the API guard refuses;
      • an unmatched URL.
    • A runtime call still emits exactly one request event, unchanged from today.

    • A refused request has outcome: "refused" and the code from its response body. Test at least one refusal from an endpoint's typed error (for example, publish with a stale release) and one from the guard (a 429). A 5xx has outcome: "failure".

    • An authenticated request carries the user's viewerId and companyId. A publish carries the resulting patchId and versionId.

    • /healthz emits no event.

    • A test covers three requests:

      • a bearer-token publish with recognisable HTML and a known filename in its payload;
      • a page view authenticated by a session cookie;
      • a device-login exchange.

      It asserts that no emitted event's serialized JSON contains the token, the cookie value, the device code, the HTML, the filename or the raw request path.

    • docs/OPERATIONS.md describes request events for every route and how to find one in CloudWatch.

    • pnpm verify passes.

    Out of scope:

  8. added
    enhancement
    on Oct 2, 2026
  9. added 3 commits that reference this issue on Oct 2, 2026
    de858c1
    c5697f1
    7c88bfe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:docsarea:serverenhancementready-for-agent

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions