Skip to content

Commit a2b0575

Browse files
authored
feat(elixir): logs docs (#16237)
In the Elixir SDK 12.0.0 we're adding support for Logs, so here are the docs 😄 ## Preview https://sentry-docs-git-solnic-logs-docs-for-elixir.sentry.dev/platforms/elixir/logs/ ## IS YOUR CHANGE URGENT? Help us prioritize incoming PRs by letting us know when the change needs to go live. - [ ] Urgent deadline (GA date, etc.): <!-- ENTER DATE HERE --> - [ ] Other deadline: <!-- ENTER DATE HERE --> - [x] None: Not urgent, can wait up to 1 week+ ## SLA - Teamwork makes the dream work, so please add a reviewer to your PRs. - Please give the docs team up to 1 week to review your PR unless you've added an urgent due date to it. Thanks in advance for your help! ## PRE-MERGE CHECKLIST *Make sure you've checked the following before merging your changes:* - [x] Checked Vercel preview for correctness, including links - [x] PR was reviewed and approved by any necessary SMEs (subject matter experts) - [x] PR was reviewed and approved by a member of the [Sentry docs team](https://github.com/orgs/getsentry/teams/docs) ## LEGAL BOILERPLATE <!-- Sentry employees and contractors can delete or ignore this section. --> Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms. ## EXTRA RESOURCES - [Sentry Docs contributor guide](https://docs.sentry.io/contributing/)
1 parent 5f7c49b commit a2b0575

13 files changed

Lines changed: 300 additions & 0 deletions

File tree

docs/platforms/elixir/configuration/options.mdx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,25 @@ config :sentry,
146146
If both `:traces_sampler` and `:traces_sample_rate` are configured, `:traces_sampler` takes precedence.
147147

148148
</SdkOption>
149+
150+
## Telemetry Processor Options
151+
152+
The Telemetry Processor is a buffered, priority-based event delivery mechanism. It batches events and sends them to Sentry using a weighted scheduler that prioritizes critical events (like errors) over lower-priority ones (like logs). Logs are routed through the Telemetry Processor by default. You can opt in to route other event types through the processor as well. In a future major release, the Telemetry Processor will become the default delivery mechanism for all event types.
153+
154+
<SdkOption name="telemetry_processor_categories" type='list' defaultValue='[:log]'>
155+
156+
A list of event categories to route through the Telemetry Processor. By default, only `:log` events use the processor. You can opt in to route additional event types through it.
157+
158+
Valid categories:
159+
160+
- `:error` — error events (critical priority)
161+
- `:check_in` — cron check-in events (high priority)
162+
- `:transaction` — transaction events (medium priority)
163+
- `:log` — log events (low priority)
164+
165+
```elixir
166+
config :sentry,
167+
telemetry_processor_categories: [:error, :check_in, :transaction, :log]
168+
```
169+
170+
</SdkOption>

docs/platforms/elixir/crons/index.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ title: Set Up Crons
33
sidebar_title: Crons
44
description: "Sentry Crons allows you to monitor the uptime and performance of any scheduled, recurring job in your application."
55
sidebar_order: 5750
6+
sidebar_section: features
67
---
78

89
Once implemented, it'll allow you to get alerts and metrics to help you solve errors, detect timeouts, and prevent disruptions to your service.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
title: Set Up Logs
3+
sidebar_title: Logs
4+
description: "Structured logs allow you to send, view and query logs sent from your applications within Sentry."
5+
sidebar_order: 4
6+
sidebar_section: features
7+
new: true
8+
---
9+
10+
With Sentry Structured Logs, you can send text-based log information from your applications to Sentry. Once in Sentry, these logs can be viewed alongside relevant errors, searched by text-string, or searched using their individual attributes.
11+
12+
## Requirements
13+
14+
<PlatformContent includePath="logs/requirements" />
15+
16+
## Setup
17+
18+
<PlatformContent includePath="logs/setup" />
19+
20+
## Usage
21+
22+
<PlatformContent includePath="logs/usage" />
23+
24+
## Integrations
25+
26+
<PlatformContent includePath="logs/integrations" />
27+
28+
## Options
29+
30+
<PlatformContent includePath="logs/options" />
31+
32+
## Default Attributes
33+
34+
<PlatformContent includePath="logs/default-attributes" />

docs/platforms/elixir/tracing/index.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ title: Set Up Tracing
33
sidebar_title: Tracing
44
description: "Learn how to enable tracing in your app and discover valuable performance insights of your application."
55
sidebar_order: 30
6+
sidebar_section: features
67
---
78

89
With [tracing](/product/insights/overview/), Sentry tracks your software performance, measuring metrics like throughput and latency, and displaying the impact of errors across multiple systems.

docs/platforms/elixir/usage/index.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
---
22
title: Usage
3+
sidebar_title: Capturing Errors
34
description: "Use the SDK to manually capture errors and other events."
45
sidebar_order: 10
6+
sidebar_section: features
57
---
68

79
Sentry's SDK hooks into your runtime environment and automatically reports errors, uncaught exceptions, and unhandled rejections as well as other types of errors depending on the platform.

docs/platforms/elixir/user-feedback/index.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ title: Set Up User Feedback
33
sidebar_title: User Feedback
44
description: "Learn more about collecting user feedback when an event occurs. Sentry pairs the feedback with the original event, giving you additional insight into issues."
55
sidebar_order: 6000
6+
sidebar_section: features
67
---
78

89
When a user experiences an error, Sentry provides the ability to collect additional feedback. You can collect feedback according to the method supported by the SDK.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
```elixir
2+
config :sentry,
3+
dsn: "___PUBLIC_DSN___",
4+
enable_logs: true,
5+
before_send_log: fn log_event ->
6+
# Skip info logs
7+
if log_event.level == :info do
8+
false
9+
else
10+
log_event
11+
end
12+
end
13+
```
14+
15+
You can also use a module/function tuple:
16+
17+
```elixir
18+
config :sentry,
19+
dsn: "___PUBLIC_DSN___",
20+
enable_logs: true,
21+
before_send_log: {MyApp.Sentry, :before_send_log}
22+
23+
# In lib/my_app/sentry.ex
24+
defmodule MyApp.Sentry do
25+
def before_send_log(%Sentry.LogEvent{} = log_event) do
26+
# Filter out logs from specific domains or modify attributes
27+
if String.contains?(log_event.body, "sensitive") do
28+
false
29+
else
30+
log_event
31+
end
32+
end
33+
end
34+
```
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
The Elixir SDK automatically sets several default attributes on all log entries to provide context and improve debugging:
2+
3+
<Include name="logs/default-attributes/core" />
4+
5+
<Include name="logs/default-attributes/message-template" />
6+
7+
<Include name="logs/default-attributes/server" />
8+
9+
### OpenTelemetry Attributes
10+
11+
If you're using OpenTelemetry with the `opentelemetry_logger_metadata` package, the following attributes are automatically included:
12+
13+
- `trace_id`: The OpenTelemetry trace ID associated with the log event.
14+
- `span_id`: The OpenTelemetry span ID associated with the log event.
15+
16+
If no OpenTelemetry context is available, a random trace ID is generated to allow log correlation within Sentry.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
Logs are sent to Sentry through Erlang's `:logger` system via `Sentry.LoggerHandler`. When `enable_logs: true` is set in your Sentry configuration, the SDK automatically attaches the handler — no manual setup is needed. Any logs from your application or libraries that use Elixir's `Logger` or Erlang's `:logger` will be captured and sent to Sentry at or above the configured level.
2+
3+
The logs behavior is configured globally via the `:logs` key — not through the handler config map:
4+
5+
```elixir
6+
config :sentry,
7+
enable_logs: true,
8+
logs: [
9+
level: :info,
10+
metadata: [:request_id, :user_id]
11+
]
12+
```
13+
14+
With this configuration, logs at or above `:info` will be sent to Sentry:
15+
16+
```elixir
17+
require Logger
18+
19+
Logger.debug("Debug message") # Not sent (below :info level)
20+
Logger.info("Info message") # Sent to Sentry
21+
Logger.warning("Warning") # Sent to Sentry
22+
Logger.error("Error occurred") # Sent to Sentry
23+
```
24+
25+
### Excluding Domains
26+
27+
You can exclude specific logger domains from being sent to Sentry using the `:excluded_domains` option under `:logs`:
28+
29+
```elixir
30+
config :sentry,
31+
enable_logs: true,
32+
logs: [
33+
level: :info,
34+
excluded_domains: [:ecto, :phoenix]
35+
]
36+
```
37+
38+
<Alert level="info" title="Logs vs Error Reporting">
39+
The logs feature (configured under `:logs`) is separate from error
40+
reporting (configured via `Sentry.LoggerHandler`'s `:level` option). Error reporting captures crash reports and
41+
exceptions, while logs captures structured log events. You can configure both
42+
independently.
43+
</Alert>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
### before_send_log
2+
3+
To filter or modify logs before they are sent to Sentry, use the `before_send_log` callback. Return `false` to skip a log, or return the log event to send it.
4+
5+
<PlatformContent includePath="configuration/before-send-log" />
6+
7+
### Logs Configuration
8+
9+
Logs behavior is configured under the `:logs` key in your Sentry configuration. These options control the auto-attached `Sentry.LoggerHandler`:
10+
11+
- **`:level`** - The minimum log level to send to Sentry's Logs Protocol. Default: `:info`. Supported values: `:debug`, `:info`, `:notice`, `:warning`, `:error`, `:critical`, `:alert`, `:emergency`.
12+
13+
- **`:excluded_domains`** - A list of logger domains to exclude from logs sent to Sentry. Default: `[]`.
14+
15+
- **`:metadata`** - Logger metadata keys to include as attributes in log events. Set to `:all` to include all metadata, or a list of specific keys like `[:request_id, :user_id]`. Default: `[]`.
16+
17+
```elixir
18+
config :sentry,
19+
dsn: "___PUBLIC_DSN___",
20+
enable_logs: true,
21+
logs: [
22+
level: :info,
23+
excluded_domains: [:ecto],
24+
metadata: [:request_id, :user_id] # or :all
25+
]
26+
```
27+
28+
### Global Configuration Options
29+
30+
These options are set in your Sentry configuration (`config :sentry`):
31+
32+
- **`:enable_logs`** - Set to `true` to enable the logs feature. When enabled, the SDK automatically attaches a `Sentry.LoggerHandler` and routes log events through the SDK's Telemetry Processor. Default is `false`.
33+
34+
- **`:before_send_log`** - A callback function to filter or modify log events before they are sent.
35+
36+
Log events are buffered by the Telemetry Processor with a capacity of 1000 entries and flushed in batches of 100 or every 5 seconds, whichever comes first. You can customize these defaults through the <PlatformLink to="/configuration/options/#telemetry-processor-options">Telemetry Processor options</PlatformLink>.
37+
38+
```elixir
39+
config :sentry,
40+
dsn: "___PUBLIC_DSN___",
41+
enable_logs: true,
42+
before_send_log: {MyApp.Sentry, :before_send_log}
43+
```

0 commit comments

Comments
 (0)