Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ npx wrangler secret put DATADOG_SITE -c worker/wrangler.jsonc
npm run worker:tail
```

`GET /health` on the Worker returns whether each sink is configured and
emits structured lines through the Pegma adapters.
`GET /health` on the Worker uses `@pegma/health` (process + logging sink
booleans), returns the shared JSON shape, and emits `health.ok` through the
Pegma adapters with the checks registered today.

## The content rule

Expand Down
23 changes: 23 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"worker:tail": "wrangler tail pegma-dev-api"
},
"dependencies": {
"@pegma/health": "file:worker-vendor/pegma-health-0.1.0.tgz",
"@pegma/logger-cloudflare": "^0.1.1",
"@pegma/logger-datadog": "^0.1.1",
"@pegma/logger-tee": "^0.1.1",
Expand Down
20 changes: 20 additions & 0 deletions src/data/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,24 @@ export const components: readonly PegmaComponent[] = [
now: '0.1.1 on npm; trusted publishing configured. Host tee wiring next.',
plan: 'docs/PROJECT_PLAN.md',
},
{
repo: 'health',
title: 'Health',
packages: ['@pegma/health'],
status: 'in development',
summary:
'Composable health probes and HTTP responses for public liveness checks.',
owns: [
'Check contracts, aggregation, and HTTP status mapping',
'Process, detail, and injected Store ping helpers',
'Spine log events health.ok / health.degraded / health.failed',
],
refuses: [
'Owning a storage adapter or inventing domain collections',
'Autodiscovery of checks — hosts register them at the composition root',
'Metrics, APM, or alert fan-out',
],
now: 'Phase 1 implemented (0.1.0, public API unstable).',
plan: 'docs/PROJECT_PLAN.md',
},
];
13 changes: 13 additions & 0 deletions worker-vendor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Vendored Health package

`pegma-health-0.1.0.tgz` is the exact npm-pack artifact from
`pegma-dev/health` commit `35a878b` (`@pegma/health` 0.1.0).

Generated with:

```text
npm ci
npm pack --workspace @pegma/health --pack-destination <pegma.dev>/worker-vendor
```

Remove this bridge when `@pegma/health` has a public npm release.
Binary file added worker-vendor/pegma-health-0.1.0.tgz
Binary file not shown.
35 changes: 32 additions & 3 deletions worker/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# pegma-dev-api Worker

Thin Cloudflare Worker that proves pegma.dev's Pegma logging composition:
Thin Cloudflare Worker that proves pegma.dev's Pegma logging composition and
hosts the public health endpoint via `@pegma/health`:

```ts
createTeeLogger(
Expand Down Expand Up @@ -39,5 +40,33 @@ token needs **Workers:Edit** in addition to **Pages:Edit**.

## Endpoints

- `GET /` or `GET /health` — JSON health; emits `request.received` and
`health.ok` through the teed Spine logger.
- `GET /` or `GET /health` — JSON from `@pegma/health`
(`createProcessCheck` + logging sink booleans). Emits `request.received`
and, with the checks registered today, `health.ok` through the teed Spine
logger (both checks are always `ok`; an absent Datadog key is detail only).
Package mapping for when a check reports otherwise: HTTP `200` for status
`ok`/`degraded`, `503` for status `fail` (log event `health.failed`).
No storage probe yet (D1 consumer still gated).

Example body:

```json
{
"ok": true,
"status": "ok",
"service": "pegma-dev-api",
"checkedAt": "2026-07-27T21:00:00.000Z",
"checks": {
"process": { "status": "ok" },
"logging": {
"status": "ok",
"detail": { "cloudflare": true, "datadog": true }
}
}
}
```

## Vendored `@pegma/health`

Until `@pegma/health` is on npm, the Worker depends on
`worker-vendor/pegma-health-0.1.0.tgz` packed from `pegma-dev/health`.
27 changes: 17 additions & 10 deletions worker/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import {
createDetailCheck,
createProcessCheck,
runHealthChecks,
toHealthResponse,
} from '@pegma/health';
import { createAppLogger, type LoggerEnv } from './logger';

export interface Env extends LoggerEnv {}
Expand All @@ -24,18 +30,19 @@ export default {
});

if (request.method === 'GET' && (path === '/' || path === '/health')) {
logger.log('info', 'health.ok', { path });
return Response.json(
{
ok: true,
service: 'pegma-dev-api',
logging: {
const result = await runHealthChecks({
service: 'pegma-dev-api',
logger,
checks: [
createProcessCheck(),
createDetailCheck('logging', {
cloudflare: true,
datadog: Boolean(env.DATADOG_API_KEY),
},
},
{ status: 200 },
);
}),
],
});
const { status, body } = toHealthResponse(result);
return Response.json(body, { status });
}

logger.log('warn', 'request.not_found', { method: request.method, path });
Expand Down