@@ -36,6 +36,11 @@ type MetricsService interface {
3636 ObserveDBTransactionDuration (status string , duration float64 )
3737 ObserveDBBatchSize (operation , table string , size int )
3838 IncSignatureVerificationExpired (expiredSeconds float64 )
39+ // GraphQL Metrics
40+ ObserveGraphQLFieldDuration (operationName , fieldName string , duration float64 )
41+ IncGraphQLField (operationName , fieldName string , success bool )
42+ ObserveGraphQLComplexity (operationName string , complexity int )
43+ IncGraphQLError (operationName , errorType string )
3944}
4045
4146// MetricsService handles all metrics for the wallet-backend
@@ -77,6 +82,12 @@ type metricsService struct {
7782
7883 // Signature Verification Metrics
7984 signatureVerificationExpired * prometheus.CounterVec
85+
86+ // GraphQL Metrics
87+ graphqlFieldDuration * prometheus.SummaryVec
88+ graphqlFieldsTotal * prometheus.CounterVec
89+ graphqlComplexity * prometheus.SummaryVec
90+ graphqlErrorsTotal * prometheus.CounterVec
8091}
8192
8293// NewMetricsService creates a new metrics service with all metrics registered
@@ -250,6 +261,38 @@ func NewMetricsService(db *sqlx.DB) MetricsService {
250261 []string {"expired_seconds" },
251262 )
252263
264+ // GraphQL Metrics
265+ m .graphqlFieldDuration = prometheus .NewSummaryVec (
266+ prometheus.SummaryOpts {
267+ Name : "graphql_field_duration_seconds" ,
268+ Help : "Duration of GraphQL field resolver execution" ,
269+ Objectives : map [float64 ]float64 {0.5 : 0.05 , 0.9 : 0.01 , 0.99 : 0.001 },
270+ },
271+ []string {"operation_name" , "field_name" },
272+ )
273+ m .graphqlFieldsTotal = prometheus .NewCounterVec (
274+ prometheus.CounterOpts {
275+ Name : "graphql_fields_total" ,
276+ Help : "Total number of GraphQL field resolutions" ,
277+ },
278+ []string {"operation_name" , "field_name" , "success" },
279+ )
280+ m .graphqlComplexity = prometheus .NewSummaryVec (
281+ prometheus.SummaryOpts {
282+ Name : "graphql_complexity" ,
283+ Help : "GraphQL query complexity values" ,
284+ Objectives : map [float64 ]float64 {0.5 : 0.05 , 0.9 : 0.01 , 0.99 : 0.001 },
285+ },
286+ []string {"operation_name" },
287+ )
288+ m .graphqlErrorsTotal = prometheus .NewCounterVec (
289+ prometheus.CounterOpts {
290+ Name : "graphql_errors_total" ,
291+ Help : "Total number of GraphQL errors" ,
292+ },
293+ []string {"operation_name" , "error_type" },
294+ )
295+
253296 m .registerMetrics ()
254297 return m
255298}
@@ -279,6 +322,10 @@ func (m *metricsService) registerMetrics() {
279322 m .dbTxnDuration ,
280323 m .dbBatchSize ,
281324 m .signatureVerificationExpired ,
325+ m .graphqlFieldDuration ,
326+ m .graphqlFieldsTotal ,
327+ m .graphqlComplexity ,
328+ m .graphqlErrorsTotal ,
282329 )
283330}
284331
@@ -466,3 +513,24 @@ func (m *metricsService) ObserveDBBatchSize(operation, table string, size int) {
466513func (m * metricsService ) IncSignatureVerificationExpired (expiredSeconds float64 ) {
467514 m .signatureVerificationExpired .WithLabelValues (fmt .Sprintf ("%fs" , expiredSeconds )).Inc ()
468515}
516+
517+ // GraphQL Metrics
518+ func (m * metricsService ) ObserveGraphQLFieldDuration (operationName , fieldName string , duration float64 ) {
519+ m .graphqlFieldDuration .WithLabelValues (operationName , fieldName ).Observe (duration )
520+ }
521+
522+ func (m * metricsService ) IncGraphQLField (operationName , fieldName string , success bool ) {
523+ successStr := "true"
524+ if ! success {
525+ successStr = "false"
526+ }
527+ m .graphqlFieldsTotal .WithLabelValues (operationName , fieldName , successStr ).Inc ()
528+ }
529+
530+ func (m * metricsService ) ObserveGraphQLComplexity (operationName string , complexity int ) {
531+ m .graphqlComplexity .WithLabelValues (operationName ).Observe (float64 (complexity ))
532+ }
533+
534+ func (m * metricsService ) IncGraphQLError (operationName , errorType string ) {
535+ m .graphqlErrorsTotal .WithLabelValues (operationName , errorType ).Inc ()
536+ }
0 commit comments