Micrometer 的可观测性支持直接在 Spring for GraphQL 中检测。 这为 GraphQL 请求和“非平凡”数据获取操作提供了指标和跟踪。 由于 GraphQL 引擎在传输层之上运行,因此如果 Spring Framework 支持传输,您还应该期待来自传输的观察结果。Spring中文文档

仅当在应用程序中配置了 时,才会发布观察结果。 您可以了解有关在 Spring Boot 中配置可观测性基础结构的更多信息。 如果要自定义使用 GraphQL 观测值生成的元数据,可以直接在检测上配置自定义约定。 如果您的应用程序使用的是 Spring Boot,那么将自定义约定作为 Bean 贡献是首选方式。ObservationRegistrySpring中文文档

服务器请求检测

GraphQL 服务器请求观察结果是使用传统和反应式应用程序的名称创建的,尤其是所有支持的传输。 此检测假定必须将任何父观测值设置为具有已知键的 GraphQL 上下文中的当前观测值。 对于跨网络边界的跟踪传播,必须由传输级别的单独检测负责。 在HTTP的情况下,Spring Framework具有专门的检测来处理跟踪传播"graphql.request""micrometer.observation"Spring中文文档

应用程序需要在其应用程序中配置检测。 默认情况下,它使用 .org.springframework.graphql.observation.GraphQlObservationInstrumentationorg.springframework.graphql.observation.DefaultExecutionRequestObservationConventionExecutionRequestObservationContextSpring中文文档

默认情况下,将创建以下 KeyValues:Spring中文文档

表 1.低基数键

graphql.operation (必填)Spring中文文档

GraphQL 操作名称。Spring中文文档

graphql.outcome (必填)Spring中文文档

GraphQL 请求的结果。Spring中文文档

KeyValue 将使用所提供查询的自定义名称,如果没有(或 ),则使用操作的标准名称。 如果已发送有效的 GraphQL 响应、无法分析请求或无法生成有效的 GraphQL 响应,则 KeyValue 将为。graphql.operation"query""mutation""subscription"graphql.outcome"SUCCESS""REQUEST_ERROR""INTERNAL_ERROR"Spring中文文档

表 2.高基数键

graphql.execution.id (必填)Spring中文文档

graphql.execution.ExecutionId的 GraphQL 请求。Spring中文文档

Spring for GraphQL 还为服务器请求观察贡献了事件。千分尺观测事件通常作为迹线中的跨度注释进行处理。 此检测将 GraphQL 响应中列出的错误记录为事件。Spring中文文档

表 3.观察活动

上下文名称Spring中文文档

GraphQL 错误类型,例如InvalidSyntaxSpring中文文档

完整的 GraphQL 错误消息,例如"Invalid syntax with offending token 'invalid'…​"Spring中文文档

表 1.低基数键

graphql.operation (必填)Spring中文文档

GraphQL 操作名称。Spring中文文档

graphql.outcome (必填)Spring中文文档

GraphQL 请求的结果。Spring中文文档

表 2.高基数键

graphql.execution.id (必填)Spring中文文档

graphql.execution.ExecutionId的 GraphQL 请求。Spring中文文档

表 3.观察活动

上下文名称Spring中文文档

GraphQL 错误类型,例如InvalidSyntaxSpring中文文档

完整的 GraphQL 错误消息,例如"Invalid syntax with offending token 'invalid'…​"Spring中文文档

DataFetcher 检测

GraphQL DataFetcher 观察值的名称为 ,仅用于被视为“非平凡”的数据获取操作(对 Java 对象进行属性获取是一项平凡的操作)。 应用程序需要在其应用程序中配置检测。 默认情况下,它使用 ."graphql.datafetcher"org.springframework.graphql.observation.GraphQlObservationInstrumentationorg.springframework.graphql.observation.DefaultDataFetcherObservationConventionDataFetcherObservationContextSpring中文文档

默认情况下,将创建以下 KeyValues:Spring中文文档

表 4.低基数键

graphql.error.type (必填)Spring中文文档

数据提取错误的类名Spring中文文档

graphql.field.name (必填)Spring中文文档

要获取的字段的名称。Spring中文文档

graphql.outcome (必填)Spring中文文档

GraphQL 数据获取操作的结果,“SUCCESS”或“ERROR”。Spring中文文档

表 5.高基数键

名字Spring中文文档

描述Spring中文文档

graphql.field.path (必填)Spring中文文档

要提取的字段的路径(例如,“/bookById”)。Spring中文文档

表 4.低基数键

graphql.error.type (必填)Spring中文文档

数据提取错误的类名Spring中文文档

graphql.field.name (必填)Spring中文文档

要获取的字段的名称。Spring中文文档

graphql.outcome (必填)Spring中文文档

GraphQL 数据获取操作的结果,“SUCCESS”或“ERROR”。Spring中文文档

表 5.高基数键

名字Spring中文文档

描述Spring中文文档

graphql.field.path (必填)Spring中文文档

要提取的字段的路径(例如,“/bookById”)。Spring中文文档