-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(performance): start transaction for echo middleware/integration (#…
…722) * feat(performance): start transaction for echo middleware/integration * test(performance): GetTransactionFromContext test for sentryecho middleware * chore(echo): rename GetTransactionFromContext to GetSpanFromContext * chore(echo): move examples to _examples directory * handle 404 errors * add TestGetTransactionFromContext * Update CHANGELOG.md --------- Co-authored-by: Emir Ribić <e@ribic.ba> Co-authored-by: Ivan Dlugos <6349682+vaind@users.noreply.github.com>
- Loading branch information
1 parent
3c523e2
commit 5942155
Showing
5 changed files
with
327 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package sentryecho_test | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
|
||
"github.com/getsentry/sentry-go" | ||
sentryecho "github.com/getsentry/sentry-go/echo" | ||
"github.com/labstack/echo/v4" | ||
) | ||
|
||
func ExampleGetSpanFromContext() { | ||
router := echo.New() | ||
router.Use(sentryecho.New(sentryecho.Options{})) | ||
router.GET("/", func(c echo.Context) error { | ||
expensiveThing := func(ctx context.Context) error { | ||
span := sentry.StartTransaction(ctx, "expensive_thing") | ||
defer span.Finish() | ||
// do resource intensive thing | ||
return nil | ||
} | ||
|
||
// Acquire transaction on current hub that's created by the SDK. | ||
// Be careful, it might be a nil value if you didn't set up sentryecho middleware. | ||
sentrySpan := sentryecho.GetSpanFromContext(c) | ||
// Pass in the `.Context()` method from `*sentry.Span` struct. | ||
// The `context.Context` instance inherits the context from `echo.Context`. | ||
err := expensiveThing(sentrySpan.Context()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return c.NoContent(http.StatusOK) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.