Skip to content

feat: logging and event hooks for observability #12

Description

@mdesoto

Context

In production, developers need visibility into what BurnerGuard is doing — how many emails are being checked, what's matching, how often the allowlist overrides. The library should provide hooks for consumers to plug in their own logging, metrics, or alerting systems without BurnerGuard depending on any specific logging framework.

Proposed API

Event hooks at creation

const guard = await BurnerGuard.create({
    onVerify: (result) => {
        logger.info('BurnerGuard verify', {domain: result.domain, isMatch: result.isMatch});
    },
    onMatch: (result) => {
        logger.warn('Disposable email detected', {domain: result.domain, matchedOn: result.matchedOn});
    },
    onError: (error, context) => {
        logger.error('BurnerGuard error', {error: error.message, context});
    }
});

Available hooks

Hook Fires when Payload
onVerify Every verify() call completes VerifyResult
onMatch verify() returns isMatch: true VerifyResult
onAllowlistOverride A blocklist match was overridden by the allowlist VerifyResult
onError An error occurs (service mode failure, file load error, etc.) Error + context
onDegradation Service mode falls back to static (see #11) VerifyResult + reason

Design principles

  • No built-in logger — zero dependencies means no winston, pino, bunyan
  • Hooks are optional — if not provided, the library is silent
  • Hooks are fire-and-forget — errors in hooks don't affect verify() results
  • Hooks receive readonly data — consumers can't mutate results through hooks

Acceptance criteria

  • Hook options in BurnerGuardOptions
  • Hooks fire at the correct points in the verify lifecycle
  • Hook errors are swallowed (don't break verify())
  • Tests covering: each hook fires correctly, hook errors don't propagate
  • README section showing integration with common loggers (pino, winston)

Priority: 🟢 Nice-to-have — polish for production use

Activity

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

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions