Skip to content

Commit

Permalink
feat: custom metric attributes (#1267)
Browse files Browse the repository at this point in the history
  • Loading branch information
StarpTech authored Oct 17, 2024
1 parent 67e8166 commit f6a4224
Show file tree
Hide file tree
Showing 35 changed files with 1,869 additions and 660 deletions.
50 changes: 24 additions & 26 deletions graphqlmetrics/pkg/telemetry/interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,36 +50,34 @@ func checkIfClaimsAreSet(claims *utils.GraphAPITokenClaims) bool {
}

func (c *Config) ObservabilityInterceptor() connect.UnaryInterceptorFunc {
return connect.UnaryInterceptorFunc(
func(next connect.UnaryFunc) connect.UnaryFunc {
return connect.UnaryFunc(func(ctx context.Context, req connect.AnyRequest) (connect.AnyResponse, error) {
attributes := defaultAttributes(req)
// connect.CodeOK does not exist
var statusCode int = 0
return func(next connect.UnaryFunc) connect.UnaryFunc {
return func(ctx context.Context, req connect.AnyRequest) (connect.AnyResponse, error) {
attributes := defaultAttributes(req)
// connect.CodeOK does not exist
var statusCode int = 0

claims, err := utils.GetClaims(ctx)
if err != nil || checkIfClaimsAreSet(claims) {
// handling this error will happen in the service itself
statusCode = int(connect.CodeInvalidArgument)
claims, err := utils.GetClaims(ctx)
if err != nil || checkIfClaimsAreSet(claims) {
// handling this error will happen in the service itself
statusCode = int(connect.CodeInvalidArgument)

attributes = append(attributes, WgFederatedGraphId.String(claims.FederatedGraphID))
attributes = append(attributes, WgOrganizationId.String(claims.OrganizationID))
} else {
attributes = append(attributes, WgFederatedGraphId.String(claims.FederatedGraphID))
attributes = append(attributes, WgOrganizationId.String(claims.OrganizationID))
}
attributes = append(attributes, WgFederatedGraphId.String(claims.FederatedGraphID))
attributes = append(attributes, WgOrganizationId.String(claims.OrganizationID))
} else {
attributes = append(attributes, WgFederatedGraphId.String(claims.FederatedGraphID))
attributes = append(attributes, WgOrganizationId.String(claims.OrganizationID))
}

res, err := next(ctx, req)
res, err := next(ctx, req)

if err != nil {
statusCode = int(connect.CodeOf(err))
}
if err != nil {
statusCode = int(connect.CodeOf(err))
}

attributes = append(attributes, semconv.RPCGRPCStatusCodeKey.Int(statusCode))
c.MetricStore.MeasureRequestCount(ctx, attributes...)
attributes = append(attributes, semconv.RPCGRPCStatusCodeKey.Int(statusCode))
c.MetricStore.MeasureRequestCount(ctx, attributes...)

return res, err
})
},
)
return res, err
}
}
}
4 changes: 2 additions & 2 deletions router-tests/kafka_events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func TestKafkaEvents(t *testing.T) {

go func() {
wg.Wait()
require.NoError(t, client.Close())
_ = client.Close()
}()

xEnv.WaitForSubscriptionCount(1, time.Second*10)
Expand Down Expand Up @@ -413,7 +413,7 @@ func TestKafkaEvents(t *testing.T) {

go func() {
wg.Wait()
require.NoError(t, client.Close())
_ = client.Close()
}()

xEnv.WaitForSubscriptionCount(1, time.Second*10)
Expand Down
Loading

0 comments on commit f6a4224

Please sign in to comment.