in graphql-dgs-spring-boot-micrometer/src/main/kotlin/com/netflix/graphql/dgs/metrics/micrometer/DgsGraphQLMetricsInstrumentation.kt [93:143]
override fun instrumentExecutionResult(
executionResult: ExecutionResult,
parameters: InstrumentationExecutionParameters,
state: InstrumentationState,
): CompletableFuture<ExecutionResult> {
require(state is MetricsInstrumentationState)
// if this is an error due to PersistedQueryNotFound, we exclude from the gql.error metric
// this is captured in a separate counter instead
val persistedQueryNotFoundErrors = executionResult.errors.filter { it.errorType is PersistedQueryNotFound }
if (persistedQueryNotFoundErrors.isNotEmpty()) {
val registry = registrySupplier.get()
persistedQueryNotFoundErrors.forEach {
val errorTags =
buildList {
add(Tag.of(GqlTag.PERSISTED_QUERY_ID.key, it.extensions["persistedQueryId"].toString()))
}
registry
.counter(GqlMetric.PERSISTED_QUERY_NOT_FOUND.key, errorTags)
.increment()
}
return CompletableFuture.completedFuture(executionResult)
}
val errorTagValues = ErrorUtils.sanitizeErrorPaths(executionResult.errors)
if (errorTagValues.isNotEmpty()) {
val baseTags =
buildList {
addAll(tagsProvider.getContextualTags())
addAll(tagsProvider.getExecutionTags(state, parameters, executionResult, null))
addAll(state.tags())
}
val registry = registrySupplier.get()
for (errorTagValue in errorTagValues) {
val errorTags =
buildList(baseTags.size + 3) {
addAll(baseTags)
add(Tag.of(GqlTag.PATH.key, errorTagValue.path))
add(Tag.of(GqlTag.ERROR_CODE.key, errorTagValue.type))
add(Tag.of(GqlTag.ERROR_DETAIL.key, errorTagValue.detail))
}
registry
.counter(GqlMetric.ERROR.key, errorTags)
.increment()
}
}
return CompletableFuture.completedFuture(executionResult)
}