Skip to main content

Observability & Monitoring

To maintain pricing accuracy and keep background jobs running smoothly, the pricing engine includes robust logging, error tracking, and rate drift detection tools.

📝 Logging Hierarchy & Standards

The pricing engine uses NestJS's structured logging framework with four severity levels:

1. Logger.log() (General Info)

  • Logs major milestones in the estimation pipeline (e.g. audience resolution, quote generation, and successful PDF compilation).
  • Example: Estimate generated in 42ms — KQ-2026-00042 — total: 1045.50

2. Logger.warn() (Warnings)

  • Logs non-critical issues that do not fail the calculation but require administrator attention.
  • Examples:
    • Missing country codes falling back to OTHER (suggests incomplete contact imports).
    • Platform fee rules falling back to the hardcoded 25% rule (suggests misconfigured default rules in the database).

3. Logger.error() (Errors)

  • Logs critical failures that abort estimation requests or fail background worker jobs.
  • Includes full stack traces and contextual metadata (e.g. vendorId, quotationId, and jobAttempts).
  • Examples:
    • Empty audience target selections.
    • Puppeteer Docker connection timeouts.

4. Logger.debug() (Debug)

  • Logs detailed transaction diagnostics (e.g. Redis cache hits/misses, row locking operations, and discount calculations).

📈 Pricing Drift & Deviation Tracking

Because Meta updates its pricing tables regularly, calculations must be monitored for drift against actual Meta delivery records.

Drift Auditing Pipeline

Post-Campaign Invoicing (Meta Webhook)


Compare Actual Meta Billings


Load Quotation snapshotId


Compute Absolute Pricing Discrepancy
[ Abs(Estimate - Actual) ]


Within Threshold Check? (e.g., 2%)
├── Yes ──> Silently Log OK
└── No ──> Trigger Alert

If actual billings deviate from estimations by more than 2%, the system logs a high-priority warning. This allows administrators to quickly identify outdated pricing rates or configuration drifts in the database.