Skip to content

fix(basket): stop logging expected conditions as errors in Axiom - #590

Merged
izadoesdev merged 3 commits into
stagingfrom
izadoesdev/basket-error-telemetry
Aug 4, 2026
Merged

fix(basket): stop logging expected conditions as errors in Axiom#590
izadoesdev merged 3 commits into
stagingfrom
izadoesdev/basket-error-telemetry

Conversation

@izadoesdev

@izadoesdev izadoesdev commented Aug 4, 2026

Copy link
Copy Markdown
Member

What

Follow-up to #589. Basket's Axiom error signal is ~100% noise: of 3.18M weekly level=error events, 3,169,529 (99.7%) are Event quota exceeded — a normal billing state (customer hit their plan limit). Rate limits, invalid client IDs, unauthorized origins, and a handled Redpanda→ClickHouse fallback are also logged as errors. Real errors (e.g. Failed to get website by ID, 135/wk) are drowned ~20,000:1, making error-rate alerting meaningless.

Root cause

The evlog Elysia plugin logs every thrown error via state.logger.error(err) and drops the error's status. Basket's onError marks 4xx as isExpectedClientError but doesn't downgrade the already-set level, and the drain's old 4xx→warn check keyed off error.status, which is gone by drain time (only error_message survives).

Fix

  1. Client errors → warn. Make the raw error spec the single source of truth in structured-errors.ts and derive CLIENT_ERROR_MESSAGES (messages with 4xx status) from it. The Axiom drain downgrades error → warn (+client_http_error) when http_status is 4xx or error_message is a known catalog client error. Ordering-independent — keys only off fields that survive to the drain.
  2. Handled Redpanda fallback → warn. The connection failure recovers via direct ClickHouse insert, so it's log.warn, not captureError.

Test

New evlog-basket.test.ts covers the downgrade matrix (catalog 4xx → warn, http_status 4xx → warn, 5xx catalog stays error, unknown stays error, string-error flattening). Full basket suite: 606 pass (vitest run); check-types green.

Follow-up

Once deployed, basket's error-rate panels/alerts will reflect real failures instead of quota noise.


Summary by cubic

Downgraded expected client HTTP errors to warn in Axiom and reclassified the Redpanda→ClickHouse fallback as warn, so Basket’s error signal reflects real failures instead of quota noise. Extracted Axiom drain helpers to @databuddy/shared/evlog-axiom and adopted them in Basket.

  • Bug Fixes

    • Downgrade events to warn (+client_http_error) in the Axiom drain when http_status is 4xx or error_message matches client errors derived from the catalog.
    • Flatten string error into error_message before classification for consistent handling.
    • Use log.warn for the handled Redpanda connection failure that falls back to direct ClickHouse insert.
  • Refactors

    • Moved the batched Axiom drain and HTTP enrichers to @databuddy/shared/evlog-axiom and switched Basket to use them.
    • Basket keeps catalog-driven client-error detection and calls the shared downgradeClientHttpError after normalization.

Written for commit 021e11e. Summary will update on new commits.

Review in cubic

Expected 4xx conditions (quota exceeded, rate limits, invalid client
IDs) were logged at error level because the evlog elysia plugin logs
every thrown error as error and drops the status. Derive the client
error message set from the error catalog and downgrade those events to
warn in the drain, keyed on http_status or the catalog message.
The fallback recovers the delivery via direct ClickHouse insert, so a
connection failure that is handled should not surface as an error in
Axiom. Log it via log.warn and assert the new channel in the test.
@unkey-deploy

unkey-deploy Bot commented Aug 4, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Unkey Deploy

Name Status Preview Inspect Updated (UTC)
links (preview) Ready Visit Preview Inspect Aug 4, 2026 12:21pm

@vercel

vercel Bot commented Aug 4, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
dashboard Ready Ready Preview Aug 4, 2026 12:23pm
databuddy-status Ready Ready Preview Aug 4, 2026 12:23pm
documentation Ready Ready Preview Aug 4, 2026 12:23pm

@vercel
vercel Bot temporarily deployed to Preview – dashboard August 4, 2026 12:10 Inactive
@vercel
vercel Bot temporarily deployed to Preview – documentation August 4, 2026 12:10 Inactive
@cursor

cursor Bot commented Aug 4, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: aa6f2eb0-b57f-41f8-a5da-2381c0c388c6

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@dosubot

dosubot Bot commented Aug 4, 2026

Copy link
Copy Markdown

📄 Knowledge review

Dosu skipped reviewing this PR because your organization has used its 200 included credits for the month. Your usage will reset on 2026-09-01. To have Dosu review this PR before then, ask your organization admin to upgrade to a pro account.


Leave Feedback Ask Dosu about Databuddy Add Dosu to your team

@greptile-apps

greptile-apps Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR reduces noisy Basket error telemetry by classifying known 4xx conditions and recoverable Redpanda connection failures as warnings.

  • Derives client-error messages directly from Basket’s structured error specification.
  • Normalizes Axiom events using surviving HTTP-status and catalog-message fields.
  • Logs Redpanda connection fallback at warning level while retaining error reporting for failed ClickHouse inserts.
  • Adds focused normalization and producer-delivery tests.

Confidence Score: 5/5

The PR appears safe to merge, with recoverable and expected conditions downgraded without suppressing downstream fallback-insert failures.

The normalization is limited to error-level events with numeric 4xx statuses or messages derived from the structured 4xx catalog, while unknown and server-side errors retain their level; failed ClickHouse fallback inserts continue to be captured as errors.

Important Files Changed

Filename Overview
apps/basket/src/lib/evlog-basket.ts Normalizes string errors and downgrades error-level events when a numeric 4xx status or known client-error message survives to the Axiom drain.
apps/basket/src/lib/structured-errors.ts Extracts the error catalog specification into a constant and derives the 4xx message set from that single source of truth.
apps/basket/src/lib/producer.ts Reclassifies recoverable Redpanda connection failures as warnings while preserving separate error capture for failed direct ClickHouse persistence.
apps/basket/src/lib/evlog-basket.test.ts Adds coverage for catalog and status-based downgrades, retained server errors, unknown errors, and string-error flattening.
apps/basket/src/lib/producer.delivery.test.ts Updates delivery tests to verify that a shared connection failure emits one warning instead of one captured error.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  E[Basket telemetry event] --> N[Normalize for Axiom]
  N --> C{Error level and client 4xx?}
  C -->|Yes| W[Emit warning with client_http_error]
  C -->|No| K[Preserve existing level]
  R[Redpanda connection failure] --> F[Select direct ClickHouse fallback]
  F --> L[Emit warning]
  F --> I{ClickHouse insert succeeds?}
  I -->|Yes| S[Delivery completes]
  I -->|No| X[Capture fallback failure as error]
Loading

Reviews (1): Last reviewed commit: "fix(basket): log redpanda to clickhouse ..." | Re-trigger Greptile

…log-axiom

Move the batched Axiom drain, HTTP enrichers, string/duration
normalization, and the client-error downgrade into a shared module so
basket (and future services) reuse them. Basket keeps its catalog-driven
client-error detection and delegates the mechanics to the shared helpers.
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