-
Notifications
You must be signed in to change notification settings - Fork 323
Open
Labels
status: waiting-for-triageAn issue we've not yet triagedAn issue we've not yet triaged
Description
There's 2 improvements i see:
- Currently metrics like: graphql_datafetcher_seconds_count group all _entities interactions under _entities. For applications which have several entityMappings defined you cant differentiate between which entity is being resolved.
- In applications which have multiple schema mappings for the same field but different objects, it currently all gets combined under the field name, which makes it impossible to separate which type this field was being called on.
I have done some testing and the following seems to solve both issues
@Configuration
class GraphQLObservationConfig {
@Bean
fun dataFetcherObservationConvention(): DataFetcherObservationConvention = object : DefaultDataFetcherObservationConvention() {
override fun fieldName(context: DataFetcherObservationContext): KeyValue {
val env = context.environment
val parent = (env.parentType as? GraphQLNamedType)?.name
val field = env.field.name
val enrichedField = if (field == "_entities") {
// Normally all _entities queries are processed as _entities but since we have so many different entities we want
// to know exactly which entities is being called
(env.getArgument<Any?>("representations") as? List<*>)
?.firstNotNullOfOrNull { rep -> (rep as? Map<*, *>)?.get("__typename") as? String }
?.let { "$field($it)" } ?: field
} else {
// Converts a field to a <parent>.<field> metric for cases where we want to differentiate between fields
// with the same name defined on different types, which would otherwise all be aggregated under the field name
parent?.let { "$it.$field" } ?: field
}
return KeyValue.of(DataFetcherLowCardinalityKeyNames.FIELD_NAME, enrichedField)
}
}
}
it changes
- e.g. the
graphql_field_name
for _entities queries to_entities(<entityName>)
- the
graphql_field_name
for fields to<parent>.<fieldName>
If this could be made part of Spring Graphql it'd be greatly appreciated!
Let me know if any clarifications are needed!
wleese and CodingContraption
Metadata
Metadata
Assignees
Labels
status: waiting-for-triageAn issue we've not yet triagedAn issue we've not yet triaged