Skip to content

feat: add LogOutput::Custom variant for user-provided slog drains#206

Merged
TheJokr merged 6 commits into
cloudflare:mainfrom
ksurent:ksurent/custom-slog-drain
May 18, 2026
Merged

feat: add LogOutput::Custom variant for user-provided slog drains#206
TheJokr merged 6 commits into
cloudflare:mainfrom
ksurent:ksurent/custom-slog-drain

Conversation

@ksurent
Copy link
Copy Markdown

@ksurent ksurent commented May 14, 2026

Add a Custom variant to LogOutput that accepts an Arc. This allows users to provide their own slog drain (e.g., for Sentry integration) without needing wrapper macros or other workarounds.

The custom drain:

  • Receives the same downstream wrapping as built-in drains (field dedup, field redaction, etc.)
  • Is not serializable (must be set in code, not YAML)
  • Ignores LogFormat (responsible for its own formatting)

The Custom variant uses Arc<dyn ...> instead of Box<dyn ...> because:

  1. LogOutput must be Clone because LoggingSettings is cloned in telemetry::init(). Box<dyn ...> is not Clone.

  2. telemetry::init() receives &LoggingSettings. A Box cannot be moved out of a shared reference, but an Arc can be cheaply cloned from one. Changing init() to take ownership would be a breaking API change.

Co–authored–by: Claude Opus 4.6

Add a Custom variant to LogOutput that accepts an Arc<dyn CustomDrain>.  This
allows users to provide their own slog drain (e.g., for Sentry integration)
without needing wrapper macros or other workarounds.

The custom drain:
- Receives the same downstream wrapping as built-in drains (field dedup, field
  redaction, etc.)
- Is not serializable (must be set in code, not YAML)
- Ignores LogFormat (responsible for its own formatting)

The Custom variant uses Arc<dyn ...> instead of Box<dyn ...> because:

1. LogOutput must be Clone because LoggingSettings is cloned in
   telemetry::init(). Box<dyn ...> is not Clone.

2. telemetry::init() receives &LoggingSettings. A Box cannot be moved out of a
   shared reference, but an Arc can be cheaply cloned from one. Changing init()
   to take ownership would be a breaking API change.

Co–authored–by: Claude Opus 4.6
@ksurent ksurent force-pushed the ksurent/custom-slog-drain branch from 8218f9a to 69746bf Compare May 14, 2026 18:33
Comment thread foundations/src/telemetry/log/testing.rs Outdated
Comment thread foundations/src/telemetry/settings/logging.rs Outdated
Comment thread foundations/tests/custom_drain.rs Outdated
@TheJokr
Copy link
Copy Markdown
Collaborator

TheJokr commented May 18, 2026

Thank you!

@TheJokr TheJokr merged commit 72043bc into cloudflare:main May 18, 2026
18 checks passed
@TheJokr TheJokr mentioned this pull request May 19, 2026
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.

2 participants