Skip to content

Commit 52f7085

Browse files
committed
docs(ruby): add sections for std_lib_logger_filter opt
1 parent 2412b50 commit 52f7085

File tree

4 files changed

+109
-0
lines changed

4 files changed

+109
-0
lines changed

docs/platforms/ruby/common/configuration/options.mdx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,32 @@ Provides a lambda or proc that's called with an SDK-specific log object, and can
362362

363363
</SdkOption>
364364

365+
<SdkOption name="std_lib_logger_filter" type="lambda | proc">
366+
367+
Provides a lambda or proc that's called to filter log messages from Ruby's standard library logger before they are sent to Sentry. This option is only used when the `:logger` patch is enabled via `config.enabled_patches`.
368+
369+
The callback receives three arguments:
370+
- `logger` - The logger instance
371+
- `message` - The log message string
372+
- `severity` - The log severity level (`:debug`, `:info`, `:warn`, `:error`, `:fatal`)
373+
374+
Return `true` to send the log to Sentry, or `false` to skip it.
375+
376+
```ruby
377+
Sentry.init do |config|
378+
config.dsn = "___PUBLIC_DSN___"
379+
config.enable_logs = true
380+
config.enabled_patches << :logger
381+
382+
# Only send ERROR and FATAL logs to Sentry
383+
config.std_lib_logger_filter = proc do |logger, message, severity|
384+
[:error, :fatal].include?(severity)
385+
end
386+
end
387+
```
388+
389+
</SdkOption>
390+
365391
<SdkOption name="before_send_check_in" type="lambda | proc">
366392

367393
Provides a lambda or proc that's called with a check-in event object, and can return a modified check-in event object, or `nil` to skip reporting the event.

docs/platforms/ruby/logs/index.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ With Sentry Structured Logs, you can send text-based log information from your a
2525

2626
<PlatformContent includePath="logs/integrations" />
2727

28+
## Options
29+
30+
<PlatformContent includePath="logs/options" />
31+
2832
## Default Attributes
2933

3034
<PlatformContent includePath="logs/default-attributes" />

platform-includes/logs/integrations/ruby.mdx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,30 @@ logger.info("Hello from stdlib logger")
1818
logger.error("Hello from stdlib logger")
1919
```
2020

21+
### Filtering Logs
22+
23+
You can filter logs before they are sent to Sentry using the `std_lib_logger_filter` configuration option. This allows you to control which log messages are sent based on severity, content, or logger instance.
24+
25+
```ruby
26+
Sentry.init do |config|
27+
config.dsn = "___PUBLIC_DSN___"
28+
config.enable_logs = true
29+
config.enabled_patches << :logger
30+
31+
# Only send ERROR and FATAL logs to Sentry
32+
config.std_lib_logger_filter = proc do |logger, message, severity|
33+
[:error, :fatal].include?(severity)
34+
end
35+
end
36+
```
37+
38+
The filter proc receives three arguments:
39+
- `logger` - The logger instance
40+
- `message` - The log message string
41+
- `severity` - The log severity level (`:debug`, `:info`, `:warn`, `:error`, `:fatal`)
42+
43+
Return `true` to send the log to Sentry, or `false` to skip it.
44+
2145
<Alert level="info" title="Note on structured logging">
2246
Ruby's stdlib logger does not support structured logging, that's why logs are sent to Sentry as plain messages with default attributes added automatically by the SDK.
2347
</Alert>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
### before_send_log
2+
3+
To filter logs before they are sent to Sentry, use the `before_send_log` callback. Return `nil` to skip a log, or return the log object to send it.
4+
5+
<PlatformContent includePath="configuration/before-send-log" />
6+
7+
### std_lib_logger_filter
8+
9+
When using Ruby's standard library logger integration (enabled with `config.enabled_patches << :logger`), you can filter log messages before they are sent to Sentry using the `std_lib_logger_filter` configuration option.
10+
11+
```ruby
12+
Sentry.init do |config|
13+
config.dsn = "___PUBLIC_DSN___"
14+
config.enable_logs = true
15+
config.enabled_patches << :logger
16+
17+
# Only send ERROR and FATAL logs to Sentry
18+
config.std_lib_logger_filter = proc do |logger, message, severity|
19+
[:error, :fatal].include?(severity)
20+
end
21+
end
22+
```
23+
24+
The filter proc receives three arguments:
25+
- `logger` - The logger instance
26+
- `message` - The log message string
27+
- `severity` - The log severity level (`:debug`, `:info`, `:warn`, `:error`, `:fatal`)
28+
29+
Return `true` to send the log to Sentry, or `false` to skip it.
30+
31+
**Examples:**
32+
33+
Filter by severity:
34+
35+
```ruby
36+
config.std_lib_logger_filter = proc do |logger, message, severity|
37+
[:error, :fatal].include?(severity)
38+
end
39+
```
40+
41+
Filter by message content:
42+
43+
```ruby
44+
config.std_lib_logger_filter = proc do |logger, message, severity|
45+
!message.include?("SKIP")
46+
end
47+
```
48+
49+
Filter by logger instance:
50+
51+
```ruby
52+
config.std_lib_logger_filter = proc do |logger, message, severity|
53+
!logger.instance_variable_get(:@logdev).nil?
54+
end
55+
```

0 commit comments

Comments
 (0)