Skip to content

Commit

Permalink
Merge pull request #899 from k2io/develop
Browse files Browse the repository at this point in the history
Fix for correct struct field name for echo version v3.2.2+
  • Loading branch information
nr-swilloughby committed Apr 18, 2024
2 parents 2c742a8 + 8890896 commit 8403072
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion v3/integrations/nrecho-v3/nrecho.go
Expand Up @@ -35,6 +35,22 @@ func handlerPointer(handler echo.HandlerFunc) uintptr {
return reflect.ValueOf(handler).Pointer()
}

func handlerName(router interface{}) string {
val := reflect.ValueOf(router)
if val.Kind() == reflect.Ptr { // for echo version v3.2.2+
val = val.Elem()
} else {
val = reflect.ValueOf(&router).Elem().Elem()
}
if name := val.FieldByName("Name"); name.IsValid() { // for echo version v3.2.2+
return name.String()
} else if handler := val.FieldByName("Handler"); handler.IsValid() {
return handler.String()
} else {
return ""
}
}

func transactionName(c echo.Context) string {
ptr := handlerPointer(c.Handler())
if ptr == handlerPointer(echo.NotFoundHandler) {
Expand Down Expand Up @@ -108,7 +124,7 @@ func WrapRouter(engine *echo.Echo) {
if engine != nil && newrelic.IsSecurityAgentPresent() {
router := engine.Routes()
for _, r := range router {
newrelic.GetSecurityAgentInterface().SendEvent("API_END_POINTS", r.Path, r.Method, r.Handler)
newrelic.GetSecurityAgentInterface().SendEvent("API_END_POINTS", r.Path, r.Method, handlerName(r))
}
}
}

0 comments on commit 8403072

Please sign in to comment.