Skip to content

Commit

Permalink
Adding more tags for panic metric
Browse files Browse the repository at this point in the history
  • Loading branch information
anirudhraja committed Feb 28, 2024
1 parent 923df99 commit 41836d7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
10 changes: 8 additions & 2 deletions runtime/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,14 @@ func (router *httpRouter) handlePanic(
}
logger := router.gateway.ContextLogger
logger.Error(r.Context(), "A http request handler paniced", zap.Error(err), zap.Int(logFieldResponseStatusCode, http.StatusInternalServerError))
router.panicCount.Inc(1)

m := router.gateway.ContextExtractor.ExtractScopeTags(r.Context())
endpointId := m[scopeTagEndpoint]
handlerId := m[scopeTagHandler]
scopeTags := map[string]string{
scopeTagEndpoint: endpointId,
scopeTagHandler: handlerId,
}
router.gateway.RootScope.Tagged(scopeTags).Counter("runtime.router.panic")
http.Error(w,
http.StatusText(http.StatusInternalServerError),
http.StatusInternalServerError,
Expand Down
5 changes: 5 additions & 0 deletions runtime/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ func (s *routerSuite) SetupTest() {
},
)
s.router = NewHTTPRouter(s.gw).(*httpRouter)
extractors = &ContextExtractors{
ScopeTagsExtractors: []ContextScopeTagsExtractor{scopeExtractor},
LogFieldsExtractors: []ContextLogFieldsExtractor{logFieldsExtractors},
}
s.router.gateway.ContextExtractor = extractors
}

func (s *routerSuite) TestRouter() {
Expand Down

0 comments on commit 41836d7

Please sign in to comment.