Skip to content

Commit 33d980b

Browse files
authored
feat(go): refactor tracing docs (#16172)
1 parent 4f784cd commit 33d980b

19 files changed

Lines changed: 243 additions & 181 deletions

File tree

docs/platforms/go/common/logs/index.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,5 @@ If the `Debug` init option is set to true, calls to the `sentry.Logger` will als
3838
## Other Logging Integrations
3939

4040
<PlatformContent includePath="logs/integrations" />
41+
42+
<PageGrid />
Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
title: Logrus
3-
description: "Logrus is a structured logger for Go, used to log messages in different formats and levels. This guide demonstrates how to integrate Logrus with Sentry to capture and send both logs and events to Sentry."
3+
description: "Integrate Logrus with Sentry to capture and send both logs and events."
4+
sidebar_order: 10
45
---
56

67
For a quick reference, there is a [complete example](https://github.com/getsentry/sentry-go/tree/master/_examples/logrus) at the Go SDK source code repository.
@@ -178,11 +179,3 @@ if client != nil {
178179
</Alert>
179180

180181
<Include name="logs/go-ctx-usage-alert.mdx"/>
181-
182-
## Logs
183-
184-
For comprehensive logging setup with Logrus, including advanced configuration options and best practices, see the [Go Logs documentation](/platforms/go/logs/). The Logrus integration shown above provides seamless integration with Sentry's structured logging features.
185-
186-
## Next Steps
187-
188-
- Explore [practical guides](/guides/) on what to monitor, log, track, and investigate after setup
Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
title: Slog
3-
description: "Slog is a structured logging library for Go, introduced in Go 1.21. This guide demonstrates how to integrate slog with Sentry to capture and send logs to Sentry."
3+
description: "Integrate slog with Sentry to capture and send structured logs."
4+
sidebar_order: 20
45
---
56

67
For a quick reference, there is a [complete example](https://github.com/getsentry/sentry-go/tree/master/_examples/slog) at the Go SDK source code repository.
@@ -84,11 +85,3 @@ logger.With("key.string", "value").Info("An error occurred")
8485
```
8586

8687
<Include name="logs/go-ctx-usage-alert.mdx"/>
87-
88-
## Logs
89-
90-
For comprehensive logging setup with slog, including advanced configuration options and best practices, see the [Go Logs documentation](/platforms/go/logs/). The slog integration shown above provides seamless integration with Sentry's structured logging features.
91-
92-
## Next Steps
93-
94-
- Explore [practical guides](/guides/) on what to monitor, log, track, and investigate after setup
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
title: Zap
3-
description: "Zap is a blazing-fast, structured logging library for Go. This guide demonstrates how to integrate zap with Sentry to capture and send logs to Sentry."
3+
description: "Integrate Zap with Sentry to capture and send structured logs."
4+
sidebar_order: 15
45
---
56

67
For a quick reference, there is a [complete example](https://github.com/getsentry/sentry-go/tree/master/_examples/zap) at the Go SDK source code repository.
@@ -136,7 +137,3 @@ scopedLogger.Info("Processing completed")
136137
```
137138

138139
<Include name="logs/go-ctx-usage-alert.mdx"/>
139-
140-
## Logs
141-
142-
For comprehensive logging setup with zap, including advanced configuration options and best practices, see the [Go Logs documentation](/platforms/go/logs/). The zap integration shown above provides seamless integration with Sentry's structured logging features.

docs/platforms/go/guides/zerolog/index.mdx renamed to docs/platforms/go/common/logs/zerolog.mdx

Lines changed: 66 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
---
22
title: Zerolog
3-
description: "Zerolog is a fast and efficient logging library for Go, designed for structured logging. This guide demonstrates how to integrate Zerolog with Sentry."
3+
description: "Capture error events from Zerolog and send them to Sentry. Note: Zerolog does not support Structured Logs."
4+
sidebar_order: 30
45
---
56

7+
<Alert level="warning">
8+
9+
The zerolog integration sends error events to Sentry but does not support Structured Logs due to architectural limitations:
10+
- The `io.Writer` interface lacks access to `context.Context`, preventing proper per-request hub isolation
11+
- In concurrent applications, breadcrumbs from different requests may leak into each other's events
12+
- Related issues: [#1178](https://github.com/getsentry/sentry-go/issues/1178), [#1029](https://github.com/getsentry/sentry-go/issues/1029)
13+
14+
For Structured Logs, use our Sentry.Logger or any of the supported integrations instead.
15+
16+
</Alert>
17+
618
For a complete example, visit the [Go SDK source code repository](https://github.com/getsentry/sentry-go/tree/master/_examples/zerolog).
719

820
[Go Dev-style API documentation](https://pkg.go.dev/github.com/getsentry/sentry-go/zerolog) is also available.
@@ -14,8 +26,6 @@ go get github.com/getsentry/sentry-go
1426
go get github.com/getsentry/sentry-go/zerolog
1527
```
1628

17-
<Break />
18-
1929
## Configure
2030

2131
### Initialize the Sentry SDK
@@ -29,8 +39,8 @@ The sentryzerolog.Options struct has the following fields:
2939

3040
```go
3141
// Levels specifies the log levels that will trigger event sending to Sentry.
32-
// Only log messages at these levels will be sent. By default, the levels are
33-
// Error, Fatal, and Panic.
42+
// Only log messages at these levels will be sent as error events. By default,
43+
// the levels are Error, Fatal, and Panic.
3444
Levels []zerolog.Level
3545

3646
// WithBreadcrumbs, when enabled, adds log entries as breadcrumbs in Sentry.
@@ -40,43 +50,63 @@ WithBreadcrumbs bool
4050

4151
// FlushTimeout sets the maximum duration allowed for flushing events to Sentry.
4252
// This is the time limit within which all pending events must be sent to Sentry
43-
// before the application exits. A typical use is ensuring all logs are sent before
44-
// application shutdown. The default timeout is usually 3 seconds.
53+
// before the application exits. The default timeout is usually 3 seconds.
4554
FlushTimeout time.Duration
4655
```
4756

48-
## Verify
57+
## What Zerolog Integration Supports
58+
59+
The zerolog integration **does** support sending **error events** to Sentry:
4960

5061
```go
51-
// Configure Zerolog to use Sentry as a writer
52-
sentryWriter, err := sentryzerolog.New(sentryzerolog.Config{
53-
ClientOptions: sentry.ClientOptions{
62+
import (
63+
"errors"
64+
"time"
65+
"os"
66+
67+
"github.com/getsentry/sentry-go"
68+
sentryzerolog "github.com/getsentry/sentry-go/zerolog"
69+
"github.com/rs/zerolog"
70+
"github.com/rs/zerolog/log"
71+
)
72+
73+
func main() {
74+
// Initialize Sentry
75+
err := sentry.Init(sentry.ClientOptions{
5476
Dsn: "___PUBLIC_DSN___",
55-
},
56-
Options: sentryzerolog.Options{
57-
Levels: []zerolog.Level{zerolog.ErrorLevel, zerolog.FatalLevel, zerolog.PanicLevel},
58-
WithBreadcrumbs: true,
59-
FlushTimeout: 3 * time.Second,
60-
},
61-
})
62-
if err != nil {
63-
log.Fatal().Err(err).Msg("failed to create sentry writer")
64-
}
65-
defer sentryWriter.Close()
77+
// Note: EnableLogs is for Structured Logs, not zerolog error events
78+
})
79+
if err != nil {
80+
log.Fatal().Err(err).Msg("sentry initialization failed")
81+
}
82+
defer sentry.Flush(2 * time.Second)
6683

67-
// Use Sentry writer in Zerolog
68-
log.Logger = log.Output(zerolog.MultiLevelWriter(zerolog.ConsoleWriter{Out: os.Stderr}, sentryWriter))
84+
// Configure Zerolog to send error events to Sentry
85+
sentryWriter, err := sentryzerolog.New(sentryzerolog.Config{
86+
Options: sentryzerolog.Options{
87+
// These levels will be sent as error events
88+
Levels: []zerolog.Level{zerolog.ErrorLevel, zerolog.FatalLevel, zerolog.PanicLevel},
89+
// Disable breadcrumbs in concurrent applications to prevent leakage
90+
WithBreadcrumbs: false,
91+
FlushTimeout: 3 * time.Second,
92+
},
93+
})
94+
if err != nil {
95+
log.Fatal().Err(err).Msg("failed to create sentry writer")
96+
}
97+
defer sentryWriter.Close()
6998

70-
// Test logging - this will be sent to Sentry as an event
71-
log.Error().Msg("This error will be sent to Sentry!")
99+
// Use Sentry writer in Zerolog
100+
log.Logger = log.Output(zerolog.MultiLevelWriter(zerolog.ConsoleWriter{Out: os.Stderr}, sentryWriter))
72101

73-
// Example of logging with error context
74-
log.Error().Err(errors.New("test error")).Msg("An error occurred")
102+
// This will be sent as an error event to Sentry
103+
log.Error().Msg("This is an error event, not a structured log")
104+
}
75105
```
76106

77107
## Usage
78108

79-
To integrate Sentry with Zerolog, you need to set up a custom writer that sends logs to Sentry based on the configured levels.
109+
To integrate Sentry with Zerolog, you need to set up a custom writer that sends error events to Sentry based on the configured levels.
80110

81111
```go
82112
import (
@@ -131,18 +161,18 @@ func main() {
131161
// Log an InfoLevel entry to STDERR (not sent to Sentry)
132162
log.Info().Msg("Application has started")
133163

134-
// Log an ErrorLevel entry to STDERR and Sentry
164+
// Log an ErrorLevel entry to STDERR and send as error event to Sentry
135165
log.Error().Msg("oh no!")
136166

137-
// Log a FatalLevel entry to STDERR, send to Sentry, and terminate the application
167+
// Log a FatalLevel entry to STDERR, send as error event to Sentry, and terminate the application
138168
log.Fatal().Err(errors.New("can't continue")).Msg("fatal error occurred")
139169
}
140170
```
141171

142172

143173
### Using `hubProvider` for Scoped Sentry Hubs
144174

145-
The hubProvider allows you to configure the Sentry hook to use a custom Sentry hub. This can be particularly useful when you want to scope logs to specific goroutines or operations, enabling more precise grouping and context in Sentry.
175+
The hubProvider allows you to configure the Sentry hook to use a custom Sentry hub. This can be particularly useful when you want to scope error events to specific goroutines or operations, enabling more precise grouping and context in Sentry.
146176

147177
You can set a custom hubProvider function using the SetHubProvider method:
148178

@@ -153,13 +183,13 @@ sentryHook.SetHubProvider(func() *sentry.Hub {
153183
})
154184
```
155185

156-
This ensures that logs from specific contexts or threads use the appropriate Sentry hub and scope.
186+
This ensures that error events from specific contexts or threads use the appropriate Sentry hub and scope.
157187

158188

159-
Use Zerolog as you normally would, and it will automatically send logs at or above the specified levels to Sentry.
189+
Use Zerolog as you normally would, and it will automatically send error events at or above the specified levels to Sentry.
160190

161191
Note: Ensure Sentry is flushed before the application exits to avoid losing any pending events.
162192

163-
## Next Steps
193+
## Concurrent Applications
164194

165-
- Explore [practical guides](/guides/) on what to monitor, log, track, and investigate after setup
195+
For concurrent applications (HTTP/gRPC servers), use scoped hubs to link error events to traces. See the `hubProvider` section above and the <PlatformLink to="/tracing/instrumentation/custom-instrumentation/">Custom Instrumentation</PlatformLink> documentation for best practices on proper hub management.

docs/platforms/go/common/tracing/index.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ Learn more about tracing <PlatformLink to="/configuration/options/#tracing-optio
3434

3535
## Verify
3636

37-
Test out tracing by starting and finishing a transaction, which you _must_ do so transactions can be sent to Sentry. Learn how in our <PlatformLink to="/tracing/instrumentation/custom-instrumentation/">Custom Instrumentation</PlatformLink> content.
37+
If you're using an HTTP framework with Sentry middleware (Gin, Echo, Fiber, etc.), transactions are created automatically for every incoming request. See <PlatformLink to="/tracing/instrumentation/auto-instrumentation/">Automatic Instrumentation</PlatformLink> for details.
38+
39+
If you're not using a supported framework, you can manually create transactions. Learn how in our <PlatformLink to="/tracing/instrumentation/custom-instrumentation/">Custom Instrumentation</PlatformLink> content.
3840

3941
While you're testing, set <PlatformIdentifier name="traces-sample-rate" /> to `1.0`, as that ensures that every transaction will be sent to Sentry. Once testing is complete, you may want to set a lower <PlatformIdentifier name="traces-sample-rate" /> value, or switch to using <PlatformIdentifier name="traces-sampler" /> to selectively sample and filter your transactions, based on contextual data.
4042

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
title: Automatic Instrumentation
3+
description: "Learn what gets captured automatically when using Sentry's HTTP framework middleware."
4+
sidebar_order: 10
5+
---
6+
7+
If you're using one of Sentry's HTTP framework middlewares, transactions are created automatically for all incoming HTTP requests when tracing is enabled. No additional code is needed beyond the middleware setup.
8+
9+
## What Gets Captured
10+
11+
<PlatformContent includePath="tracing/automatic-instrumentation/http-frameworks" />
12+
13+
## Supported Frameworks
14+
15+
Sentry provides middleware for the following Go HTTP frameworks:
16+
17+
| Framework | Package | Guide |
18+
|-----------|---------|-------|
19+
| Gin | `sentry-go/gin` | [Gin guide](/platforms/go/guides/gin/) |
20+
| Echo | `sentry-go/echo` | [Echo guide](/platforms/go/guides/echo/) |
21+
| Fiber | `sentry-go/fiber` | [Fiber guide](/platforms/go/guides/fiber/) |
22+
| net/http | `sentry-go/http` | [net/http guide](/platforms/go/guides/http/) |
23+
| Iris | `sentry-go/iris` | [Iris guide](/platforms/go/guides/iris/) |
24+
| FastHTTP | `sentry-go/fasthttp` | [FastHTTP guide](/platforms/go/guides/fasthttp/) |
25+
| Negroni | `sentry-go/negroni` | [Negroni guide](/platforms/go/guides/negroni/) |
26+
27+
Each middleware is installed and configured as part of the framework setup. See the individual guide pages for installation instructions.
28+
29+
## HTTP Client Spans
30+
31+
For outbound HTTP requests, use the `sentryhttpclient` package to automatically create spans for client requests. See the <PlatformLink to="/tracing/instrumentation/custom-instrumentation/requests-module/">HTTP Requests</PlatformLink> documentation for details.
32+
33+
## Adding Custom Spans
34+
35+
Once the middleware creates a transaction, you can add child spans within your handlers to track specific operations. See <PlatformLink to="/tracing/instrumentation/custom-instrumentation/">Custom Instrumentation</PlatformLink> for details.

0 commit comments

Comments
 (0)