Skip to content

Accept keyword options in Sentry.add_logger_handler/1#4146

Open
alco wants to merge 2 commits intomainfrom
sentry-handler-opts
Open

Accept keyword options in Sentry.add_logger_handler/1#4146
alco wants to merge 2 commits intomainfrom
sentry-handler-opts

Conversation

@alco
Copy link
Copy Markdown
Member

@alco alco commented Apr 21, 2026

vetted by human ready for review

Summary

  • Electric.Telemetry.Sentry.add_logger_handler/1 now accepts a keyword list of options instead of just an id
  • Any option other than :id is merged into the Sentry.LoggerHandler config map, so downstream apps can tune handler settings like :discard_threshold and :sync_threshold at install time instead of calling :logger.update_handler_config/3 after the fact
  • Adds test/electric/telemetry/sentry_test.exs covering the default config, merged overrides, and override-wins semantics

Motivates/enables stratovolt#1473 and is used to fix https://github.com/electric-sql/stratovolt/issues/1458, where cloud-sync-service needs to cap the Sentry.LoggerHandler mailbox via :discard_threshold to avoid blocking log calls or unbounded mailbox growth under error bursts. Once this lands, that PR can collapse into a single call:

Electric.Telemetry.Sentry.add_logger_handler(
  discard_threshold: 2000,
  sync_threshold: nil
)

Test plan

  • MIX_TARGET=application mix test test/electric/telemetry/ (15 tests, 0 failures)
  • MIX_TARGET=application mix compile --warnings-as-errors

🤖 Generated with Claude Code

Let callers pass handler config overrides (e.g. :discard_threshold,
:sync_threshold) through to Sentry.LoggerHandler without having to
update the handler config out-of-band via :logger after the fact. The
:id option is still accepted to override the handler id; any other
option is merged into the handler's config map over the existing
defaults.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@alco alco added the claude label Apr 21, 2026
@claude
Copy link
Copy Markdown

claude Bot commented Apr 21, 2026

Claude Code Review

Summary

This PR refactors Electric.Telemetry.Sentry.add_logger_handler to accept an optional second argument (a keyword list of config overrides), enabling callers to tune Sentry.LoggerHandler settings like :discard_threshold at install time. All issues from the previous review were addressed and the implementation is clean.

What's Working Well

  • The API redesign from the first iteration is much better: add_logger_handler with id and opts defaults preserves the existing atom-ID-only calling convention, eliminating the backward-compat concern
  • @type handler_opts with @typedoc adds useful documentation without over-specifying
  • default_handler_id/0 is an elegant solution to the test duplication concern: no magic string copying, and it is genuinely useful for external consumers (like stratovolt) who need to inspect or remove the default handler
  • Test comment now clearly explains both why async: false is required and what unique IDs accomplish
  • patch changeset level is correct now that backward compat is preserved

Issues Found

No critical or important issues remain.

Suggestions (Nice to Have)

describe label covers only one arity

File: packages/sync-service/test/electric/telemetry/sentry_test.exs:20

The describe block is named "add_logger_handler/2" but the last test inside it calls add_logger_handler() with zero arguments. Since the tests cover /0, /1, and /2, consider naming it "add_logger_handler" (without the arity suffix) to avoid confusion.

Issue Conformance

No linked issue; previous review noted this. The PR description remains clear and the tests provide sufficient acceptance criteria. No new concern here.

Previous Review Status

All issues from iteration 1 were addressed:

  • Breaking change / wrong changeset level — Fixed by changing the signature to two args with defaults, preserving the atom-ID-only form; patch is now correct
  • Misleading test comment — Replaced with the suggested copy explaining VM-global state vs. name collisions
  • @spec precision — Three @spec overloads added plus @type handler_opts with @typedoc
  • Default handler ID duplication — Fixed via the new default_handler_id/0 public accessor

Review iteration: 2 | 2026-04-21

Revise the API so add_logger_handler/1's original atom-id contract is
preserved: id is the first optional positional arg, and a keyword list
of handler-config overrides is the second optional arg. Callers passing
a bare atom keep working unchanged.

Also address review feedback:
- Add a @type handler_opts so the opts shape is documented in the spec
- Expose default_handler_id/0 so external callers don't have to
  hard-code :electric_sentry_handler
- Rewrite the test's async: false comment to explain the VM-global
  :logger state (not just handler-id isolation)
- Reference default_handler_id/0 from the default-id test instead of
  duplicating the atom

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.20%. Comparing base (388ec63) to head (aa072e2).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4146   +/-   ##
=======================================
  Coverage   89.20%   89.20%           
=======================================
  Files          25       25           
  Lines        2520     2520           
  Branches      636      641    +5     
=======================================
  Hits         2248     2248           
  Misses        270      270           
  Partials        2        2           
Flag Coverage Δ
packages/experimental 87.73% <ø> (ø)
packages/react-hooks 86.48% <ø> (ø)
packages/start 82.83% <ø> (ø)
packages/typescript-client 94.30% <ø> (ø)
packages/y-electric 56.05% <ø> (ø)
typescript 89.20% <ø> (ø)
unit-tests 89.20% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants