From dd36d3bbce684104ca95338e6963f73c732c25c1 Mon Sep 17 00:00:00 2001 From: Giannis Gkiortzis <58184179+giortzisg@users.noreply.github.com> Date: Fri, 17 Apr 2026 10:47:41 +0200 Subject: [PATCH 1/2] docs(go): Update Echo guide for v5 and TracesSampler SamplingContext Echo v5 changed handler signatures from echo.Context to *echo.Context (pointer). Update all code examples in the Echo guide accordingly. TracesSampler gained two new SamplingContext fields: - ParentSampled: covers both local and remote parent sampling decisions, replacing the previous pattern of checking ctx.Parent != nil. - ParentSampleRate: the sample rate from the parent's Dynamic Sampling Context. Update the default-sampling-context-platform and always-inherit-sampling-decision includes to reflect these additions. Co-Authored-By: Claude --- docs/platforms/go/guides/echo/index.mdx | 12 ++++++------ .../always-inherit-sampling-decision/go.mdx | 9 ++++++--- .../default-sampling-context-platform/go.mdx | 9 ++++++++- 3 files changed, 20 insertions(+), 10 deletions(-) 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..1ec91aaea7daa4 100644 --- a/platform-includes/performance/always-inherit-sampling-decision/go.mdx +++ b/platform-includes/performance/always-inherit-sampling-decision/go.mdx @@ -2,9 +2,12 @@ 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 parent (works for both local and remote parents). + if ctx.ParentSampled != sentry.SampledUndefined { + if ctx.ParentSampled == sentry.SampledTrue { + return 1.0 + } + return 0.0 } // Or continue with a custom decision... }), 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 } ``` From bb914c288a4b17d7887dfa315326533204507bdc Mon Sep 17 00:00:00 2001 From: Giannis Gkiortzis <58184179+giortzisg@users.noreply.github.com> Date: Fri, 17 Apr 2026 10:50:11 +0200 Subject: [PATCH 2/2] docs(go): Explicitly check both local and remote parent in TracesSampler example The previous example only used ctx.ParentSampled, which reads as remote-only. Show the two cases separately: ctx.Parent for local spans (same process) and ctx.ParentSampled for remote spans (upstream service). Co-Authored-By: Claude --- .../always-inherit-sampling-decision/go.mdx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/platform-includes/performance/always-inherit-sampling-decision/go.mdx b/platform-includes/performance/always-inherit-sampling-decision/go.mdx index 1ec91aaea7daa4..cec8ef2c8af052 100644 --- a/platform-includes/performance/always-inherit-sampling-decision/go.mdx +++ b/platform-includes/performance/always-inherit-sampling-decision/go.mdx @@ -2,14 +2,22 @@ err := sentry.Init(sentry.ClientOptions{ // ... TracesSampler: sentry.TracesSampler(func(ctx sentry.SamplingContext) float64 { - // Inherit decision from parent (works for both local and remote parents). + // 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 + } + // 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 } - // Or continue with a custom decision... + // No parent — apply a default sample rate. + return 0.1 }), }) ```