mirror of
https://github.com/rjNemo/rentease.git
synced 2026-06-06 02:36:49 +00:00
basic tracing middleware
This commit is contained in:
parent
08739d10ba
commit
bc2c7a7583
3 changed files with 36 additions and 22 deletions
|
|
@ -7,7 +7,6 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/a-h/templ"
|
||||
"github.com/getsentry/sentry-go"
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/labstack/gommon/log"
|
||||
u "github.com/rjNemo/underscore"
|
||||
|
|
@ -21,27 +20,6 @@ import (
|
|||
|
||||
func handleListBookingPage(bs *booking.Service, hc *config.Host) echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
ctx := c.Request().Context()
|
||||
hub := sentry.GetHubFromContext(ctx)
|
||||
if hub == nil {
|
||||
// Check the concurrency guide for more details: https://docs.sentry.io/platforms/go/concurrency/
|
||||
hub = sentry.CurrentHub().Clone()
|
||||
ctx = sentry.SetHubOnContext(ctx, hub)
|
||||
}
|
||||
|
||||
options := []sentry.SpanOption{
|
||||
// Set the OP based on values from https://develop.sentry.dev/sdk/performance/span-operations/
|
||||
sentry.WithOpName("http.server"),
|
||||
sentry.ContinueFromRequest(c.Request()),
|
||||
sentry.WithTransactionSource(sentry.SourceURL),
|
||||
}
|
||||
|
||||
transaction := sentry.StartTransaction(ctx,
|
||||
fmt.Sprintf("%s %s", c.Request().Method, c.Request().URL.Path),
|
||||
options...,
|
||||
)
|
||||
defer transaction.Finish()
|
||||
|
||||
bookings := bs.All()
|
||||
|
||||
bvm := u.Map(bookings, func(b *booking.Line) *view.ListBookingsViewModel {
|
||||
|
|
|
|||
|
|
@ -125,6 +125,7 @@ func NewRouter(fs embed.FS) *echo.Echo {
|
|||
e.Use(middleware.Secure())
|
||||
e.Use(middleware.Gzip())
|
||||
e.Use(sentryecho.New(sentryecho.Options{}))
|
||||
e.Use(SentryTracingMiddleware)
|
||||
// static assets
|
||||
e.StaticFS("/static", echo.MustSubFS(fs, "assets"))
|
||||
|
||||
|
|
|
|||
35
internal/server/tracing.go
Normal file
35
internal/server/tracing.go
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/getsentry/sentry-go"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
func SentryTracingMiddleware(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
ctx := c.Request().Context()
|
||||
hub := sentry.GetHubFromContext(ctx)
|
||||
if hub == nil {
|
||||
// Check the concurrency guide for more details: https://docs.sentry.io/platforms/go/concurrency/
|
||||
hub = sentry.CurrentHub().Clone()
|
||||
ctx = sentry.SetHubOnContext(ctx, hub)
|
||||
}
|
||||
|
||||
options := []sentry.SpanOption{
|
||||
// Set the OP based on values from https://develop.sentry.dev/sdk/performance/span-operations/
|
||||
sentry.WithOpName("http.server"),
|
||||
sentry.ContinueFromRequest(c.Request()),
|
||||
sentry.WithTransactionSource(sentry.SourceURL),
|
||||
}
|
||||
|
||||
transaction := sentry.StartTransaction(ctx,
|
||||
fmt.Sprintf("%s %s", c.Request().Method, c.Request().URL.Path),
|
||||
options...,
|
||||
)
|
||||
|
||||
defer transaction.Finish()
|
||||
return next(c)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue