Metrics exporters

Export router metrics


The GraphOS Router and Apollo Router Core support collection of metrics with OpenTelemetry, with exporters for:

In router.yaml, you configure router metrics with the following settings:

  • telemetry.exporters.metrics.common. Configure values for the router which are common across metrics exporters.

  • telemetry.exporters.metrics.prometheus. Configure the Prometheus exporter.

  • telemetry.exporters.metrics.otlp. Configure the OpenTelemetry exporter. Supports sending traces to Datadog.

Metrics common configuration

Common metrics configuration contains global settings for all exporters:

service_name

Set a service name for your router metrics so you can easily locate them in external metrics dashboards.

The service name can be set by an environment variable or in router.yaml, with the following order of precedence (first to last):

  1. OTEL_SERVICE_NAME environment variable

  2. OTEL_RESOURCE_ATTRIBUTES environment variable

  3. telemetry.exporters.metrics.common.service_name in router.yaml

    Example service_name
    Example setting service name in telemetry.exporters.metrics.common.service_name:
    YAML
    router.yaml
    1telemetry:
    2  exporters:
    3    metrics:
    4      common:
    5        # (Optional) Set the service name to easily find metrics related to the apollo-router in your metrics dashboards
    6        service_name: "router"
  4. telemetry.exporters.metrics.common.resource in router.yaml

    Example resource
    Example setting service name in telemetry.exporters.metrics.common.resource:
    YAML
    router.yaml
    1telemetry:
    2  exporters:
    3    metrics:
    4      common:
    5        resource:
    6          # (Optional) Set the service name to easily find metrics related to the apollo-router in your metrics dashboards
    7          "service.name": "router"

If the service name isn't explicitly set, it defaults to unknown_service:router or unknown_service if the executable name cannot be determined.

resource

A resource attribute is a set of key-value pairs that provide additional information to an exporter. It's an attribute of an OpenTelemetry resource. Application performance monitors (APM) can interpret and display resource information.

In router.yaml, resource attributes are set in telemetry.metrics.common.resource. For example:

YAML
router.yaml
1telemetry:
2  exporters:
3    metrics:
4      common:
5        resource:
6          "deployment.environment.name": "production"
7          "k8s.namespace.name": "{env.MY_K8_NAMESPACE_ENV_VARIABLE}"

For OpenTelemetry conventions for resources, see Resource Semantic Conventions.

buckets

You can customize bucket boundaries for all generated histograms by setting telemetry.exporters.metrics.common.buckets in router.yaml. For example:

YAML
router.yaml
1telemetry:
2  exporters:
3    metrics:
4      common:
5        buckets:
6          - 0.05
7          - 0.10
8          - 0.25
9          - 0.50
10          - 1.00
11          - 2.50
12          - 5.00
13          - 10.00
14          - 20.00

views

OpenTelemetry views enable you to customize metrics behavior, including renaming metrics, overriding attributes, changing default buckets, or dropping metrics entirely.

Renaming metrics

You can rename metrics to match your organization's naming conventions or to align with existing monitoring infrastructure. This is particularly useful for customizing OTLP semantic convention metrics.

YAML
router.yaml
1telemetry:
2  exporters:
3    metrics:
4      common:
5        service_name: apollo-router
6        views:
7          - name: http.server.request.duration # Instrument name to rename
8            rename: apollo.router.http.request.duration # New metric name
9
note
Important naming considerations:
  • OTLP exporters use the renamed metric name exactly as specified.
  • Prometheus exporters automatically transform metric names:
    • Dots (.) are converted to underscores (_).
    • Unit suffixes are added (e.g., _seconds, _bytes).
    • For example, apollo.router.http.duration becomes apollo_router_http_duration_seconds.
  • Apollo Studio metrics aren't affected by renaming and continue to use the original metric names.

You can combine rename with other view properties:

YAML
router.yaml
1telemetry:
2  exporters:
3    metrics:
4      common:
5        views:
6          - name: apollo.router.operations
7            rename: custom.graphql.operations
8            description: "Custom GraphQL operation metrics"
9            aggregation:
10              histogram:
11                buckets: [0.1, 0.5, 1.0, 5.0, 10.0]
12            allowed_attribute_keys:
13              - graphql.operation.name
14              - graphql.operation.type
15

Customizing metric attributes and buckets

You can override default attributes and buckets for specific metrics:

YAML
router.yaml
1telemetry:
2  exporters:
3    metrics:
4      common:
5        service_name: apollo-router
6        views:
7          - name: apollo_router_http_request_duration_seconds # Instrument name you want to edit. You can use wildcard in names. If you want to target all instruments just use '*'
8            unit: "ms" # (Optional) override the unit
9            description: "my new description of this metric" # (Optional) override the description
10            aggregation: # (Optional)
11              histogram:
12                buckets: # Override default buckets configured for this histogram
13                - 1
14                - 2
15                - 3
16                - 4
17                - 5
18            allowed_attribute_keys: # (Optional) Keep only listed attributes on the metric
19            - status
20

Dropping metrics

You can drop specific metrics if you don't want them sent to your APM:

YAML
router.yaml
1telemetry:
2  exporters:
3    metrics:
4      common:
5        service_name: apollo-router
6        views:
7          - name: apollo_router_http_request_duration_seconds # Instrument name you want to edit. You can use wildcard in names. If you want to target all instruments just use '*'
8            aggregation: drop
9

Metrics common reference

AttributeDefaultDescription
service_nameunknown_service:routerThe OpenTelemetry service name.
service_namespaceThe OpenTelemetry namespace.
resourceThe OpenTelemetry resource to attach to metrics.
viewsCustomizes metrics using OpenTelemetry views: rename metrics, override default buckets and attributes, or drop metrics entirely.
Feedback

Edit on GitHub

Ask Community