Skip to content

lifecycle hooks at ingestion, query, alert evaluation and webhook dispatch (#216) - #241

Merged
Polliog merged 17 commits into
developfrom
feat/hooks-216
Jun 9, 2026
Merged

lifecycle hooks at ingestion, query, alert evaluation and webhook dispatch (#216)#241
Polliog merged 17 commits into
developfrom
feat/hooks-216

Conversation

@Polliog

@Polliog Polliog commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

Refs #216.

What

A small, typed set of four named lifecycle hooks, no-op by default in OSS:

Phase When Context
beforeIngest after auth/PII/quota, before reservoir write (covers HTTP + OTLP logs) org, project, eventCount, byteSize, mutable records
beforeQuery top of queryLogs, before the cache key org, projectIds, mutable params
beforeAlertEvaluation per rule in the eval loop org, ruleId, ruleType
beforeWebhookDispatch before safeFetch (channel + legacy alert paths) org, channelId/ruleId, readonly url/host, mutable headers/body

Handlers run sequentially in registration order, may mutate the documented fields, and abort by throwing HookRejectionError(code, message, statusCode) which the global error handler surfaces like capability errors. Unexpected hook errors fail closed (500, chained via Error.cause), except in the alert loop where a failing hook skips only that rule and the batch continues.

Registration

  • Code-level: hooks.register(...) from src/hooks/index.js in a downstream bootstrap.
  • Container: HOOKS_MODULES env (comma-separated module paths default-exporting (hooks, helpers) => void), loaded at boot on server and worker, fatal on load failure. External modules receive { HookRejectionError } as the second arg so they can produce clean 4xx rejections.

Notes

  • beforeIngest realigns downstream consumers (sigma, exceptions, pipelines, metering, correlation) when a hook filters records; a tenancy guard fails closed if a hook rewrites a record's projectId.
  • OTLP logs route passes 4xx hook statuses through and maps 5xx hook failures to retryable 503 (a 400 would tell exporters to permanently drop the batch).
  • Contract documented in docs/lifecycle-hooks.md.

Tests

56 new hook tests (registry, loader, all four call sites, HTTP-stack rejection). Full backend suite green except the pre-existing env-only digests/generator number-locale failures on Windows.

@codecov

codecov Bot commented Jun 9, 2026

Copy link
Copy Markdown

@Polliog
Polliog merged commit f8d09cc into develop Jun 9, 2026
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant