@claxedo/workspace-relay 0.6.0 → 0.7.0

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/main.d.ts CHANGED
@@ -4,48 +4,68 @@ import { type RelayHostPublicKey, type RevocationLookup, type WorkspaceRelayTarg
4
4
  import type { RelayKey } from "./auth";
5
5
  export { createCachedRevocationClient, createCachedTargetClient } from "./server";
6
6
  /**
7
- * D12 observability: Sentry on the relay (ops floor ADR
8
- * docs/plans/2026-07-11-016-wp-ops-floor-design.md §4).
7
+ * W2c (2026-07-28-001): PostHog is the relay's error sink — one vendor
8
+ * carries error tracking for every runtime behind one distinct_id space.
9
9
  *
10
- * Gated on `CLAXEDO_RELAY_SENTRY_DSN` (the relay's OWN DSN env — separate
11
- * Sentry project from the control plane). Absent DSN → `Sentry.init` is never
12
- * called: zero SDK overhead, zero network — the documented no-op posture, safe
13
- * before the Sentry account exists. Release = git SHA passed by the D11
14
- * deploy workflow (`CLAXEDO_RELEASE`; `GIT_SHA` accepted as alias); events are
15
- * tagged unit=relay + deployment_mode (absent → "self-host", mirroring D9's
16
- * default). Tracing stays off (ADR: it is where Sentry gets expensive).
10
+ * Sending requires two independent opt-ins: `CLAXEDO_TELEMETRY_MODE=on` AND
11
+ * `CLAXEDO_POSTHOG_KEY` (`POSTHOG_KEY` accepted as a fallback — the same
12
+ * unprefixed name claxedo-server's posthog.ts already reads). Any other
13
+ * combination → no `PostHog` client is ever constructed: zero SDK overhead,
14
+ * zero network — a clean no-op safe to ship before the telemetry account
15
+ * exists. Host defaults to `https://us.i.posthog.com` (the canonical ingest
16
+ * host — NOT the legacy `app.posthog.com` default some SDKs ship). Release =
17
+ * git SHA passed by the D11 deploy workflow (`CLAXEDO_RELEASE`; `GIT_SHA`
18
+ * accepted as alias); captures are tagged unit=relay + deployment_mode
19
+ * (absent → "self-host", mirroring D9's default).
17
20
  *
18
- * The relay is a Bun process (`Bun.serve`), so this uses `@sentry/bun` —
19
- * Sentry's Bun-native SDK with the same init-gated pattern as @sentry/node
20
- * (https://docs.sentry.io/platforms/javascript/guides/bun/).
21
+ * `posthog-node` runs fine on Bun (`Bun.serve`), unlike the Cloudflare
22
+ * Worker, which keeps it off its import graph entirely (see worker.ts).
21
23
  */
22
24
  export type RelayObservabilityEnv = {
23
- CLAXEDO_RELAY_SENTRY_DSN?: string | undefined;
25
+ /** Only `on` permits sending, matched case-insensitively after trimming. */
26
+ CLAXEDO_TELEMETRY_MODE?: string | undefined;
27
+ CLAXEDO_POSTHOG_KEY?: string | undefined;
28
+ POSTHOG_KEY?: string | undefined;
29
+ CLAXEDO_POSTHOG_HOST?: string | undefined;
24
30
  CLAXEDO_RELEASE?: string | undefined;
25
31
  GIT_SHA?: string | undefined;
26
32
  CLAXEDO_DEPLOYMENT_MODE?: string | undefined;
27
33
  /** Accept process.env verbatim (extra keys are ignored). */
28
34
  [key: string]: string | undefined;
29
35
  };
30
- export type RelaySentryOptions = {
31
- dsn: string;
36
+ export type RelayTelemetryOptions = {
37
+ key: string;
38
+ host: string;
32
39
  release?: string;
33
- tracesSampleRate: 0;
34
- initialScope: {
35
- tags: {
36
- unit: "relay";
37
- deployment_mode: string;
38
- };
40
+ tags: {
41
+ unit: "relay";
42
+ deployment_mode: string;
39
43
  };
40
44
  };
41
45
  /**
42
- * Pure env → Sentry options resolver. `undefined` = DSN absent = do NOT init
43
- * (no client, no network). Exported for tests.
46
+ * Pure env → PostHog options resolver. `undefined` = do NOT construct a client
47
+ * (no client, no network), which is the answer unless BOTH opt-ins are
48
+ * present. The mode is read before the key so that a deployment which has not
49
+ * said `on` stays silent no matter which keys reach its environment.
50
+ * Exported for tests.
44
51
  */
45
- export declare function relaySentryOptions(env: RelayObservabilityEnv): RelaySentryOptions | undefined;
52
+ export declare function relayTelemetryOptions(env: RelayObservabilityEnv): RelayTelemetryOptions | undefined;
46
53
  export declare function initRelayObservability(env?: RelayObservabilityEnv): {
47
54
  enabled: boolean;
48
55
  };
56
+ /**
57
+ * Capture-and-flush used by the fatal handlers and the startup catch. With no
58
+ * initialized client (key absent) this is a documented no-op. Never throws —
59
+ * observability must not preempt the exit path.
60
+ *
61
+ * `distinctId: "system"` mirrors the ops-plane convention: process-fatal
62
+ * events carry no user identity. `client.flush()` has no built-in timeout,
63
+ * so it races a 2s timer; the flush promise's
64
+ * rejection is swallowed even when the timer wins the race, so a slow network
65
+ * failure that resolves after the timeout never surfaces as a second
66
+ * unhandledRejection mid-shutdown.
67
+ */
68
+ export declare function reportFatal(error: unknown): Promise<void>;
49
69
  /**
50
70
  * Production fail-closed gate for the relay → claxedo-server resolver channel.
51
71
  *
@@ -212,9 +232,9 @@ export type FatalProcessHandlerOptions = {
212
232
  log?: (message: string) => void;
213
233
  register?: boolean;
214
234
  /**
215
- * D12: error-tracker hook, invoked (and awaited) before teardown so a fatal
216
- * crash reaches Sentry before the process exits. Failures are logged and
217
- * never block the exit path. Defaults to none (tests, DSN-absent runs).
235
+ * W2c: error-tracker hook, invoked (and awaited) before teardown so a fatal
236
+ * crash reaches PostHog before the process exits. Failures are logged and
237
+ * never block the exit path. Defaults to none (tests, key-absent runs).
218
238
  */
219
239
  report?: (error: unknown, source: "uncaughtException" | "unhandledRejection") => void | Promise<void>;
220
240
  stopServer?: () => Promise<void> | void;