Prometheus is a platform for scraping metrics from services and utilities. You can use @graphql-mesh/plugin-prometheus plugin to expose and collect metrics from all phases of your GraphQL execution including internal query planning and outgoing HTTP requests.

This plugin tracks the complete gateway execution flow and exposes the following metrics:

  • Successful requests (requestCount)
  • Request summary (requestSummary)
  • errors (categorized by phase)
  • resolvers tracing and runtime
  • deprecated fields usage
  • count of graphql operations
  • parse execution time
  • validate execution time
  • contextBuilding execution time
  • execute execution time
  • Latency of outgoing HTTP request
  • Latency of the delegation to the individual sources

Getting Started

yarn add @graphql-mesh/plugin-prometheus
yarn add prom-client

Example Configuration

# ...
  - prometheus:
    # all optional, and by default, all set to false, please opt-in to the metrics you wish to get
    # requires `execute` to be true
    requestCount: true
    # requires `execute` to be true
    requestSummary: true
    parse: true
    validate: true
    contextBuilding: true
    execute: true
    errors: true
    resolvers: true
    # reports metrics also for these resolvers, by default all fields are reported
      - Mutation.*
      - Query.user
    deprecatedFields: true
    # the path of the endpoint to expose the metrics, default is /metrics
    endpoint: /metrics

Note: Tracing resolvers using resolvers: true might have a performance impact on your GraphQL runtime. Please consider to test it locally first and then decide if it's needed.

Custom Registry

You can customize the client's registry by passing a custom registry to the registry option.

// myRegistry.ts
import { Registry } from 'prom-client';
export default const myRegistry = new Registry();
# ...
  - prometheus:
      # ...
      registry: ./myRegistry.ts

Config API Reference

  • requestCount (type: Boolean)
  • requestTotalDuration (type: Boolean)
  • requestSummary (type: Boolean)
  • parse (type: Boolean)
  • validate (type: Boolean)
  • contextBuilding (type: Boolean)
  • execute (type: Boolean)
  • errors (type: Boolean)
  • resolvers (type: Boolean)
  • resolversWhiteList (type: Array of String)
  • deprecatedFields (type: Boolean)
  • delegation (type: Boolean)
  • fetch (type: Boolean)
  • skipIntrospection (type: Boolean)
  • registry (type: String)
  • endpoint (type: String) - The path to the metrics endpoint default: /metrics