Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion skills/sentry-elixir-sdk/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,6 @@ Connecting Phoenix backend and JavaScript frontend with linked Sentry projects e
| Source code context missing in production | Run `mix sentry.package_source_code` before building your OTP release |
| Context not appearing on async events | `Sentry.Context.*` is process-scoped; pass values explicitly or propagate Logger metadata across processes |
| Oban integration not reporting crons | Requires Oban v2.17.6+ or Oban Pro; cron jobs must have `"cron" => true` in job meta |
| Duplicate events from Cowboy/Bandit crashes | Set `excluded_domains: [:cowboy, :bandit]` in `LoggerHandler` config (both excluded by default as of v13.1.0) |
| Duplicate events from Cowboy crashes | Set `excluded_domains: [:cowboy]` in `LoggerHandler` config (excluded by default) |
| `finch` not starting | Ensure `{:finch, "~> 0.21"}` is in deps; Finch is the default HTTP client since v12.0.0 |
| JSON encoding error | Add `{:jason, "~> 1.4"}` and set `json_library: Jason` for Elixir < 1.18 |
44 changes: 44 additions & 0 deletions skills/sentry-elixir-sdk/references/logging.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,49 @@ config :sentry,

`enable_logs: true` automatically wires up a Logger handler that captures log entries and forwards them to the Sentry Logs Protocol endpoint via the `TelemetryProcessor`.

### Unified Config: Error Events + Structured Logs (since v13.2.0)

The `enable_logs: true` path can now **also capture error events** (crashes and Logger messages) in addition to structured logs, eliminating the need to manually configure `LoggerHandler` for most use cases:

```elixir
# config/config.exs
config :sentry,
enable_logs: true,
logs: [
# Structured logs sent to Sentry's Logs UI:
level: :info,
metadata: [:request_id],
excluded_domains: [:cowboy],

# Error events (crashes + Logger messages):
capture_log_messages: true, # also report Logger messages as error events
capture_level: :error, # minimum level for error events (default: :error)
capture_metadata: [:request_id, :user_id], # metadata for error events
capture_excluded_domains: [:cowboy] # domains to exclude from error events
]
```

With this config:
- `:info` and higher logs → Sentry Logs UI (structured logs)
- `:error` and higher logs → Sentry Issues (error events)
- Crashes are always reported as error events (regardless of `capture_log_messages`)

### Logs Protocol Configuration Options (enable_logs: true)

| Option | Type | Default | Description |
|--------|------|---------|-------------|
| **Structured Logs (Logs UI)** | | | |
| `:level` | `Logger.level` | `:info` | Minimum log level for structured logs sent to Logs UI |
| `:metadata` | `[atom] \| :all` | `[]` | Logger metadata keys to include as log attributes |
| `:excluded_domains` | `[atom]` | `[]` | Domains to exclude from structured logs |
| **Error Events (Issues)** | | | |
| `:capture_log_messages` | `boolean` | `false` | When `true`, Logger messages (e.g., `Logger.error("oops")`) are also reported as error events. Crashes are always reported regardless of this setting. Since v13.2.0 |
| `:capture_level` | `Logger.level` | `:error` | Minimum level for error events (including crashes). Since v13.2.0 |
| `:capture_metadata` | `[atom] \| :all` | `[]` | Logger metadata keys to include in error events (added under `:extra` as `logger_metadata`). Since v13.2.0 |
| `:capture_excluded_domains` | `[atom]` | `[]` | Domains to exclude from error events. Since v13.2.0 |
Comment on lines +200 to +205

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Documentation for enable_logs: true is near pre-existing text that incorrectly implies excluded_domains defaults to [:cowboy], which is no longer true for this new configuration.
Severity: MEDIUM

Suggested Fix

Update the pre-existing "Best Practices" and "Troubleshooting" sections (lines 249 and 259) to clarify that the [:cowboy] default only applies to the older LoggerHandler configuration, not the new enable_logs: true method. Alternatively, remove the outdated claims about the default.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: skills/sentry-elixir-sdk/references/logging.md#L200-L205

Potential issue: The new documentation recommends using `enable_logs: true` for log
configuration. While the new configuration table correctly states that
`excluded_domains` defaults to `[]` in this mode, it is placed directly above
pre-existing "Best Practices" and "Troubleshooting" sections. These older sections claim
the default for `excluded_domains` is `[:cowboy]`. This creates a misleading context
where users adopting the new `enable_logs: true` feature will likely believe Cowboy
domains are excluded by default and will not configure `excluded_domains: [:cowboy]`
themselves, resulting in duplicate Cowboy crash events being sent to Sentry.

Did we get this right? 👍 / 👎 to inform future reviews.


> **Note:** The `:capture_*` keys configure **error events** independently from the structured logs keys. You can capture structured logs at `:info` while only creating error events at `:error`.

### Filter logs before sending

```elixir
Expand Down Expand Up @@ -202,6 +245,7 @@ You can run both simultaneously. A common setup: `LoggerHandler` at `:error` lev
## Best Practices

- Prefer `Sentry.LoggerHandler` over `Sentry.LoggerBackend` for new projects — `LoggerHandler` is the Erlang `:logger` handler and runs in the calling process, which is more efficient
- For v13.2.0+, prefer `enable_logs: true` with `capture_log_messages: true` over manually configuring `LoggerHandler` — it handles both structured logs and error events
- Set `excluded_domains: [:cowboy]` (the default) to avoid duplicate events when using `Sentry.PlugCapture` with Cowboy
- Enable `capture_log_messages: true` to catch error-level log messages that are not explicit `capture_exception` calls
- Use `tags_from_metadata` to promote high-cardinality identifiers (user ID, region, request ID) to searchable Sentry tags
Expand Down