diff --git a/docs/platforms/android/logs/index.mdx b/docs/platforms/android/logs/index.mdx
index 3cfa6cbeb27441..760c7672c85be6 100644
--- a/docs/platforms/android/logs/index.mdx
+++ b/docs/platforms/android/logs/index.mdx
@@ -26,3 +26,7 @@ With Sentry Structured Logs, you can send text-based log information from your a
## Options
+
+## Default Attributes
+
+
diff --git a/docs/platforms/apple/common/logs/index.mdx b/docs/platforms/apple/common/logs/index.mdx
index 61d54bd74aa790..32140b4a29f898 100644
--- a/docs/platforms/apple/common/logs/index.mdx
+++ b/docs/platforms/apple/common/logs/index.mdx
@@ -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
@@ -22,3 +22,7 @@ With Sentry Structured Logs, you can send text based log information from your a
## Options
+
+## Default Attributes
+
+
diff --git a/docs/platforms/dart/common/logs/index.mdx b/docs/platforms/dart/common/logs/index.mdx
index 2470b2ed9c0956..760c7672c85be6 100644
--- a/docs/platforms/dart/common/logs/index.mdx
+++ b/docs/platforms/dart/common/logs/index.mdx
@@ -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
@@ -27,3 +26,7 @@ With Sentry Structured Logs, you can send text-based log information from your a
## Options
+
+## Default Attributes
+
+
diff --git a/docs/platforms/dart/guides/flutter/logs/index.mdx b/docs/platforms/dart/guides/flutter/logs/index.mdx
index 977de3adff95d0..32140b4a29f898 100644
--- a/docs/platforms/dart/guides/flutter/logs/index.mdx
+++ b/docs/platforms/dart/guides/flutter/logs/index.mdx
@@ -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
@@ -23,3 +22,7 @@ With Sentry Structured Logs, you can send text-based log information from your a
## Options
+
+## Default Attributes
+
+
diff --git a/docs/platforms/dotnet/common/logs/index.mdx b/docs/platforms/dotnet/common/logs/index.mdx
index db6457dec25e5b..b990ffa023da9e 100644
--- a/docs/platforms/dotnet/common/logs/index.mdx
+++ b/docs/platforms/dotnet/common/logs/index.mdx
@@ -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
@@ -33,3 +32,7 @@ With Sentry Structured Logs, you can send text-based log information from your a
## Options
+
+## Default Attributes
+
+
diff --git a/docs/platforms/go/common/logs/index.mdx b/docs/platforms/go/common/logs/index.mdx
index 6762dd801af352..8addf4742a4136 100644
--- a/docs/platforms/go/common/logs/index.mdx
+++ b/docs/platforms/go/common/logs/index.mdx
@@ -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.
-
-
-
-### Options
+
-#### 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
- },
-})
-```
+
## 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`.
+
## Integrations
-### Supported libraries
-- [Slog](/platforms/go/guides/slog)
-- [Logrus](/platforms/go/guides/logrus)
-
-### `io.Writer` interface
+
-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")
-```
+
### 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.
-
+
+
+## Default Attributes
+
+
diff --git a/docs/platforms/java/common/logs/index.mdx b/docs/platforms/java/common/logs/index.mdx
index 2470b2ed9c0956..760c7672c85be6 100644
--- a/docs/platforms/java/common/logs/index.mdx
+++ b/docs/platforms/java/common/logs/index.mdx
@@ -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
@@ -27,3 +26,7 @@ With Sentry Structured Logs, you can send text-based log information from your a
## Options
+
+## Default Attributes
+
+
diff --git a/docs/platforms/javascript/common/logs/index.mdx b/docs/platforms/javascript/common/logs/index.mdx
index c9fea7b692bcb4..50022148b33564 100644
--- a/docs/platforms/javascript/common/logs/index.mdx
+++ b/docs/platforms/javascript/common/logs/index.mdx
@@ -10,7 +10,6 @@ notSupported:
-
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
@@ -32,3 +31,7 @@ With Sentry Structured Logs, you can send text-based log information from your a
## Options
+
+## Default Attributes
+
+
diff --git a/docs/platforms/php/common/logs/index.mdx b/docs/platforms/php/common/logs/index.mdx
index 53d3c0b9d819d2..9f784b60008525 100644
--- a/docs/platforms/php/common/logs/index.mdx
+++ b/docs/platforms/php/common/logs/index.mdx
@@ -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.
@@ -29,3 +28,7 @@ Let us know what you would like to see on GitHub: [Symfony Logs](https://github.
## Options
+
+## Default Attributes
+
+
diff --git a/docs/platforms/php/guides/laravel/logs/index.mdx b/docs/platforms/php/guides/laravel/logs/index.mdx
index 2446d560d71c7e..41822688bd2760 100644
--- a/docs/platforms/php/guides/laravel/logs/index.mdx
+++ b/docs/platforms/php/guides/laravel/logs/index.mdx
@@ -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
@@ -24,6 +23,10 @@ With Sentry Structured Logs, you can send text-based log information from your L
+## Default Attributes
+
+
+
## Troubleshooting
If your logs are not appearing in Sentry, check or test the following:
diff --git a/docs/platforms/python/logs/index.mdx b/docs/platforms/python/logs/index.mdx
index 2470b2ed9c0956..760c7672c85be6 100644
--- a/docs/platforms/python/logs/index.mdx
+++ b/docs/platforms/python/logs/index.mdx
@@ -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
@@ -27,3 +26,7 @@ With Sentry Structured Logs, you can send text-based log information from your a
## Options
+
+## Default Attributes
+
+
diff --git a/docs/platforms/react-native/logs/index.mdx b/docs/platforms/react-native/logs/index.mdx
index e754a96819b1b6..b7569ee6165b7d 100644
--- a/docs/platforms/react-native/logs/index.mdx
+++ b/docs/platforms/react-native/logs/index.mdx
@@ -7,7 +7,6 @@ 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
@@ -29,3 +28,7 @@ With Sentry Structured Logs, you can send text-based log information from your a
## Options
+
+## Default Attributes
+
+
diff --git a/docs/platforms/ruby/logs/index.mdx b/docs/platforms/ruby/logs/index.mdx
index 8b01ebd90921f4..93e519fe568d8c 100644
--- a/docs/platforms/ruby/logs/index.mdx
+++ b/docs/platforms/ruby/logs/index.mdx
@@ -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
@@ -23,3 +22,7 @@ With Sentry Structured Logs, you can send text-based log information from your a
## Integrations
+
+## Default Attributes
+
+
diff --git a/docs/platforms/rust/common/logs/index.mdx b/docs/platforms/rust/common/logs/index.mdx
index 26d540190e7041..28822e73613c88 100644
--- a/docs/platforms/rust/common/logs/index.mdx
+++ b/docs/platforms/rust/common/logs/index.mdx
@@ -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
@@ -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:
+
+
+
+
+
+
+
+
+
+
diff --git a/includes/logs/default-attributes/browser.mdx b/includes/logs/default-attributes/browser.mdx
new file mode 100644
index 00000000000000..e364a4bd21faf9
--- /dev/null
+++ b/includes/logs/default-attributes/browser.mdx
@@ -0,0 +1,4 @@
+### Browser Attributes
+
+- `browser.name`: Display name of the browser application.
+- `browser.version`: Version string of the browser.
diff --git a/includes/logs/default-attributes/core.mdx b/includes/logs/default-attributes/core.mdx
new file mode 100644
index 00000000000000..30929c220c7e8c
--- /dev/null
+++ b/includes/logs/default-attributes/core.mdx
@@ -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`.
diff --git a/includes/logs/default-attributes/integration.mdx b/includes/logs/default-attributes/integration.mdx
new file mode 100644
index 00000000000000..cfa7d109eb2a28
--- /dev/null
+++ b/includes/logs/default-attributes/integration.mdx
@@ -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`.
diff --git a/includes/logs/default-attributes/message-template-examples/dart.mdx b/includes/logs/default-attributes/message-template-examples/dart.mdx
new file mode 100644
index 00000000000000..baef7ce5ee42ed
--- /dev/null
+++ b/includes/logs/default-attributes/message-template-examples/dart.mdx
@@ -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"
diff --git a/includes/logs/default-attributes/message-template-examples/java.mdx b/includes/logs/default-attributes/message-template-examples/java.mdx
new file mode 100644
index 00000000000000..0e9d9a315f8d7b
--- /dev/null
+++ b/includes/logs/default-attributes/message-template-examples/java.mdx
@@ -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"
diff --git a/includes/logs/default-attributes/message-template-examples/javascript.mdx b/includes/logs/default-attributes/message-template-examples/javascript.mdx
new file mode 100644
index 00000000000000..24f4d5e4272371
--- /dev/null
+++ b/includes/logs/default-attributes/message-template-examples/javascript.mdx
@@ -0,0 +1,13 @@
+For example, with the following log:
+
+```javascript
+const user = "John";
+const product = "Product 1";
+Sentry.logger.info(Sentry.logger.fmt`'${user}' added '${product}' to cart.`);
+```
+
+Sentry will add the following attributes:
+
+- `message.template`: "%s added %s to cart."
+- `message.parameter.0`: "John"
+- `message.parameter.1`: "Product 1"
diff --git a/includes/logs/default-attributes/message-template.mdx b/includes/logs/default-attributes/message-template.mdx
new file mode 100644
index 00000000000000..d9c47fc1c0d8d6
--- /dev/null
+++ b/includes/logs/default-attributes/message-template.mdx
@@ -0,0 +1,6 @@
+### Message Template Attributes
+
+If the log was paramaterized, Sentry adds the message template and parameters as log attributes.
+
+- `message.template`: The parameterized template string. This is sent from the SDK as `sentry.message.template`.
+- `message.parameter.X`: The parameters to fill the template string. X can either be the number that represent the parameter's position in the template string (`sentry.message.parameter.0`, `sentry.message.parameter.1`, etc) or the parameter's name (`sentry.message.parameter.item_id`, `sentry.message.parameter.user_id`, etc). This is sent from the SDK as `sentry.message.parameter.X`.
diff --git a/includes/logs/default-attributes/mobile-desktop-native.mdx b/includes/logs/default-attributes/mobile-desktop-native.mdx
new file mode 100644
index 00000000000000..575fc776519211
--- /dev/null
+++ b/includes/logs/default-attributes/mobile-desktop-native.mdx
@@ -0,0 +1,3 @@
+### Message Template Attributes
+
+If the log was paramaterized (like with `Sentry.logger().error("A %s log message", "formatted");`), Sentry adds the message template and parameters as log attributes.
diff --git a/includes/logs/default-attributes/server.mdx b/includes/logs/default-attributes/server.mdx
new file mode 100644
index 00000000000000..8631d6baaba768
--- /dev/null
+++ b/includes/logs/default-attributes/server.mdx
@@ -0,0 +1,3 @@
+### Server Attributes
+
+- `server.address`: The address of the server that sent the log. Equivalent to `server_name` that gets attached to Sentry errors.
diff --git a/includes/logs/default-attributes/user-mobile.mdx b/includes/logs/default-attributes/user-mobile.mdx
new file mode 100644
index 00000000000000..a5fadc7e3405f5
--- /dev/null
+++ b/includes/logs/default-attributes/user-mobile.mdx
@@ -0,0 +1,8 @@
+### User Attributes
+
+- `user.id`: The user ID. Maps to id in the User payload, which is set by default by the SDKs.
+
+If user information is available in the current scope, the following attributes are added to the log:
+
+- `user.name`: The username. Maps to username in the User payload.
+- `user.email`: The email address. Maps to email in the User payload.
diff --git a/includes/logs/default-attributes/user.mdx b/includes/logs/default-attributes/user.mdx
new file mode 100644
index 00000000000000..a8ac6eb6e04b67
--- /dev/null
+++ b/includes/logs/default-attributes/user.mdx
@@ -0,0 +1,7 @@
+### User Attributes
+
+If user information is available in the current scope, the following attributes are added to the log:
+
+- `user.id`: The user ID.
+- `user.name`: The username.
+- `user.email`: The email address.
diff --git a/includes/logs/javascript-usage.mdx b/includes/logs/javascript-usage.mdx
index 07ae9450d678a8..3651682e37c076 100644
--- a/includes/logs/javascript-usage.mdx
+++ b/includes/logs/javascript-usage.mdx
@@ -7,30 +7,32 @@ Aside from the primary logging methods, we've provided a format text function, `
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.
```js
-const { logger } = Sentry;
-
-logger.error(logger.fmt`Uh on, something broke, here's the error: '${error}'`);
-logger.info(logger.fmt`'${user.username}' added '${product.name}' to cart.`);
+Sentry.logger.error(
+ Sentry.logger.fmt`Uh on, something broke, here's the error: '${error}'`
+);
+Sentry.logger.info(
+ Sentry.logger.fmt`'${user.username}' added '${product.name}' to cart.`
+);
```
You can also pass additional attributes directly to the logging functions, avoiding the need to use the `fmt` function.
```js
-const { logger } = Sentry;
-
-logger.trace("Starting database connection", { database: "users" });
-logger.debug("Cache miss for user", { userId: 123 });
-logger.info("Updated profile", { profileId: 345 });
-logger.warn("Rate limit reached for endpoint", {
+Sentry.logger.trace("Starting database connection", { database: "users" });
+Sentry.logger.debug("Cache miss for user", { userId: 123 });
+Sentry.logger.info("Updated profile", { profileId: 345 });
+Sentry.logger.warn("Rate limit reached for endpoint", {
endpoint: "/api/results/",
isEnterprise: false,
});
-logger.error("Failed to process payment", {
+Sentry.logger.error("Failed to process payment", {
orderId: "order_123",
amount: 99.99,
});
-logger.fatal("Database connection pool exhausted", {
+Sentry.logger.fatal("Database connection pool exhausted", {
database: "users",
activeConnections: 100,
});
```
+
+Setting a log message is required for the Sentry SDK to send the log to Sentry.
diff --git a/platform-includes/llm-rules-logs/javascript.nextjs.mdx b/platform-includes/llm-rules-logs/javascript.nextjs.mdx
index 926ba4a1c7eec3..7a9c51e9177f1d 100644
--- a/platform-includes/llm-rules-logs/javascript.nextjs.mdx
+++ b/platform-includes/llm-rules-logs/javascript.nextjs.mdx
@@ -7,7 +7,6 @@ When created as a rules file this should be placed alongside other editor specif
- Where logs are used, ensure Sentry is imported using `import * as Sentry from "@sentry/nextjs"`
- Enable logging in Sentry using `Sentry.init({ enableLogs: true })`
-- Reference the logger using `const { logger } = Sentry`
- Sentry offers a `consoleLoggingIntegration` that can be used to log specific console error types automatically without instrumenting the individual logger calls
## Configuration
@@ -21,7 +20,7 @@ import * as Sentry from "@sentry/nextjs";
Sentry.init({
dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
-
+ // Enable logs to be sent to Sentry
enableLogs: true,
});
```
@@ -40,25 +39,23 @@ Sentry.init({
## Logger Examples
-`logger.fmt` is a template literal function that should be used to bring variables into the structured logs.
+`Sentry.logger.fmt` is a template literal function that should be used to bring variables into the structured logs.
```javascript
import * as Sentry from "@sentry/nextjs";
-const { logger } = Sentry;
-
-logger.trace("Starting database connection", { database: "users" });
-logger.debug(logger.fmt`Cache miss for user: ${userId}`);
-logger.info("Updated profile", { profileId: 345 });
-logger.warn("Rate limit reached for endpoint", {
+Sentry.logger.trace("Starting database connection", { database: "users" });
+Sentry.logger.debug(Sentry.logger.fmt`Cache miss for user: ${userId}`);
+Sentry.logger.info("Updated profile", { profileId: 345 });
+Sentry.logger.warn("Rate limit reached for endpoint", {
endpoint: "/api/results/",
isEnterprise: false,
});
-logger.error("Failed to process payment", {
+Sentry.logger.error("Failed to process payment", {
orderId: "order_123",
amount: 99.99,
});
-logger.fatal("Database connection pool exhausted", {
+Sentry.logger.fatal("Database connection pool exhausted", {
database: "users",
activeConnections: 100,
});
diff --git a/platform-includes/llm-rules-logs/javascript.node.mdx b/platform-includes/llm-rules-logs/javascript.node.mdx
index 181489535fb1df..bc9bf1407d0214 100644
--- a/platform-includes/llm-rules-logs/javascript.node.mdx
+++ b/platform-includes/llm-rules-logs/javascript.node.mdx
@@ -7,7 +7,6 @@ When created as a rules file this should be placed alongside other editor specif
- Where logs are used, ensure Sentry is imported using `import * as Sentry from "@sentry/node"`
- Enable logging in Sentry using `Sentry.init({ enableLogs: true })`
-- Reference the logger using `const { logger } = Sentry`
- Sentry offers a `consoleLoggingIntegration` that can be used to log specific console error types automatically without instrumenting the individual logger calls
## Configuration
@@ -21,7 +20,7 @@ import * as Sentry from "@sentry/node";
Sentry.init({
dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
-
+ // Enable logs to be sent to Sentry
enableLogs: true,
});
```
@@ -40,25 +39,23 @@ Sentry.init({
## Logger Examples
-`logger.fmt` is a template literal function that should be used to bring variables into the structured logs.
+`Sentry.logger.fmt` is a template literal function that should be used to bring variables into the structured logs.
```javascript
import * as Sentry from "@sentry/node";
-const { logger } = Sentry;
-
-logger.trace("Starting database connection", { database: "users" });
-logger.debug(logger.fmt`Cache miss for user: ${userId}`);
-logger.info("Updated profile", { profileId: 345 });
-logger.warn("Rate limit reached for endpoint", {
+Sentry.logger.trace("Starting database connection", { database: "users" });
+Sentry.logger.debug(Sentry.logger.fmt`Cache miss for user: ${userId}`);
+Sentry.logger.info("Updated profile", { profileId: 345 });
+Sentry.logger.warn("Rate limit reached for endpoint", {
endpoint: "/api/results/",
isEnterprise: false,
});
-logger.error("Failed to process payment", {
+Sentry.logger.error("Failed to process payment", {
orderId: "order_123",
amount: 99.99,
});
-logger.fatal("Database connection pool exhausted", {
+Sentry.logger.fatal("Database connection pool exhausted", {
database: "users",
activeConnections: 100,
});
diff --git a/platform-includes/llm-rules-logs/javascript.react.mdx b/platform-includes/llm-rules-logs/javascript.react.mdx
index 2daf071136de71..0367cf04353350 100644
--- a/platform-includes/llm-rules-logs/javascript.react.mdx
+++ b/platform-includes/llm-rules-logs/javascript.react.mdx
@@ -7,7 +7,6 @@ When created as a rules file this should be placed alongside other editor specif
- Where logs are used, ensure Sentry is imported using `import * as Sentry from "@sentry/react"`
- Enable logging in Sentry using `Sentry.init({ enableLogs: true })`
-- Reference the logger using `const { logger } = Sentry`
- Sentry offers a `consoleLoggingIntegration` that can be used to log specific console error types automatically without instrumenting the individual logger calls
## Configuration
@@ -19,7 +18,7 @@ The Sentry initialization needs to be updated to enable the logs feature.
```javascript
Sentry.init({
dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
-
+ // Enable logs to be sent to Sentry
enableLogs: true,
});
```
@@ -38,25 +37,23 @@ Sentry.init({
## Logger Examples
-`logger.fmt` is a template literal function that should be used to bring variables into the structured logs.
+`Sentry.logger.fmt` is a template literal function that should be used to bring variables into the structured logs.
```javascript
import * as Sentry from "@sentry/react";
-const { logger } = Sentry;
-
-logger.trace("Starting database connection", { database: "users" });
-logger.debug(logger.fmt`Cache miss for user: ${userId}`);
-logger.info("Updated profile", { profileId: 345 });
-logger.warn("Rate limit reached for endpoint", {
+Sentry.logger.trace("Starting database connection", { database: "users" });
+Sentry.logger.debug(Sentry.logger.fmt`Cache miss for user: ${userId}`);
+Sentry.logger.info("Updated profile", { profileId: 345 });
+Sentry.logger.warn("Rate limit reached for endpoint", {
endpoint: "/api/results/",
isEnterprise: false,
});
-logger.error("Failed to process payment", {
+Sentry.logger.error("Failed to process payment", {
orderId: "order_123",
amount: 99.99,
});
-logger.fatal("Database connection pool exhausted", {
+Sentry.logger.fatal("Database connection pool exhausted", {
database: "users",
activeConnections: 100,
});
diff --git a/platform-includes/logs/default-attributes/android.mdx b/platform-includes/logs/default-attributes/android.mdx
new file mode 100644
index 00000000000000..f6e978e7232f36
--- /dev/null
+++ b/platform-includes/logs/default-attributes/android.mdx
@@ -0,0 +1,13 @@
+The Android SDK automatically sets several default attributes on all log entries to provide context and improve debugging:
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/platform-includes/logs/default-attributes/apple.mdx b/platform-includes/logs/default-attributes/apple.mdx
new file mode 100644
index 00000000000000..217ebd53850b7e
--- /dev/null
+++ b/platform-includes/logs/default-attributes/apple.mdx
@@ -0,0 +1,11 @@
+The Apple SDKs automatically sets several default attributes on all log entries to provide context and improve debugging:
+
+
+
+
+
+
+
+
+
+
diff --git a/platform-includes/logs/default-attributes/dart.flutter.mdx b/platform-includes/logs/default-attributes/dart.flutter.mdx
new file mode 100644
index 00000000000000..7b181eb685c5f2
--- /dev/null
+++ b/platform-includes/logs/default-attributes/dart.flutter.mdx
@@ -0,0 +1,13 @@
+The Flutter SDK automatically sets several default attributes on all log entries to provide context and improve debugging:
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/platform-includes/logs/default-attributes/dart.mdx b/platform-includes/logs/default-attributes/dart.mdx
new file mode 100644
index 00000000000000..ea38e0cab57afd
--- /dev/null
+++ b/platform-includes/logs/default-attributes/dart.mdx
@@ -0,0 +1,11 @@
+The Dart SDK automatically sets several default attributes on all log entries to provide context and improve debugging:
+
+
+
+
+
+
+
+
+
+
diff --git a/platform-includes/logs/default-attributes/dotnet.mdx b/platform-includes/logs/default-attributes/dotnet.mdx
new file mode 100644
index 00000000000000..58fc383acb8f04
--- /dev/null
+++ b/platform-includes/logs/default-attributes/dotnet.mdx
@@ -0,0 +1,11 @@
+The .NET SDK automatically sets several default attributes on all log entries to provide context and improve debugging:
+
+
+
+
+
+
+
+
+
+
diff --git a/platform-includes/logs/default-attributes/go.mdx b/platform-includes/logs/default-attributes/go.mdx
new file mode 100644
index 00000000000000..b355cf008b7729
--- /dev/null
+++ b/platform-includes/logs/default-attributes/go.mdx
@@ -0,0 +1,25 @@
+The Go SDK automatically sets several default attributes on all log entries to provide context and improve debugging:
+
+
+
+
+
+For example, with the following log:
+
+```go
+ctx := context.Background()
+logger := sentry.NewLogger(ctx)
+
+logger.Info().Emitf("A %s log message", "formatted")
+```
+
+Sentry will add the following attributes:
+
+- `message.template`: "A %s log message"
+- `message.parameter.0`: "formatted"
+
+
+
+
+
+
diff --git a/platform-includes/logs/default-attributes/java.mdx b/platform-includes/logs/default-attributes/java.mdx
new file mode 100644
index 00000000000000..d365d61d50f123
--- /dev/null
+++ b/platform-includes/logs/default-attributes/java.mdx
@@ -0,0 +1,13 @@
+The Java SDK automatically sets several default attributes on all log entries to provide context and improve debugging:
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/platform-includes/logs/default-attributes/javascript.astro.mdx b/platform-includes/logs/default-attributes/javascript.astro.mdx
new file mode 100644
index 00000000000000..bca9ddb2a852e9
--- /dev/null
+++ b/platform-includes/logs/default-attributes/javascript.astro.mdx
@@ -0,0 +1,15 @@
+The Astro SDK automatically sets several default attributes on all log entries to provide context and improve debugging:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/platform-includes/logs/default-attributes/javascript.bun.mdx b/platform-includes/logs/default-attributes/javascript.bun.mdx
new file mode 100644
index 00000000000000..32831c53e3123d
--- /dev/null
+++ b/platform-includes/logs/default-attributes/javascript.bun.mdx
@@ -0,0 +1,13 @@
+The Bun SDK automatically sets several default attributes on all log entries to provide context and improve debugging:
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/platform-includes/logs/default-attributes/javascript.cloudflare.mdx b/platform-includes/logs/default-attributes/javascript.cloudflare.mdx
new file mode 100644
index 00000000000000..abe462b8c9dcf7
--- /dev/null
+++ b/platform-includes/logs/default-attributes/javascript.cloudflare.mdx
@@ -0,0 +1,11 @@
+The Cloudflare SDK automatically sets several default attributes on all log entries to provide context and improve debugging:
+
+
+
+
+
+
+
+
+
+
diff --git a/platform-includes/logs/default-attributes/javascript.electron.mdx b/platform-includes/logs/default-attributes/javascript.electron.mdx
new file mode 100644
index 00000000000000..82f76db344967a
--- /dev/null
+++ b/platform-includes/logs/default-attributes/javascript.electron.mdx
@@ -0,0 +1,11 @@
+The Electron SDK automatically sets several default attributes on all log entries to provide context and improve debugging:
+
+
+
+
+
+
+
+
+
+
diff --git a/platform-includes/logs/default-attributes/javascript.mdx b/platform-includes/logs/default-attributes/javascript.mdx
new file mode 100644
index 00000000000000..51863c5e070dab
--- /dev/null
+++ b/platform-includes/logs/default-attributes/javascript.mdx
@@ -0,0 +1,13 @@
+The JavaScript SDK automatically sets several default attributes on all log entries to provide context and improve debugging:
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/platform-includes/logs/default-attributes/javascript.nextjs.mdx b/platform-includes/logs/default-attributes/javascript.nextjs.mdx
new file mode 100644
index 00000000000000..f93943895ba774
--- /dev/null
+++ b/platform-includes/logs/default-attributes/javascript.nextjs.mdx
@@ -0,0 +1,15 @@
+The Next.js SDK automatically sets several default attributes on all log entries to provide context and improve debugging:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/platform-includes/logs/default-attributes/javascript.node.mdx b/platform-includes/logs/default-attributes/javascript.node.mdx
new file mode 100644
index 00000000000000..93de1bf8d63e0c
--- /dev/null
+++ b/platform-includes/logs/default-attributes/javascript.node.mdx
@@ -0,0 +1,13 @@
+The Node SDK automatically sets several default attributes on all log entries to provide context and improve debugging:
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/platform-includes/logs/default-attributes/javascript.nuxt.mdx b/platform-includes/logs/default-attributes/javascript.nuxt.mdx
new file mode 100644
index 00000000000000..b983d06484bee9
--- /dev/null
+++ b/platform-includes/logs/default-attributes/javascript.nuxt.mdx
@@ -0,0 +1,15 @@
+The Nuxt SDK automatically sets several default attributes on all log entries to provide context and improve debugging:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/platform-includes/logs/default-attributes/javascript.react-router.mdx b/platform-includes/logs/default-attributes/javascript.react-router.mdx
new file mode 100644
index 00000000000000..f30dd02bd50051
--- /dev/null
+++ b/platform-includes/logs/default-attributes/javascript.react-router.mdx
@@ -0,0 +1,15 @@
+The React Router SDK automatically sets several default attributes on all log entries to provide context and improve debugging:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/platform-includes/logs/default-attributes/javascript.remix.mdx b/platform-includes/logs/default-attributes/javascript.remix.mdx
new file mode 100644
index 00000000000000..7590276a400728
--- /dev/null
+++ b/platform-includes/logs/default-attributes/javascript.remix.mdx
@@ -0,0 +1,15 @@
+The Remix SDK automatically sets several default attributes on all log entries to provide context and improve debugging:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/platform-includes/logs/default-attributes/javascript.solidstart.mdx b/platform-includes/logs/default-attributes/javascript.solidstart.mdx
new file mode 100644
index 00000000000000..1638a511f8828e
--- /dev/null
+++ b/platform-includes/logs/default-attributes/javascript.solidstart.mdx
@@ -0,0 +1,15 @@
+The SolidStart SDK automatically sets several default attributes on all log entries to provide context and improve debugging:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/platform-includes/logs/default-attributes/javascript.sveltekit.mdx b/platform-includes/logs/default-attributes/javascript.sveltekit.mdx
new file mode 100644
index 00000000000000..a84eea7e7d3360
--- /dev/null
+++ b/platform-includes/logs/default-attributes/javascript.sveltekit.mdx
@@ -0,0 +1,15 @@
+The SvelteKit SDK automatically sets several default attributes on all log entries to provide context and improve debugging:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/platform-includes/logs/default-attributes/javascript.tanstackstart-react.mdx b/platform-includes/logs/default-attributes/javascript.tanstackstart-react.mdx
new file mode 100644
index 00000000000000..74f96461d9db60
--- /dev/null
+++ b/platform-includes/logs/default-attributes/javascript.tanstackstart-react.mdx
@@ -0,0 +1,15 @@
+The Tanstack Start React SDK automatically sets several default attributes on all log entries to provide context and improve debugging:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/platform-includes/logs/default-attributes/php.laravel.mdx b/platform-includes/logs/default-attributes/php.laravel.mdx
new file mode 100644
index 00000000000000..3638525f618ed4
--- /dev/null
+++ b/platform-includes/logs/default-attributes/php.laravel.mdx
@@ -0,0 +1,11 @@
+The Laravel SDK automatically sets several default attributes on all log entries to provide context and improve debugging:
+
+
+
+
+
+
+
+
+
+
diff --git a/platform-includes/logs/default-attributes/php.mdx b/platform-includes/logs/default-attributes/php.mdx
new file mode 100644
index 00000000000000..2a9d33e197e7e0
--- /dev/null
+++ b/platform-includes/logs/default-attributes/php.mdx
@@ -0,0 +1,11 @@
+The PHP SDK automatically sets several default attributes on all log entries to provide context and improve debugging:
+
+
+
+
+
+
+
+
+
+
diff --git a/platform-includes/logs/default-attributes/python.mdx b/platform-includes/logs/default-attributes/python.mdx
new file mode 100644
index 00000000000000..432e0474b4fab3
--- /dev/null
+++ b/platform-includes/logs/default-attributes/python.mdx
@@ -0,0 +1,11 @@
+The Python SDK automatically sets several default attributes on all log entries to provide context and improve debugging:
+
+
+
+
+
+
+
+
+
+
diff --git a/platform-includes/logs/default-attributes/react-native.mdx b/platform-includes/logs/default-attributes/react-native.mdx
new file mode 100644
index 00000000000000..6e2d611919d282
--- /dev/null
+++ b/platform-includes/logs/default-attributes/react-native.mdx
@@ -0,0 +1,13 @@
+The React Native SDK automatically sets several default attributes on all log entries to provide context and improve debugging:
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/platform-includes/logs/default-attributes/ruby.mdx b/platform-includes/logs/default-attributes/ruby.mdx
new file mode 100644
index 00000000000000..1dc3439b12c122
--- /dev/null
+++ b/platform-includes/logs/default-attributes/ruby.mdx
@@ -0,0 +1,11 @@
+The Ruby SDK automatically sets several default attributes on all log entries to provide context and improve debugging:
+
+
+
+
+
+
+
+
+
+
diff --git a/platform-includes/logs/integrations/go.mdx b/platform-includes/logs/integrations/go.mdx
new file mode 100644
index 00000000000000..0982684eb41a1c
--- /dev/null
+++ b/platform-includes/logs/integrations/go.mdx
@@ -0,0 +1,16 @@
+### Supported libraries
+
+- [Slog](/platforms/go/guides/slog)
+- [Logrus](/platforms/go/guides/logrus)
+
+### `io.Writer` interface
+
+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.
+
+```go
+sentryLogger := sentry.NewLogger(ctx)
+logger := log.New(sentryLogger, "", log.LstdFlags)
+logger.Println("Implementing log.Logger")
+```
diff --git a/platform-includes/logs/options/go.mdx b/platform-includes/logs/options/go.mdx
new file mode 100644
index 00000000000000..534ed7dd85db36
--- /dev/null
+++ b/platform-includes/logs/options/go.mdx
@@ -0,0 +1,22 @@
+#### BeforeSendLog
+
+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
+ },
+})
+```
diff --git a/platform-includes/logs/requirements/go.mdx b/platform-includes/logs/requirements/go.mdx
new file mode 100644
index 00000000000000..a8531fab271b98
--- /dev/null
+++ b/platform-includes/logs/requirements/go.mdx
@@ -0,0 +1 @@
+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.
diff --git a/platform-includes/logs/setup/go.mdx b/platform-includes/logs/setup/go.mdx
index 924fa933b857e5..4d814bff3e6bc3 100644
--- a/platform-includes/logs/setup/go.mdx
+++ b/platform-includes/logs/setup/go.mdx
@@ -13,6 +13,7 @@ import (
func main() {
if err := sentry.Init(sentry.ClientOptions{
Dsn: "___PUBLIC_DSN___",
+ // Enable logs to be sent to Sentry
EnableLogs: true,
}); err != nil {
fmt.Printf("Sentry initialization failed: %v\n", err)
@@ -20,4 +21,4 @@ func main() {
// Flush buffered events before the program terminates.
defer sentry.Flush(2 * time.Second)
}
-```
\ No newline at end of file
+```
diff --git a/platform-includes/logs/usage/android.mdx b/platform-includes/logs/usage/android.mdx
index d9eff3ff266814..7f8e73911203c9 100644
--- a/platform-includes/logs/usage/android.mdx
+++ b/platform-includes/logs/usage/android.mdx
@@ -64,4 +64,4 @@ Sentry.logger().log(
"log message %s",
"param1"
)
-```
\ No newline at end of file
+```
diff --git a/platform-includes/logs/usage/go.mdx b/platform-includes/logs/usage/go.mdx
new file mode 100644
index 00000000000000..9479ee1441ee71
--- /dev/null
+++ b/platform-includes/logs/usage/go.mdx
@@ -0,0 +1,61 @@
+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`.