Skip to content

Commit f2cd9fc

Browse files
committed
Merge branch 'master' of github.com:getsentry/sentry-docs into smi/quick-start/sveltekit-manual
2 parents 071fb99 + 474101c commit f2cd9fc

File tree

12 files changed

+313
-12
lines changed

12 files changed

+313
-12
lines changed

develop-docs/sdk/telemetry/traces/dynamic-sampling-context.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ All of the attributes in the table below are required (non-optional) in a sense,
5050

5151
At the moment, only `release`, `environment` and `transaction` are used by the product for dynamic sampling functionality.
5252
The rest of the context attributes, `trace_id`, `public_key`, `sampled` and `sample_rate`, are used by Relay for internal decisions and for extrapolation in the product.
53-
Additional entries such as `replay_id`, `org` and `sample_rand` are only using the DSC as a means of transport.
53+
Additional entries such as `replay_id`, `org_id` and `sample_rand` are only using the DSC as a means of transport.
5454

5555
| Attribute | Type | Description | Example | Required Level |
5656
| --------------------------- | ------ | ---------------------------------------------------------------------------------------------------------------------------- | ------------------------------------ | ------------------------------------ |
@@ -62,7 +62,7 @@ Additional entries such as `replay_id`, `org` and `sample_rand` are only using t
6262
| `release` | string | The release name as specified in client options. | `[email protected]`, `1.2.3`, `2025.4.107` | required |
6363
| `environment` | string | The environment name as specified in client options. | `production`, `staging` | required |
6464
| `transaction` | string | The transaction name set on the scope. **Only include** if name has [good quality](#note-on-good-quality-transaction-names). | `/login`, `myApp.myController.login` | required (if known and good quality) |
65-
| `org` | string | The org ID parsed from the DSN or received by a downstream SDK. | `1` | required |
65+
| `org_id` | string | The org ID parsed from the DSN or received by a downstream SDK. | `1` | required |
6666
| `user_segment` [DEPRECATED] | string | User segment as set by the user with `scope.set_user()`. | | deprecated |
6767

6868
0: In any case, `trace_id`, `public_key`, and `sample_rate` should always be known to an SDK, so these values are strictly required.
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
---
2+
title: Set Up Logs in Go
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: 5600
6+
---
7+
8+
<Include name="feature-stage-beta-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+
Logs in Go are supported in Sentry Go SDK version `0.33.0` and above.
15+
16+
## Setup
17+
18+
To enable logging, you need to initialize the SDK with the `EnableLogs` option set to true.
19+
20+
```go
21+
package main
22+
23+
import (
24+
"context"
25+
"github.com/getsentry/sentry-go"
26+
"time"
27+
)
28+
29+
func main() {
30+
if err := sentry.Init(sentry.ClientOptions{
31+
Dsn: "___PUBLIC_DSN___",
32+
EnableLogs: true,
33+
}); err != nil {
34+
fmt.Printf("Sentry initialization failed: %v\n", err)
35+
}
36+
// Flush buffered events before the program terminates.
37+
// Set the timeout to the maximum duration the program can afford to wait.
38+
defer sentry.Flush(2 * time.Second)
39+
}
40+
```
41+
42+
## Usage
43+
44+
Once the feature is enabled on the SDK and the SDK is initialized, you can send logs by using
45+
the `sentry.Logger` API.
46+
47+
The `Sentry.Logger` API exposes methods that support six different log levels: `trace`,
48+
`debug`, `info`, `warn`, `error` and `fatal`. The methods support both `fmt.Print` and `fmt.Printf` like syntax.
49+
If you pass in format specifiers like `%v`, these will be sent to Sentry, and can be searched from within the Logs UI,
50+
and even added to the Logs views as a dedicated column.
51+
52+
```go
53+
ctx := context.Background()
54+
logger := sentry.NewLogger(ctx)
55+
56+
// You can use the logger like [fmt.Print]
57+
logger.Info(ctx, "Hello ", "world!")
58+
// Or like [fmt.Printf]
59+
logger.Infof(ctx, "Hello %v!", "world")
60+
```
61+
You can also pass additional attributes to the logger via the `SetAttributes` function. These attributes will also be searchable in the Logs UI.
62+
63+
```go
64+
package main
65+
66+
import (
67+
"context"
68+
"github.com/getsentry/sentry-go"
69+
"github.com/getsentry/sentry-go/attribute"
70+
"time"
71+
)
72+
73+
func main() {
74+
err := sentry.Init(sentry.ClientOptions{
75+
Dsn: "___PUBLIC_DSN___",
76+
EnableLogs: true,
77+
})
78+
if err != nil {
79+
panic(err)
80+
}
81+
defer sentry.Flush(2 * time.Second)
82+
83+
ctx := context.Background()
84+
logger := sentry.NewLogger(ctx)
85+
86+
logger.SetAttributes(
87+
attribute.Int("key.int", 42),
88+
attribute.Bool("key.boolean", true),
89+
attribute.Float64("key.float", 42.4),
90+
attribute.String("key.string", "string"),
91+
)
92+
logger.Warnf(ctx, "I have params: %v and attributes", "example param")
93+
}
94+
```
95+
Currently the `attribute` API supports only these value types: `int`, `string`, `bool`, and `float`.
96+
97+
## Integrations
98+
99+
The `sentry.Logger` implements the `io.Writer` interface, so you can easily inject the logger into your existing setup.
100+
101+
```go
102+
sentryLogger := sentry.NewLogger(ctx)
103+
logger := log.New(sentryLogger, "", log.LstdFlags)
104+
logger.Println("Implementing log.Logger")
105+
106+
slogger := slog.New(slog.NewJSONHandler(sentryLogger, nil))
107+
slogger.Info("Implementing slog.Logger")
108+
```
109+
110+
<Alert>
111+
In order to properly attach the correct trace with each Log entry, a `context.Context` is required. The `Write` function of
112+
the `io.Writer` interface doesn't provide `context`, so wrapping the custom logger will not get the trace and current span attached.
113+
We recommend using the `sentry.Logger` to ensure your logs are connected to spans and errors in the Sentry UI.
114+
</Alert>
115+
116+
## Options
117+
118+
### BeforeSendLog
119+
120+
To filter logs, or update them before they are sent to Sentry, you can use the `BeforeSendLog` client option.
121+
```go
122+
if err := sentry.Init(sentry.ClientOptions{
123+
Dsn: "___PUBLIC_DSN___",
124+
EnableLogs: true,
125+
BeforeSendLog: func(log *Log) *Log {
126+
// filter out all trace logs
127+
if log.Level == sentry.LogLevelTrace {
128+
return nil
129+
}
130+
131+
// filter all logs below warning
132+
if log.Severity <= LogSeverityInfo {
133+
return nil
134+
}
135+
},
136+
}); err != nil {
137+
fmt.Printf("Sentry initialization failed: %v\n", err)
138+
}
139+
```
140+
141+
### Debug
142+
143+
If the `Debug` init option is set to true, calls to the `sentry.Logger` will also print to the console with the appropriate log level.

docs/platforms/native/common/configuration/filtering.mdx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,32 @@ Typically, a `hint` holds the original exception so that additional data can be
3131
<PlatformContent includePath="configuration/before-send-hint" />
3232

3333
When the SDK creates an event or breadcrumb for transmission, that transmission is typically created from some sort of source object. For instance, an error event is typically created from a log record or exception instance. For better customization, SDKs send these objects to certain callbacks (<PlatformIdentifier name="before-send" />, <PlatformIdentifier name="before-breadcrumb" /> or the event processor system in the SDK).
34+
35+
36+
## Filtering Transaction Events
37+
38+
To prevent certain transactions from being reported to Sentry, use the <PlatformIdentifier name="traces-sampler" /> or <PlatformIdentifier name="before-send-transaction" /> configuration option, which allows you to provide a function to evaluate the current transaction and drop it if it's not one you want.
39+
40+
### Using <PlatformIdentifier name="traces-sampler" />
41+
42+
<Alert>
43+
The <PlatformIdentifier name="traces-sampler" /> and <PlatformIdentifier name="traces-sample-rate" /> config options are mutually exclusive. If you define a <PlatformIdentifier name="traces-sampler" /> to filter out certain transactions, you must also handle the case of non-filtered transactions by returning the rate at which you'd like them sampled.
44+
</Alert>
45+
46+
47+
In its simplest form, used just for filtering the transaction, it looks like this:
48+
49+
<PlatformContent includePath="performance/traces-sampler-as-sampler" />
50+
51+
It also allows you to sample different transactions at different rates.
52+
53+
If the transaction currently being processed has a parent transaction (from an upstream service calling this service), the parent (upstream) sampling decision will always be included in the `parent_sampled` parameter, so that your <PlatformIdentifier name="traces-sampler" /> can choose whether and when to inherit that decision. In most cases, inheritance is the right choice, to avoid breaking distributed traces. A broken trace will not include all your services. See <PlatformLink to="/configuration/sampling/#inheritance">Inheriting the parent sampling decision</PlatformLink> to learn more.
54+
55+
Learn more about <PlatformLink to="/configuration/sampling/">configuring the sample rate</PlatformLink>.
56+
57+
### Using <PlatformIdentifier name="before-send-transaction" />
58+
<Alert>
59+
When discarding a transaction in a `before_send_transaction` callback, one must call `sentry_value_decref(tx)` and return a `sentry_value_new_null()`.
60+
</Alert>
61+
62+
<PlatformContent includePath="configuration/before-send-transaction" />

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ This function is called with a backend-specific event object, and can return a m
8484

8585
</ConfigKey>
8686

87+
<ConfigKey name="before-transaction">
88+
89+
This function is called with an SDK-specific transaction event object, and can return a modified transaction event object, or `sentry_value_new_null()` to skip reporting the event. One way this might be used is for manual PII stripping before sending.
90+
91+
</ConfigKey>
92+
8793
## Tracing Options
8894

8995
<ConfigKey name="traces-sample-rate">
@@ -94,6 +100,6 @@ A number between `0.0` and `1.0`, controlling the percentage chance a given tran
94100

95101
<ConfigKey name="traces-sampler">
96102

97-
A function responsible for determining the percentage chance a given transaction will be sent to Sentry. It will automatically be passed information about the transaction and the context in which it's being created, and must return a number between `0` (0% chance of being sent) and `1` (100% chance of being sent). Can also be used for filtering transactions, by returning 0 for those that are unwanted. Either this or <PlatformIdentifier name="traces-sample-rate" /> must be defined to enable tracing.
103+
A function responsible for determining the percentage chance a given transaction will be sent to Sentry. It will automatically be passed information about the transaction and the context in which it's being created, and must return a number between `0` (0% chance of being sent) and `1` (100% chance of being sent). Can also be used for filtering transactions, by returning 0 for those that are unwanted. Either this or <PlatformIdentifier name="traces-sample-rate" /> must be defined to enable tracing. An example can be found in the [Sampling](/platforms/native/configuration/sampling/#setting-a-sampling-function) section.
98104

99105
</ConfigKey>

docs/platforms/ruby/logs/index.mdx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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-beta-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" />

docs/product/explore/logs/getting-started/index.mdx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,18 @@ To set up Sentry Logs, use the links below for supported SDKs. After it's been s
197197
url="/platforms/python/logs/"
198198
/>
199199

200+
### Ruby
201+
202+
- <LinkWithPlatformIcon
203+
platform="ruby"
204+
label="Ruby"
205+
url="/platforms/ruby/logs/"
206+
/>
207+
208+
### Go
209+
210+
- [Go](/platforms/go/logs/)
211+
200212
## Upcoming SDKs
201213

202214
We're actively working on adding Log functionality to additional SDKs. Check out these GitHub issues for the latest updates:
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
```c
2+
3+
static sentry_value_t
4+
before_transaction_callback(sentry_value_t tx, void *user_data)
5+
{
6+
(void)user_data;
7+
// throw out any transaction while a tag is active
8+
if (!sentry_value_is_null(sentry_value_get_by_key(tx, "tags"))) {
9+
sentry_value_decref(tx);
10+
return sentry_value_new_null();
11+
}
12+
// replace the transaction name with a custom one otherwise
13+
sentry_value_set_by_key(
14+
tx, "transaction", sentry_value_new_string("little.coffeepot"));
15+
return tx;
16+
}
17+
18+
sentry_options_t *options = sentry_options_new();
19+
sentry_options_set_before_transaction(options, before_transaction_callback, NULL);
20+
sentry_init(options);
21+
```
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)