Skip to content

Commit 4726223

Browse files
Add per-operation GraphQL metrics
Record more granular GraphQL metrics: introduce a status variable and keep the aggregate counter/timer while adding dedicated per-operation counters and timers. Adds labels for operation name, type and status on the total counter, a per-operation count metric (graphql.operation.{type}.{name}.{status}.count), and a per-operation timer (graphql.operation.{type}.{name}.duration). This improves observability and enables per-operation histograms via Micrometer timers.
1 parent 1abad47 commit 4726223

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

src/main/java/com/espacogeek/geek/metrics/GraphQLExecutionInstrumentation.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,33 @@ public void recordOperation(String operationName, String operationType, long dur
2424
// Garantir que operationName não seja nulo
2525
String name = operationName != null && !operationName.isEmpty() ? operationName : "anonymous";
2626
String type = operationType != null ? operationType.toLowerCase() : "unknown";
27+
String status = success ? "success" : "error";
2728

28-
// Métrica: Total de operações
29+
// Contador total (com labels)
2930
meterRegistry.counter(
3031
"graphql.operations.total",
3132
"operation", name,
3233
"type", type,
33-
"status", success ? "success" : "error"
34+
"status", status
3435
).increment();
3536

36-
// Métrica: Duração
37+
// Contador dedicado para cada operação (nome + tipo + status)
38+
meterRegistry.counter(
39+
String.format("graphql.operation.%s.%s.%s.count", type, name, status)
40+
).increment();
41+
42+
// Timer/histograma para cada operação (Micrometer Timer já suporta histogramas)
3743
meterRegistry.timer(
3844
"graphql.operations.duration",
3945
"operation", name,
4046
"type", type
4147
).record(durationMs, java.util.concurrent.TimeUnit.MILLISECONDS);
4248

49+
// Timer/histograma dedicado para cada operação
50+
meterRegistry.timer(
51+
String.format("graphql.operation.%s.%s.duration", type, name)
52+
).record(durationMs, java.util.concurrent.TimeUnit.MILLISECONDS);
53+
4354
log.debug("GraphQL Metrics recorded - Op: {}, Type: {}, Duration: {}ms, Success: {}",
4455
name, type, durationMs, success);
4556
} catch (Exception e) {

0 commit comments

Comments
 (0)