Skip to content

Commit

Permalink
Add tagged metrics for Thrift app errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Greenleaf committed Jan 12, 2019
1 parent 1c5c6cf commit 15d78c5
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 13 deletions.
22 changes: 15 additions & 7 deletions codegen/template_bundle/template_files.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 14 additions & 6 deletions codegen/templates/tchannel_endpoint.tmpl
Expand Up @@ -67,7 +67,7 @@ func New{{$handlerName}}(deps *module.Dependencies) *{{$handlerName}} {

// {{$handlerName}} is the handler for "{{.ThriftService}}::{{.Name}}".
type {{$handlerName}} struct {
Deps *module.Dependencies
Deps *module.Dependencies
endpoint *zanzibar.TChannelEndpoint
}

Expand Down Expand Up @@ -161,6 +161,10 @@ func (h *{{$handlerName}}) Handle(
{{$method := .Name -}}
{{range .Exceptions -}}
case *{{.Type}}:
ctxWithError := zanzibar.WithScopeTags(ctx, map[string]string{
"app-error": "{{.Type}}",
})
h.Deps.Default.ContextMetrics.IncCounter(ctxWithError, zanzibar.MetricEndpointAppErrors, 1)
if v == nil {
h.Deps.Default.ContextLogger.Error(
ctx,
Expand All @@ -175,6 +179,10 @@ func (h *{{$handlerName}}) Handle(
res.{{title .Name}} = v
{{end -}}
default:
ctxWithError := zanzibar.WithScopeTags(ctx, map[string]string{
"app-error": "unknown",
})
h.Deps.Default.ContextMetrics.IncCounter(ctxWithError, zanzibar.MetricEndpointAppErrors, 1)
h.Deps.Default.ContextLogger.Error(ctx, "Endpoint failure: handler returned error", zap.Error(err))
return false, nil, resHeaders, errors.Wrapf(
err, "%s.%s (%s) handler returned error",
Expand Down Expand Up @@ -243,12 +251,12 @@ func (h *{{$handlerName}}) redirectToDeputy(
h.Deps.Default.Logger,
h.Deps.Default.ContextMetrics,
&zanzibar.TChannelClientOption{
ServiceName: serviceName,
ClientID: "{{$clientID}}",
MethodNames: methodNames,
Timeout: timeout,
ServiceName: serviceName,
ClientID: "{{$clientID}}",
MethodNames: methodNames,
Timeout: timeout,
TimeoutPerAttempt: timeoutPerAttempt,
RoutingKey: &routingKey,
RoutingKey: &routingKey,
},
)

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions runtime/constants.go
Expand Up @@ -34,6 +34,9 @@ const (
// MetricEndpointPanics is endpoint level panic counter
MetricEndpointPanics = "endpoint.panic"

// MetricEndpointAppErrors is endpoint level panic counter
MetricEndpointAppErrors = "endpoint.app-errors-err"

clientRequest = "client.request"
clientSuccess = "client.success"
clientStatus = "client.status"
Expand Down

0 comments on commit 15d78c5

Please sign in to comment.