Skip to content
Merged
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
4 changes: 4 additions & 0 deletions docs/platforms/android/logs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ With Sentry Structured Logs, you can send text-based log information from your a
## Options

<PlatformContent includePath="logs/options" />

## Default Attributes

<PlatformContent includePath="logs/default-attributes" />
6 changes: 5 additions & 1 deletion docs/platforms/apple/common/logs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: "Structured logs allow you to send, view and query logs sent from y
sidebar_order: 5755
---

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.
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.

## Requirements

Expand All @@ -22,3 +22,7 @@ With Sentry Structured Logs, you can send text based log information from your a
## Options

<PlatformContent includePath="logs/options" />

## Default Attributes

<PlatformContent includePath="logs/default-attributes" />
5 changes: 4 additions & 1 deletion docs/platforms/dart/common/logs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ description: "Structured logs allow you to send, view and query logs sent from y
sidebar_order: 5755
---


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.

## Requirements
Expand All @@ -27,3 +26,7 @@ With Sentry Structured Logs, you can send text-based log information from your a
## Options

<PlatformContent includePath="logs/options" />

## Default Attributes

<PlatformContent includePath="logs/default-attributes" />
5 changes: 4 additions & 1 deletion docs/platforms/dart/guides/flutter/logs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ description: "Structured logs allow you to send, view and query logs sent from y
sidebar_order: 5755
---


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.

## Requirements
Expand All @@ -23,3 +22,7 @@ With Sentry Structured Logs, you can send text-based log information from your a
## Options

<PlatformContent includePath="logs/options" />

## Default Attributes

<PlatformContent includePath="logs/default-attributes" />
5 changes: 4 additions & 1 deletion docs/platforms/dotnet/common/logs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ notSupported:
- dotnet.xamarin
---


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.

## Requirements
Expand All @@ -33,3 +32,7 @@ With Sentry Structured Logs, you can send text-based log information from your a
## Options

<PlatformContent includePath="logs/options" />

## Default Attributes

<PlatformContent includePath="logs/default-attributes" />
119 changes: 12 additions & 107 deletions docs/platforms/go/common/logs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,129 +5,34 @@ description: "Structured logs allow you to send, view, and query logs sent from
sidebar_order: 5600
---


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.

## Requirements

Logs in Go are supported in Sentry Go SDK version `0.33.0` and above. To use integrations with other logging libraries, check their specific documentation pages for detailed requirements.

## Configure

### Initialize the Sentry SDK

To enable logging, you need to initialize the SDK with the `EnableLogs` option set to true.

<PlatformContent includePath="getting-started-include-logs-config" />

### Options
<PlatformContent includePath="logs/requirements" />

#### BeforeSendLog
## Setup

To filter logs, or update them before they are sent to Sentry, you can use the `BeforeSendLog` client option.

```go
sentry.Init(sentry.ClientOptions{
Dsn: "___PUBLIC_DSN___",
EnableLogs: true,
BeforeSendLog: func(log *sentry.Log) *sentry.Log {
// filter out all trace logs
if log.Level == sentry.LogLevelTrace {
return nil
}

// filter all logs below warning
if log.Severity <= sentry.LogSeverityInfo {
return nil
}
return log
},
})
```
<PlatformContent includePath="logs/setup" />

## Usage

Once the feature is enabled on the SDK and the SDK is initialized, you can send logs by using the `sentry.Logger` API or our different integrations.

The `sentry.Logger` API exposes methods that support six different log levels:
- `trace`
- `debug`
- `info`
- `warn`
- `error`
- `fatal`

The methods support both `fmt.Print` and `fmt.Printf` like syntax. If you pass in format specifiers like `%v`, these 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.

```go
func main() {
if err := sentry.Init(sentry.ClientOptions{
Dsn: "___PUBLIC_DSN___",
EnableLogs: true,
}); err != nil {
log.Fatalf("Sentry initialization failed: %v", err)
}
// Flush buffered events before the program terminates.
// Set the timeout to the maximum duration the program can afford to wait.
defer sentry.Flush(2 * time.Second)

// The SentryLogger requires context, to link logs with the appropriate traces. You can either create a new logger
// by providing the context, or use WithCtx() to pass the context inline.
ctx := context.Background()
logger := sentry.NewLogger(ctx)

// Or inline using WithCtx()
newCtx := context.Background()
// WithCtx() does not modify the original context attached on the logger.
logger.Info().WithCtx(newCtx).Emit("context passed")

// You can use the logger like [fmt.Print]
logger.Info().Emit("Hello ", "world!")
// Or like [fmt.Printf]
logger.Info().Emitf("Hello %v!", "world")
}
```

You can also pass additional permanent attributes to the logger via `SetAttributes`, or attach certain attributes to the `LogEntry` itself.
These attributes do not persist after Emitting the `LogEntry`. All attributes will be searchable in the Logs UI.

```go
logger.SetAttributes(
attribute.Int("key.int", 42),
attribute.Bool("key.boolean", true),
attribute.Float64("key.float", 42.4),
attribute.String("key.string", "string"),
)
logger.Warn().Emitf("I have params: %v and attributes", "example param")

// This entry would contain all attributes attached to the logger.
// However, it's also possible to overwrite them.
logger.Info().String("key.string", "newstring").Emit("overwriting key.string")
```

Currently, the `attribute` API supports only these value types: `int`, `string`, `bool`, and `float`.
<PlatformContent includePath="logs/usage" />

## Integrations

### Supported libraries
- [Slog](/platforms/go/guides/slog)
- [Logrus](/platforms/go/guides/logrus)

### `io.Writer` interface
<PlatformContent includePath="logs/integrations" />

The `sentry.Logger` implements the `io.Writer` interface, so you can easily inject the logger into your existing setup. However, to correctly
link your traces you would need to create a new logger everytime you want to pass a new context. Due to this limitation we recommend using the
`sentry.Logger` or any of the other supported integrations.
## Options

```go
sentryLogger := sentry.NewLogger(ctx)
logger := log.New(sentryLogger, "", log.LstdFlags)
logger.Println("Implementing log.Logger")
```
<PlatformContent includePath="logs/options" />

### Debug

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.

<Include name="logs/go-ctx-usage-alert.mdx"/>
<Include name="logs/go-ctx-usage-alert.mdx" />

## Default Attributes

<PlatformContent includePath="logs/default-attributes" />
5 changes: 4 additions & 1 deletion docs/platforms/java/common/logs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ description: "Structured logs allow you to send, view and query logs sent from y
sidebar_order: 5755
---


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.

## Requirements
Expand All @@ -27,3 +26,7 @@ With Sentry Structured Logs, you can send text-based log information from your a
## Options

<PlatformContent includePath="logs/options" />

## Default Attributes

<PlatformContent includePath="logs/default-attributes" />
5 changes: 4 additions & 1 deletion docs/platforms/javascript/common/logs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ notSupported:

<PlatformContent includePath="llm-rules-logs" />


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.

## Requirements
Expand All @@ -32,3 +31,7 @@ With Sentry Structured Logs, you can send text-based log information from your a
## Options

<PlatformContent includePath="logs/options" />

## Default Attributes

<PlatformContent includePath="logs/default-attributes" />
5 changes: 4 additions & 1 deletion docs/platforms/php/common/logs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ description: "Structured logs allow you to send, view and query logs sent from y
sidebar_order: 5600
---


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.

<Alert title="Looking for Symfony?">
Expand All @@ -29,3 +28,7 @@ Let us know what you would like to see on GitHub: [Symfony Logs](https://github.
## Options

<PlatformContent includePath="logs/options" />

## Default Attributes

<PlatformContent includePath="logs/default-attributes" />
5 changes: 4 additions & 1 deletion docs/platforms/php/guides/laravel/logs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ description: "Structured logs allow you to send, view and query logs sent from y
sidebar_order: 5600
---


With Sentry Structured Logs, you can send text-based log information from your Laravel applications to Sentry. Once in Sentry, these logs can be viewed alongside relevant errors, searched by text-string, or searched using their individual attributes.

## Requirements
Expand All @@ -24,6 +23,10 @@ With Sentry Structured Logs, you can send text-based log information from your L

<PlatformContent includePath="logs/options" />

## Default Attributes

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

## Troubleshooting

If your logs are not appearing in Sentry, check or test the following:
Expand Down
5 changes: 4 additions & 1 deletion docs/platforms/python/logs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ description: "Structured logs allow you to send, view and query logs sent from y
sidebar_order: 5755
---


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.

## Requirements
Expand All @@ -27,3 +26,7 @@ With Sentry Structured Logs, you can send text-based log information from your a
## Options

<PlatformContent includePath="logs/options" />

## Default Attributes

<PlatformContent includePath="logs/default-attributes" />
5 changes: 4 additions & 1 deletion docs/platforms/react-native/logs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ sidebar_order: 5755

<PlatformContent includePath="llm-rules-logs" />


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.

## Requirements
Expand All @@ -29,3 +28,7 @@ With Sentry Structured Logs, you can send text-based log information from your a
## Options

<PlatformContent includePath="logs/options" />

## Default Attributes

<PlatformContent includePath="logs/default-attributes" />
5 changes: 4 additions & 1 deletion docs/platforms/ruby/logs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ description: "Structured logs allow you to send, view and query logs sent from y
sidebar_order: 5755
---


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.

## Requirements
Expand All @@ -23,3 +22,7 @@ With Sentry Structured Logs, you can send text-based log information from your a
## Integrations

<PlatformContent includePath="logs/integrations" />

## Default Attributes

<PlatformContent includePath="logs/default-attributes" />
15 changes: 14 additions & 1 deletion docs/platforms/rust/common/logs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ description: "Structured logs allow you to send, view, and query logs sent from
sidebar_order: 5600
---


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.

## Requirements
Expand Down Expand Up @@ -223,3 +222,17 @@ let _guard = sentry::init(("___PUBLIC_DSN___", sentry::ClientOptions {
..Default::default()
}));
```

## Default Attributes

The Rust SDK automatically sets several default attributes on all log entries to provide context and improve debugging:

<Include name="logs/default-attributes/core" />

<Include name="logs/default-attributes/message-template" />

<Include name="logs/default-attributes/server" />

<Include name="logs/default-attributes/user" />

<Include name="logs/default-attributes/integration" />
4 changes: 4 additions & 0 deletions includes/logs/default-attributes/browser.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### Browser Attributes

- `browser.name`: Display name of the browser application.
- `browser.version`: Version string of the browser.
7 changes: 7 additions & 0 deletions includes/logs/default-attributes/core.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### Core Attributes

- `environment`: The environment set in the SDK if defined. This is sent from the SDK as `sentry.environment`.
- `release`: The release set in the SDK if defined. This is sent from the SDK as `sentry.release`.
- `trace.parent_span_id`: The span ID of the span that was active when the log was collected (only set if there was an active span). This is sent from the SDK as `sentry.trace.parent_span_id`.
- `sdk.name`: The name of the SDK that sent the log. This is sent from the SDK as `sentry.sdk.name`. This is sent from the SDK as `sentry.sdk.name`.
- `sdk.version`: The version of the SDK that sent the log. This is sent from the SDK as `sentry.sdk.version`. This is sent from the SDK as `sentry.sdk.version`.
5 changes: 5 additions & 0 deletions includes/logs/default-attributes/integration.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### Integration Attributes

If a log is generated by an SDK integration, the SDK will set additional attributes to help you identify the source of the log.

- `origin`: The origin of the log. This is sent from the SDK as `sentry.origin`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
For example, with the following log:

```dart
Sentry.logger.fmt.info("%s added %s to cart.", ["John", "Product 1"]);
```

Sentry will add the following attributes:

- `message.template`: "%s added %s to cart."
- `message.parameter.0`: "John"
- `message.parameter.1`: "Product 1"
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
For example, with the following log:

```java
Sentry.logger().error("A %s log message", "formatted");
```

Sentry will add the following attributes:

- `message.template`: "A %s log message"
- `message.parameter.0`: "formatted"
Loading