Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions docs/platforms/go/guides/echo/index.mdx
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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!")

Expand All @@ -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.

Expand All @@ -94,15 +94,15 @@ 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")
}
return next(ctx)
}
})

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")
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}),
})
```
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
```
Loading