Skip to content

Commit f98dbed

Browse files
committed
[ruby] initial docs for logs
1 parent 350714a commit f98dbed

File tree

6 files changed

+107
-0
lines changed

6 files changed

+107
-0
lines changed

docs/platforms/ruby/logs/index.mdx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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: 5755
6+
---
7+
8+
<Include name="feature-stage-alpha-logs.mdx" />
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" />
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### ActiveSupport Instrumentation
2+
3+
Coming soon...
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#### before_send_log
2+
3+
Coming soon...
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Logs for Ruby are supported in Sentry Ruby SDK version `5.24.0` and above.
2+
3+
```bash
4+
gem install sentry-ruby
5+
```
6+
7+
Or add it to your Gemfile:
8+
9+
```ruby
10+
gem "sentry-ruby"
11+
```
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
To enable logging, you need to initialize the SDK with the `enable_logs` option set to `true`.
2+
3+
```ruby
4+
Sentry.init do |config|
5+
config.dsn = "___PUBLIC_DSN___"
6+
config.enable_logs = true
7+
end
8+
```
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
Once the feature is enabled on the SDK and the SDK is initialized, you can send logs using the `Sentry.logger` APIs.
2+
3+
The `logger` namespace exposes six methods that you can use to log messages at different log levels: `trace`, `debug`, `info`, `warning`, `error`, and `fatal`.
4+
5+
You can pass additional attributes directly to the logging functions. These properties will be sent to Sentry, and can be searched from within the Logs UI, and even added to the Logs views as a dedicated column.
6+
7+
```ruby
8+
Sentry.logger.info("Updated global cache")
9+
10+
Sentry.logger.debug("Cache miss for user %{user_id}", user_id: 123)
11+
12+
Sentry.logger.trace(
13+
"Starting database connection %{database}",
14+
database: "users"
15+
)
16+
17+
Sentry.logger.warn(
18+
"Rate limit reached for endpoint %{endpoint}",
19+
endpoint: "/api/results/"
20+
)
21+
22+
Sentry.logger.error(
23+
"Failed to process payment. Order: %{order_id}. Amount: %{amount}",
24+
order_id: "or_2342", amount: 99.99
25+
)
26+
27+
Sentry.logger.fatal(
28+
"Database %{database} connection pool exhausted",
29+
database: "users"
30+
)
31+
```
32+
33+
You can also use message templates with positional or hash parameters:
34+
35+
```ruby
36+
# Using named parameters
37+
Sentry.logger.info("User %{name} logged in", name: "Jane Doe")
38+
39+
# Using positional parameters
40+
Sentry.logger.info("User %s logged in", ["Jane Doe"])
41+
```
42+
43+
Any other arbitrary attributes will be sent as part of the log event payload:
44+
45+
```ruby
46+
# Here `user_id` and `action` will be sent as extra attributes that
47+
# Sentry Logs UI displays
48+
Sentry.logger.info(
49+
"User %{user} logged in",
50+
user: "Jane", user_id: 123, action: "create"
51+
)
52+
```

0 commit comments

Comments
 (0)