diff --git a/docs/platforms/go/guides/echo/tracing/instrumentation/echo.mdx b/docs/platforms/go/guides/echo/tracing/instrumentation/echo.mdx new file mode 100644 index 0000000000000..005fe4778316a --- /dev/null +++ b/docs/platforms/go/guides/echo/tracing/instrumentation/echo.mdx @@ -0,0 +1,28 @@ +--- +title: Automatic Instrumentation +sidebar_order: 1 +sdk: sentry.go.echo +description: "Learn about tracing instrumentation for the Echo HTTP framework." +--- + + + +To capture transactions, you'll need to first set up tracing. + + + +The `sentryecho` middleware provides automatic tracing and error capturing for Echo applications. The source can be found [on GitHub](https://github.com/getsentry/sentry-go/tree/master/echo). + +For installation and configuration instructions, see the [Echo Getting Started](/platforms/go/guides/echo/) guide. + +## Automatic Instrumentation + + + +## Adding Custom Spans + +You can add custom child spans to track specific operations within your handlers. See the Custom Instrumentation documentation for details on manual span creation. + +## Distributed Tracing + +The `sentryecho` middleware automatically continues traces from upstream services by reading Sentry trace headers from incoming requests. No additional configuration is needed. diff --git a/docs/platforms/go/guides/fasthttp/tracing/instrumentation/fasthttp.mdx b/docs/platforms/go/guides/fasthttp/tracing/instrumentation/fasthttp.mdx new file mode 100644 index 0000000000000..10585c0a1e347 --- /dev/null +++ b/docs/platforms/go/guides/fasthttp/tracing/instrumentation/fasthttp.mdx @@ -0,0 +1,28 @@ +--- +title: Automatic Instrumentation +sidebar_order: 1 +sdk: sentry.go.fasthttp +description: "Learn about tracing instrumentation for the FastHTTP framework." +--- + + + +To capture transactions, you'll need to first set up tracing. + + + +The `sentryfasthttp` middleware provides automatic tracing and error capturing for FastHTTP applications. The source can be found [on GitHub](https://github.com/getsentry/sentry-go/tree/master/fasthttp). + +For installation and configuration instructions, see the [FastHTTP Getting Started](/platforms/go/guides/fasthttp/) guide. + +## Automatic Instrumentation + + + +## Adding Custom Spans + +You can add custom child spans to track specific operations. See the Custom Instrumentation documentation for details on manual span creation. + +## Distributed Tracing + +The `sentryfasthttp` middleware automatically continues traces from upstream services by reading Sentry trace headers from incoming requests. No additional configuration is needed. diff --git a/docs/platforms/go/guides/fiber/tracing/instrumentation/fiber.mdx b/docs/platforms/go/guides/fiber/tracing/instrumentation/fiber.mdx new file mode 100644 index 0000000000000..00c835597d7f8 --- /dev/null +++ b/docs/platforms/go/guides/fiber/tracing/instrumentation/fiber.mdx @@ -0,0 +1,28 @@ +--- +title: Automatic Instrumentation +sidebar_order: 1 +sdk: sentry.go.fiber +description: "Learn about tracing instrumentation for the Fiber HTTP framework." +--- + + + +To capture transactions, you'll need to first set up tracing. + + + +The `sentryfiber` middleware provides automatic tracing and error capturing for Fiber applications. The source can be found [on GitHub](https://github.com/getsentry/sentry-go/tree/master/fiber). + +For installation and configuration instructions, see the [Fiber Getting Started](/platforms/go/guides/fiber/) guide. + +## Automatic Instrumentation + + + +## Adding Custom Spans + +You can add custom child spans to track specific operations. See the Custom Instrumentation documentation for details on manual span creation. + +## Distributed Tracing + +The `sentryfiber` middleware automatically continues traces from upstream services by reading Sentry trace headers from incoming requests. No additional configuration is needed. diff --git a/docs/platforms/go/guides/gin/tracing/instrumentation/gin.mdx b/docs/platforms/go/guides/gin/tracing/instrumentation/gin.mdx new file mode 100644 index 0000000000000..9e841dc200f0e --- /dev/null +++ b/docs/platforms/go/guides/gin/tracing/instrumentation/gin.mdx @@ -0,0 +1,28 @@ +--- +title: Automatic Instrumentation +sidebar_order: 1 +sdk: sentry.go.gin +description: "Learn about tracing instrumentation for the Gin HTTP framework." +--- + + + +To capture transactions, you'll need to first set up tracing. + + + +The `sentrygin` middleware provides automatic tracing and error capturing for Gin applications. The source can be found [on GitHub](https://github.com/getsentry/sentry-go/tree/master/gin). + +For installation and configuration instructions, see the [Gin Getting Started](/platforms/go/guides/gin/) guide. + +## Automatic Instrumentation + + + +## Adding Custom Spans + +You can add custom child spans to track specific operations within your handlers. See the Custom Instrumentation documentation for details on manual span creation. + +## Distributed Tracing + +The `sentrygin` middleware automatically continues traces from upstream services by reading Sentry trace headers from incoming requests. No additional configuration is needed. diff --git a/docs/platforms/go/guides/http/tracing/instrumentation/http.mdx b/docs/platforms/go/guides/http/tracing/instrumentation/http.mdx new file mode 100644 index 0000000000000..c6710dec97ab5 --- /dev/null +++ b/docs/platforms/go/guides/http/tracing/instrumentation/http.mdx @@ -0,0 +1,30 @@ +--- +title: Automatic Instrumentation +sidebar_order: 1 +sdk: sentry.go.http +description: "Learn about tracing instrumentation for the standard library net/http package." +--- + + + +To capture transactions, you'll need to first set up tracing. + + + +The `sentryhttp` middleware provides automatic tracing and error capturing for applications using Go's standard `net/http` package. The source can be found [on GitHub](https://github.com/getsentry/sentry-go/tree/master/http). + +For installation and configuration instructions, see the [net/http Getting Started](/platforms/go/guides/http/) guide. + +## Automatic Instrumentation + + + +## Adding Custom Spans + +You can add custom child spans to track specific operations within your handlers. See the Custom Instrumentation documentation for details on manual span creation. + +## Distributed Tracing + +The `sentryhttp` middleware automatically continues traces from upstream services by reading Sentry trace headers from incoming requests. No additional configuration is needed. + +For outbound HTTP requests with tracing, see the HTTP Requests documentation. diff --git a/docs/platforms/go/guides/iris/tracing/instrumentation/iris.mdx b/docs/platforms/go/guides/iris/tracing/instrumentation/iris.mdx new file mode 100644 index 0000000000000..9878e2a8ec14a --- /dev/null +++ b/docs/platforms/go/guides/iris/tracing/instrumentation/iris.mdx @@ -0,0 +1,28 @@ +--- +title: Automatic Instrumentation +sidebar_order: 1 +sdk: sentry.go.iris +description: "Learn about tracing instrumentation for the Iris HTTP framework." +--- + + + +To capture transactions, you'll need to first set up tracing. + + + +The `sentryiris` middleware provides automatic tracing and error capturing for Iris applications. The source can be found [on GitHub](https://github.com/getsentry/sentry-go/tree/master/iris). + +For installation and configuration instructions, see the [Iris Getting Started](/platforms/go/guides/iris/) guide. + +## Automatic Instrumentation + + + +## Adding Custom Spans + +You can add custom child spans to track specific operations. See the Custom Instrumentation documentation for details on manual span creation. + +## Distributed Tracing + +The `sentryiris` middleware automatically continues traces from upstream services by reading Sentry trace headers from incoming requests. No additional configuration is needed. diff --git a/docs/platforms/go/guides/logrus/tracing/instrumentation/logrus.mdx b/docs/platforms/go/guides/logrus/tracing/instrumentation/logrus.mdx new file mode 100644 index 0000000000000..8eddbfc99e3a5 --- /dev/null +++ b/docs/platforms/go/guides/logrus/tracing/instrumentation/logrus.mdx @@ -0,0 +1,92 @@ +--- +title: Logrus Integration with Tracing +sidebar_order: 200 +sdk: sentry.go.logrus +description: "Learn how to link Logrus logs with distributed traces." +--- + + + +To link logs with traces, you'll need to first set up tracing. + + + +The `sentrylogrus` integration provides structured logging support. When combined with tracing, you can link your logs to traces by using `NewLogHook` with context-aware logging methods. + +## Linking Logs to Traces + +To link your Logrus logs to active traces, use `NewLogHook` (which supports context) and log with `WithContext(ctx)`. + +### Example + +```go +package main + +import ( + "fmt" + "net/http" + "time" + + "github.com/getsentry/sentry-go" + sentryhttp "github.com/getsentry/sentry-go/http" + sentrylogrus "github.com/getsentry/sentry-go/logrus" + "github.com/sirupsen/logrus" +) + +var logger = logrus.New() + +func main() { + // Initialize Sentry with tracing and logs enabled + if err := sentry.Init(sentry.ClientOptions{ + Dsn: "___PUBLIC_DSN___", + EnableTracing: true, + TracesSampleRate: 1.0, + EnableLogs: true, + LogsSampleRate: 1.0, + }); err != nil { + panic(err) + } + defer sentry.Flush(2 * time.Second) + + // Use NewLogHook to send logs with context support + hook, err := sentrylogrus.NewLogHook( + []logrus.Level{logrus.InfoLevel, logrus.ErrorLevel}, + sentry.ClientOptions{ + Dsn: "___PUBLIC_DSN___", + EnableLogs: true, + }, + ) + if err != nil { + panic(err) + } + defer hook.Flush(5 * time.Second) + logger.AddHook(hook) + + sentryHandler := sentryhttp.New(sentryhttp.Options{}) + http.Handle("/", sentryHandler.Handle(http.HandlerFunc(handler))) + + fmt.Println("Listening on :3000") + http.ListenAndServe(":3000", nil) +} + +func handler(w http.ResponseWriter, r *http.Request) { + ctx := r.Context() + // Logs with context are automatically linked to the active trace + logger.WithContext(ctx).Info("Processing request") + + w.Write([]byte("OK")) +} +``` + +## Best Practices + +- **Use `NewLogHook` not `NewEventHook`**: Only `NewLogHook` supports context-based trace linking +- **Enable logs**: Set `EnableLogs: true` in ClientOptions +- **Use `WithContext`**: Always use `logger.WithContext(ctx)` to associate logs with the active trace +- **Log within transactions**: Ensure logs are created while a transaction or span is active + +## Related Documentation + +- Logs - Comprehensive logging setup +- Custom Instrumentation - Manual tracing setup +- [Logrus Integration Guide](/platforms/go/guides/logrus/) - Full Logrus integration details diff --git a/docs/platforms/go/guides/negroni/tracing/instrumentation/negroni.mdx b/docs/platforms/go/guides/negroni/tracing/instrumentation/negroni.mdx new file mode 100644 index 0000000000000..8e581e19671ce --- /dev/null +++ b/docs/platforms/go/guides/negroni/tracing/instrumentation/negroni.mdx @@ -0,0 +1,24 @@ +--- +title: Automatic Instrumentation +sidebar_order: 1 +sdk: sentry.go.negroni +description: "Learn about tracing instrumentation for the Negroni HTTP middleware." +--- + + + +To capture transactions, you'll need to first set up tracing. + + + +The `sentrynegroni` middleware provides automatic tracing and error capturing for applications using Negroni. The source can be found [on GitHub](https://github.com/getsentry/sentry-go/tree/master/negroni). + +For installation and configuration instructions, see the [Negroni Getting Started](/platforms/go/guides/negroni/) guide. + +## Automatic Instrumentation + + + +## Adding Custom Spans + +You can add custom child spans to track specific operations. See the Custom Instrumentation documentation for details on manual span creation. diff --git a/docs/platforms/go/guides/slog/tracing/instrumentation/slog.mdx b/docs/platforms/go/guides/slog/tracing/instrumentation/slog.mdx new file mode 100644 index 0000000000000..b31489bc61fb7 --- /dev/null +++ b/docs/platforms/go/guides/slog/tracing/instrumentation/slog.mdx @@ -0,0 +1,72 @@ +--- +title: Slog Integration with Tracing +sidebar_order: 201 +sdk: sentry.go.slog +description: "Learn how to link Slog logs with distributed traces." +--- + + + +To link logs with traces, you'll need to first set up tracing. + + + +The `sentryslog` integration provides structured logging support for Go's standard `log/slog` package (Go 1.21+). When combined with tracing, you can link your logs to traces for better observability. + +## Linking Logs to Traces + +To link your Slog logs to active traces, you need to use context-aware logging methods like `logger.InfoContext()`. + +### Example + +```go +package main + +import ( + "context" + "fmt" + "log/slog" + "net/http" + "time" + + "github.com/getsentry/sentry-go" + sentryhttp "github.com/getsentry/sentry-go/http" +) + +func main() { + // Initialize Sentry with tracing enabled + if err := sentry.Init(sentry.ClientOptions{ + Dsn: "___PUBLIC_DSN___", + EnableTracing: true, + TracesSampleRate: 1.0, + }); err != nil { + panic(err) + } + defer sentry.Flush(2 * time.Second) + + sentryHandler := sentryhttp.New(sentryhttp.Options{}) + http.Handle("/", sentryHandler.Handle(http.HandlerFunc(handler))) + + fmt.Println("Listening on :3000") + http.ListenAndServe(":3000", nil) +} + +func handler(w http.ResponseWriter, r *http.Request) { + ctx := r.Context() + // Logs with context are automatically linked to the active trace + slog.InfoContext(ctx, "Processing request") + + w.Write([]byte("OK")) +} +``` + +## Best Practices + +- **Use context-aware methods**: Always use `InfoContext`, `ErrorContext`, etc. instead of `Info`, `Error` +- **Log within transactions**: Ensure logs are created while a transaction or span is active + +## Related Documentation + +- Logs - Comprehensive logging setup +- Custom Instrumentation - Manual tracing setup +- [Slog Integration Guide](/platforms/go/guides/slog/) - Full Slog integration details diff --git a/docs/platforms/go/guides/zerolog/index.mdx b/docs/platforms/go/guides/zerolog/index.mdx index 4966c02d43a80..b9543e6bf140f 100644 --- a/docs/platforms/go/guides/zerolog/index.mdx +++ b/docs/platforms/go/guides/zerolog/index.mdx @@ -1,8 +1,19 @@ --- title: Zerolog -description: "Zerolog is a fast and efficient logging library for Go, designed for structured logging. This guide demonstrates how to integrate Zerolog with Sentry." +description: "Learn how to capture errors and events from Zerolog and send them to Sentry." --- + + +The zerolog integration sends error events to Sentry but does not support Structured Logs due to architectural limitations: +- The `io.Writer` interface lacks access to `context.Context`, preventing proper per-request hub isolation +- In concurrent applications, breadcrumbs from different requests may leak into each other's events +- Related issues: [#1178](https://github.com/getsentry/sentry-go/issues/1178), [#1029](https://github.com/getsentry/sentry-go/issues/1029) + +For Structured Logs, use our Sentry.Logger or any of the supported integrations instead. + + + For a complete example, visit the [Go SDK source code repository](https://github.com/getsentry/sentry-go/tree/master/_examples/zerolog). [Go Dev-style API documentation](https://pkg.go.dev/github.com/getsentry/sentry-go/zerolog) is also available. @@ -29,8 +40,8 @@ The sentryzerolog.Options struct has the following fields: ```go // Levels specifies the log levels that will trigger event sending to Sentry. -// Only log messages at these levels will be sent. By default, the levels are -// Error, Fatal, and Panic. +// Only log messages at these levels will be sent as error events. By default, +// the levels are Error, Fatal, and Panic. Levels []zerolog.Level // WithBreadcrumbs, when enabled, adds log entries as breadcrumbs in Sentry. @@ -40,8 +51,7 @@ WithBreadcrumbs bool // FlushTimeout sets the maximum duration allowed for flushing events to Sentry. // This is the time limit within which all pending events must be sent to Sentry -// before the application exits. A typical use is ensuring all logs are sent before -// application shutdown. The default timeout is usually 3 seconds. +// before the application exits. The default timeout is usually 3 seconds. FlushTimeout time.Duration ``` @@ -67,16 +77,16 @@ defer sentryWriter.Close() // Use Sentry writer in Zerolog log.Logger = log.Output(zerolog.MultiLevelWriter(zerolog.ConsoleWriter{Out: os.Stderr}, sentryWriter)) -// Test logging - this will be sent to Sentry as an event +// Test error reporting - this will be sent to Sentry as an error event log.Error().Msg("This error will be sent to Sentry!") -// Example of logging with error context +// Example of error reporting with error context log.Error().Err(errors.New("test error")).Msg("An error occurred") ``` ## Usage -To integrate Sentry with Zerolog, you need to set up a custom writer that sends logs to Sentry based on the configured levels. +To integrate Sentry with Zerolog, you need to set up a custom writer that sends error events to Sentry based on the configured levels. ```go import ( @@ -131,10 +141,10 @@ func main() { // Log an InfoLevel entry to STDERR (not sent to Sentry) log.Info().Msg("Application has started") - // Log an ErrorLevel entry to STDERR and Sentry + // Log an ErrorLevel entry to STDERR and send as error event to Sentry log.Error().Msg("oh no!") - // Log a FatalLevel entry to STDERR, send to Sentry, and terminate the application + // Log a FatalLevel entry to STDERR, send as error event to Sentry, and terminate the application log.Fatal().Err(errors.New("can't continue")).Msg("fatal error occurred") } ``` @@ -142,7 +152,7 @@ func main() { ### Using `hubProvider` for Scoped Sentry Hubs -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. +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. You can set a custom hubProvider function using the SetHubProvider method: @@ -153,9 +163,13 @@ sentryHook.SetHubProvider(func() *sentry.Hub { }) ``` -This ensures that logs from specific contexts or threads use the appropriate Sentry hub and scope. +This ensures that error events from specific contexts or threads use the appropriate Sentry hub and scope. -Use Zerolog as you normally would, and it will automatically send logs at or above the specified levels to Sentry. +Use Zerolog as you normally would, and it will automatically send error events at or above the specified levels to Sentry. Note: Ensure Sentry is flushed before the application exits to avoid losing any pending events. + +## Concurrent Applications + +For concurrent applications (HTTP/gRPC servers), see the [tracing documentation](/platforms/go/guides/zerolog/tracing/instrumentation/zerolog/) for best practices on linking error events to traces with proper hub management. diff --git a/docs/platforms/go/guides/zerolog/logs/index.mdx b/docs/platforms/go/guides/zerolog/logs/index.mdx new file mode 100644 index 0000000000000..efe891689c195 --- /dev/null +++ b/docs/platforms/go/guides/zerolog/logs/index.mdx @@ -0,0 +1,72 @@ +--- +title: Logs in Zerolog +sidebar_title: Logs +description: "Zerolog does not support Structured Logs. Use alternative integrations instead." +sidebar_order: 5600 +sidebar_section: features +--- + + + +The zerolog integration sends error events to Sentry but does not support Structured Logs due to architectural limitations: +- The `io.Writer` interface lacks access to `context.Context`, preventing proper per-request hub isolation +- In concurrent applications, breadcrumbs from different requests may leak into each other's events +- Related issues: [#1178](https://github.com/getsentry/sentry-go/issues/1178), [#1029](https://github.com/getsentry/sentry-go/issues/1029) + +For Structured Logs, use our Sentry.Logger or any of the supported integrations instead. + + + +## What Zerolog Integration Supports + +The zerolog integration **does** support sending **error events** to Sentry: + +```go +import ( + "errors" + "time" + "os" + + "github.com/getsentry/sentry-go" + sentryzerolog "github.com/getsentry/sentry-go/zerolog" + "github.com/rs/zerolog" + "github.com/rs/zerolog/log" +) + +func main() { + // Initialize Sentry + err := sentry.Init(sentry.ClientOptions{ + Dsn: "___PUBLIC_DSN___", + // Note: EnableLogs is for Structured Logs, not zerolog error events + }) + if err != nil { + log.Fatal().Err(err).Msg("sentry initialization failed") + } + defer sentry.Flush(2 * time.Second) + + // Configure Zerolog to send error events to Sentry + sentryWriter, err := sentryzerolog.New(sentryzerolog.Config{ + Options: sentryzerolog.Options{ + // These levels will be sent as error events + Levels: []zerolog.Level{zerolog.ErrorLevel, zerolog.FatalLevel, zerolog.PanicLevel}, + // Disable breadcrumbs in concurrent applications to prevent leakage + WithBreadcrumbs: false, + FlushTimeout: 3 * time.Second, + }, + }) + if err != nil { + log.Fatal().Err(err).Msg("failed to create sentry writer") + } + defer sentryWriter.Close() + + // Use Sentry writer in Zerolog + log.Logger = log.Output(zerolog.MultiLevelWriter(zerolog.ConsoleWriter{Out: os.Stderr}, sentryWriter)) + + // This will be sent as an error event to Sentry + log.Error().Msg("This is an error event, not a structured log") +} +``` + +## Linking Error Events to Traces + +If you need to link zerolog error events to traces in concurrent applications, see the [tracing instrumentation documentation](/platforms/go/guides/zerolog/tracing/instrumentation/zerolog/). diff --git a/docs/platforms/go/guides/zerolog/tracing/instrumentation/zerolog.mdx b/docs/platforms/go/guides/zerolog/tracing/instrumentation/zerolog.mdx new file mode 100644 index 0000000000000..fc1d44664e531 --- /dev/null +++ b/docs/platforms/go/guides/zerolog/tracing/instrumentation/zerolog.mdx @@ -0,0 +1,127 @@ +--- +title: Linking Zerolog Error Events to Traces +sidebar_order: 202 +sdk: sentry.go.zerolog +description: "Learn how to link Zerolog error events with distributed traces in concurrent applications." +--- + + + +The zerolog integration sends error events to Sentry but does not support Structured Logs due to architectural limitations: +- The `io.Writer` interface lacks access to `context.Context`, preventing proper per-request hub isolation +- In concurrent applications, breadcrumbs from different requests may leak into each other's events +- Related issues: [#1178](https://github.com/getsentry/sentry-go/issues/1178), [#1029](https://github.com/getsentry/sentry-go/issues/1029) + +However, you can link error events to traces with manual hub management. + + + +## Linking Error Events to Traces + +The zerolog integration sends error events (not structured logs) to Sentry. To properly link these error events to traces in concurrent applications, you need to create a per-request writer with the hub from context: + +### Example + +```go +package main + +import ( + "fmt" + "net/http" + "os" + "time" + + "github.com/getsentry/sentry-go" + sentryzerolog "github.com/getsentry/sentry-go/zerolog" + "github.com/rs/zerolog" + "github.com/rs/zerolog/log" +) + +func main() { + // Initialize Sentry with tracing enabled + if err := sentry.Init(sentry.ClientOptions{ + Dsn: "___PUBLIC_DSN___", + EnableTracing: true, + TracesSampleRate: 1.0, + }); err != nil { + panic(err) + } + defer sentry.Flush(2 * time.Second) + + baseSentryWriter, err := sentryzerolog.New(sentryzerolog.Config{ + Options: sentryzerolog.Options{ + Levels: []zerolog.Level{ + zerolog.ErrorLevel, + zerolog.FatalLevel, + zerolog.PanicLevel, + }, + FlushTimeout: 3 * time.Second, + }, + }) + if err != nil { + panic(err) + } + defer baseSentryWriter.Close() + + // Global logger for non-request contexts + log.Logger = log.Output(zerolog.MultiLevelWriter( + zerolog.ConsoleWriter{Out: os.Stderr}, + baseSentryWriter, + )) + + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + ctx := r.Context() + + // Start a transaction + transaction := sentry.StartTransaction(ctx, + fmt.Sprintf("%s %s", r.Method, r.URL.Path), + sentry.WithOpName("http.server"), + ) + defer transaction.Finish() + ctx = transaction.Context() + + // Get hub from context for this request + hub := sentry.GetHubFromContext(ctx) + + // Create request-scoped writer with the hub from context + requestWriter := baseSentryWriter.WithHub(hub) + + // Create request-scoped logger + requestLogger := zerolog.New(zerolog.MultiLevelWriter( + zerolog.ConsoleWriter{Out: os.Stderr}, + requestWriter, + )).With().Timestamp().Logger() + + // Info logs are written to console but not sent to Sentry + requestLogger.Info(). + Str("method", r.Method). + Str("path", r.URL.Path). + Msg("Request received") + + // Simulate an error - this will be sent to Sentry as an error event + // linked to this request's trace + requestLogger.Error(). + Str("trace_id", transaction.TraceID.String()). + Str("span_id", transaction.SpanID.String()). + Msg("Example error event linked to trace") + + w.Write([]byte("OK")) + }) + + fmt.Println("Listening on :3000") + http.ListenAndServe(":3000", nil) +} +``` + +## Best Practices + +1. **Disable `WithBreadcrumbs` in concurrent applications** - To avoid breadcrumb leakage across requests +2. **Create per-request loggers** - Use `WithHub()` to create request-scoped writers that properly link error events to traces +3. **Add explicit trace context** - Include `trace_id` and `span_id` in error event fields for easier debugging +4. **Use structured fields** - Add relevant context fields to error events + +## Related Documentation + +- Custom Instrumentation - Manual tracing setup +- [Zerolog Integration Guide](/platforms/go/guides/zerolog/) - Full Zerolog integration details +- [Structured Logs](/platforms/go/common/logs/) - Structured Logs with sentry.Logger diff --git a/platform-includes/tracing/automatic-instrumentation/http-frameworks/go.mdx b/platform-includes/tracing/automatic-instrumentation/http-frameworks/go.mdx new file mode 100644 index 0000000000000..986b0aa3fda80 --- /dev/null +++ b/platform-includes/tracing/automatic-instrumentation/http-frameworks/go.mdx @@ -0,0 +1,8 @@ +The Sentry middleware for this framework **automatically creates transactions** for all incoming HTTP requests when tracing is enabled. Each transaction includes: + +- **Transaction name**: HTTP method and route path (e.g., `GET /users/:id`) +- **HTTP status code**: Captured when the response is sent +- **Distributed tracing**: Continues traces from upstream services via Sentry trace headers +- **Request context**: Hub attached for additional error capture and custom spans + +You can add custom child spans within your handlers to track specific operations.