可观测性

使用 Micrometer 的可观测性支持 直接集成到 Spring for GraphQL 中。这为 GraphQL 请求和“非平凡”数据获取操作启用了指标和跟踪。由于 GraphQL 引擎在传输层之上运行,您还应该预期来自传输层的观测,如果 Spring Framework 支持的话。

只有在应用程序中配置了 ObservationRegistry 时,才会发布观测。您可以了解更多关于在 Spring Boot 中配置可观测性基础设施的信息。如果您想自定义 GraphQL 观测产生的元数据,您可以直接在 instrumentation 上配置自定义约定。如果您的应用程序使用 Spring Boot,将自定义约定作为 bean 贡献是首选方式。

服务器请求 instrumentation

GraphQL 服务器请求观测以名称 "graphql.request" 创建,适用于传统和响应式应用程序以及所有受支持的传输层。此 instrumentation 假定任何父观测必须使用众所周知的 "micrometer.observation" 键在 GraphQL 上下文中设置为当前观测。对于跨网络边界的跟踪传播,传输层上的单独 instrumentation 必须负责。对于 HTTP,Spring Framework 有专门的 instrumentation 负责跟踪传播

应用程序需要在其应用程序中配置 org.springframework.graphql.observation.GraphQlObservationInstrumentation instrumentation。它默认使用 org.springframework.graphql.observation.DefaultExecutionRequestObservationConvention,由 ExecutionRequestObservationContext 提供支持。

默认情况下,将创建以下键值

表 1. 低基数键

名称

描述

graphql.operation.type (必需)

GraphQL 操作类型。

graphql.outcome (必需)

GraphQL 请求的结果。

graphql.operation.type 键值将使用操作的标准名称"query""mutation""subscription"),如果请求文档无法解析,则为 "operation"

graphql.outcome 键值将是

  • "SUCCESS" 如果发送了有效的 GraphQL 响应且不包含任何错误

  • "REQUEST_ERROR" 如果请求无法解析,或者响应包含错误(其中没有一个类型为 org.springframework.graphql.execution.ErrorType.INTERNAL_ERROR

  • "INTERNAL_ERROR" 如果无法生成有效的 GraphQL 响应,或者响应包含至少一个类型为 org.springframework.graphql.execution.ErrorType.INTERNAL_ERROR 的错误

表2. 高基数键

名称

描述

graphql.execution.id (必需)

GraphQL 请求的 graphql.execution.ExecutionId

graphql.operation.name (必需)

GraphQL 操作名称。

graphql.operation.name 键值将类似于 graphql.operation.name,它将使用客户端提供的操作名称。

Spring for GraphQL 还为服务器请求观测贡献事件。Micrometer 观测事件 通常在跟踪中作为 span 注解处理。此 instrumentation 将 GraphQL 响应中列出的错误记录为事件。

表3. 观测事件

名称

上下文名称

GraphQL 错误类型,例如 InvalidSyntax

完整的 GraphQL 错误消息,例如 "Invalid syntax with offending token 'invalid'..."

DataFetcher instrumentation

GraphQL DataFetcher 观测以名称 "graphql.datafetcher" 创建,仅适用于被视为“非平凡”的数据获取操作(Java 对象上的属性获取是平凡操作)。应用程序需要在其应用程序中配置 org.springframework.graphql.observation.GraphQlObservationInstrumentation instrumentation。它默认使用 org.springframework.graphql.observation.DefaultDataFetcherObservationConvention,由 DataFetcherObservationContext 提供支持。

默认情况下,将创建以下键值

表 4. 低基数键

名称

描述

graphql.error.type (必需)

数据获取错误的类名

graphql.field.name (必需)

正在获取的字段名称。

graphql.outcome (必需)

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

表5. 高基数键

名称

描述

graphql.field.path (必需)

正在获取的字段路径(例如,“/bookById”)。

DataLoader instrumentation

GraphQL DataLoader 观测以名称 "graphql.dataloader" 创建,观测对 @BatchMapping 控制器方法和手动注册的 DataLoader 实例的调用。应用程序需要在其应用程序中配置 org.springframework.graphql.observation.GraphQlObservationInstrumentation instrumentation。它默认使用 org.springframework.graphql.observation.DefaultDataLoaderObservationConvention,由 DataLoaderObservationContext 提供支持。

默认情况下,将创建以下键值

表6. 低基数键

名称

描述

graphql.error.type (必需)

数据获取错误的类名

graphql.loader.name (必需)

正在使用的 DataLoader 的名称。

graphql.outcome (必需)

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

表7. 高基数键

名称

描述

graphql.loader.size (必需)

加载元素列表的大小。

© . This site is unofficial and not affiliated with VMware.