Skip to content

Commit

Permalink
Add new relic segments for auth middleware.
Browse files Browse the repository at this point in the history
  • Loading branch information
robinjhuang committed Jan 19, 2025
1 parent 2e310d7 commit ff03fcf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions server/middleware/authentication/firebase_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"registry-backend/ent"
"strings"

"github.com/newrelic/go-agent/v3/newrelic"
"github.com/rs/zerolog/log"

firebase "firebase.google.com/go"
Expand Down Expand Up @@ -50,6 +51,10 @@ func FirebaseAuthMiddleware(entClient *ent.Client) echo.MiddlewareFunc {

return func(next echo.HandlerFunc) echo.HandlerFunc {
return func(ctx echo.Context) error {
if txn := newrelic.FromContext(ctx.Request().Context()); txn != nil {
segment := txn.StartSegment("FirebaseAuthMiddleware")
defer segment.End()
}
// Check if the request is in the allow list.
reqPath := ctx.Request().URL.Path
reqMethod := ctx.Request().Method
Expand Down
5 changes: 5 additions & 0 deletions server/middleware/authentication/jwt_admin_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/golang-jwt/jwt/v5"
"github.com/labstack/echo/v4"
"github.com/newrelic/go-agent/v3/newrelic"
)

// JWTAdminAuthMiddleware checks for a JWT token in the Authorization header,
Expand All @@ -33,6 +34,10 @@ func JWTAdminAuthMiddleware(entClient *ent.Client, secret string) echo.Middlewar

return func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
if txn := newrelic.FromContext(c.Request().Context()); txn != nil {
segment := txn.StartSegment("JWTAdminAuthMiddleware")
defer segment.End()
}
reqPath := c.Request().URL.Path

// Check if the request path matches any of the protected endpoints
Expand Down
5 changes: 5 additions & 0 deletions server/middleware/authentication/service_account_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"

"github.com/labstack/echo/v4"
"github.com/newrelic/go-agent/v3/newrelic"
"github.com/rs/zerolog/log"
"google.golang.org/api/idtoken"
)
Expand All @@ -22,6 +23,10 @@ func ServiceAccountAuthMiddleware() echo.MiddlewareFunc {

return func(next echo.HandlerFunc) echo.HandlerFunc {
return func(ctx echo.Context) error {
if txn := newrelic.FromContext(ctx.Request().Context()); txn != nil {
segment := txn.StartSegment("ServiceAccountAuthMiddleware")
defer segment.End()
}
// Check if the request reqPath and method are in the checklist
reqPath := ctx.Request().URL.Path
reqMethod := ctx.Request().Method
Expand Down

0 comments on commit ff03fcf

Please sign in to comment.