diff --git a/docs/platforms/go/guides/echo/index.mdx b/docs/platforms/go/guides/echo/index.mdx index 6f7e59d2710d1f..c25eeb67832796 100644 --- a/docs/platforms/go/guides/echo/index.mdx +++ b/docs/platforms/go/guides/echo/index.mdx @@ -1,6 +1,6 @@ --- title: Echo -description: "Echo is a high-performance web framework for building robust and scalable applications in Go. Learn how to set it up with Sentry." +description: "Echo is a high-performance web framework for building robust and scalable applications in Go. Learn how to set it up with Sentry. Requires Echo v5." --- For a quick reference, there is a [complete example](https://github.com/getsentry/sentry-go/tree/master/_examples/echo) at the Go SDK source code repository. @@ -63,7 +63,7 @@ app.Use(sentryecho.New(sentryecho.Options{ })) // Set up routes -app.GET("/", func(ctx echo.Context) error { +app.GET("/", func(ctx *echo.Context) error { // capturing an error intentionally to simulate usage sentry.CaptureMessage("It works!") @@ -75,7 +75,7 @@ app.Logger.Fatal(app.Start(":3000")) ## Usage -`sentryecho` attaches an instance of `*sentry.Hub` (https://pkg.go.dev/github.com/getsentry/sentry-go#Hub) to the `echo.Context`, which makes it available throughout the rest of the request's lifetime. +`sentryecho` attaches an instance of `*sentry.Hub` (https://pkg.go.dev/github.com/getsentry/sentry-go#Hub) to the `*echo.Context`, which makes it available throughout the rest of the request's lifetime. You can access it by using the `sentryecho.GetHubFromContext()` method on the context itself in any of your proceeding middleware and routes. And it should be used instead of the global `sentry.CaptureMessage`, `sentry.CaptureException` or any other calls, as it keeps the separation of data between the requests. @@ -94,7 +94,7 @@ app.Use(sentryecho.New(sentryecho.Options{ })) app.Use(func(next echo.HandlerFunc) echo.HandlerFunc { - return func(ctx echo.Context) error { + return func(ctx *echo.Context) error { if hub := sentryecho.GetHubFromContext(ctx); hub != nil { hub.Scope().SetTag("someRandomTag", "maybeYouNeedIt") } @@ -102,7 +102,7 @@ app.Use(func(next echo.HandlerFunc) echo.HandlerFunc { } }) -app.GET("/", func(ctx echo.Context) error { +app.GET("/", func(ctx *echo.Context) error { if hub := sentryecho.GetHubFromContext(ctx); hub != nil { hub.WithScope(func(scope *sentry.Scope) { scope.SetExtra("unwantedQuery", "someQueryDataMaybe") @@ -112,7 +112,7 @@ app.GET("/", func(ctx echo.Context) error { return ctx.String(http.StatusOK, "Hello, World!") }) -app.GET("/foo", func(ctx echo.Context) error { +app.GET("/foo", func(ctx *echo.Context) error { // sentryecho handler will catch it just fine. Also, because we attached "someRandomTag" // in the middleware before, it will be sent through as well panic("y tho") diff --git a/platform-includes/performance/always-inherit-sampling-decision/go.mdx b/platform-includes/performance/always-inherit-sampling-decision/go.mdx index e7ef272b04a533..cec8ef2c8af052 100644 --- a/platform-includes/performance/always-inherit-sampling-decision/go.mdx +++ b/platform-includes/performance/always-inherit-sampling-decision/go.mdx @@ -2,11 +2,22 @@ err := sentry.Init(sentry.ClientOptions{ // ... TracesSampler: sentry.TracesSampler(func(ctx sentry.SamplingContext) float64 { - // Inherit decision from parent. - if ctx.Parent != nil && ctx.Parent.Sampled != sentry.SampledUndefined { - return 1.0 + // Inherit decision from a local parent span (same process). + if ctx.Parent != nil { + if ctx.Parent.Sampled == sentry.SampledTrue { + return 1.0 + } + return 0.0 } - // Or continue with a custom decision... + // Inherit decision from a remote parent span (upstream service). + if ctx.ParentSampled != sentry.SampledUndefined { + if ctx.ParentSampled == sentry.SampledTrue { + return 1.0 + } + return 0.0 + } + // No parent — apply a default sample rate. + return 0.1 }), }) ``` diff --git a/platform-includes/performance/default-sampling-context-platform/go.mdx b/platform-includes/performance/default-sampling-context-platform/go.mdx index 2323badfaca36b..0eda51a5b2fb31 100644 --- a/platform-includes/performance/default-sampling-context-platform/go.mdx +++ b/platform-includes/performance/default-sampling-context-platform/go.mdx @@ -3,6 +3,13 @@ For the Go SDK, it is: ```go type SamplingContext struct { Span *Span // The current span, always non-nil. - Parent *Span // The parent span, may be nil. + Parent *Span // The local parent span, non-nil only when the parent exists in the same process. + // ParentSampled is the sampling decision of the parent span. + // + // For a remote span, Parent is nil but ParentSampled reflects the upstream decision. + // For a local span, ParentSampled mirrors Parent.Sampled. + ParentSampled Sampled + // ParentSampleRate is the sample rate used by the parent transaction, propagated via Dynamic Sampling Context. + ParentSampleRate *float64 } ```