Here's your chance to speak at GraphQL Summit in New York City, October 8 - 10, 2024! 🏙️ Submit your proposal by May 31.
Docs
Launch GraphOS Studio

Instruments

Collect measurements with standard and custom instruments


This feature is only available with a GraphOS Dedicated or Enterprise plan.
To compare GraphOS feature support across all plan types, see the pricing page.

An instrument in the collects data and reports measurements to a metric backend. Supported instruments include standard instruments from OpenTelemetry, standard instruments for the router's request lifecycle, and custom instruments. Supported instrument kinds are counters and histograms.

You can configure instruments in router.yaml with telemetry.instrumentation.instruments.

OpenTelemetry standard instruments

OpenTelemetry specifies multiple standard metric instruments that are available in the router:

  • http.server.active_requests - The number of active requests in flight.
  • http.server.request.body.size - A histogram of request body sizes for requests handled by the router.
  • http.server.request.duration - A histogram of request durations for requests handled by the router.
  • http.server.response.body.size - A histogram of response body sizes for requests handled by the router.

These instruments are configurable in router.yaml:

router.yaml
telemetry:
instrumentation:
instruments:
router:
http.server.active_requests: true # (default false)
http.server.request.body.size: true # (default false)
http.server.request.duration: true # (default false)
http.server.response.body.size: true # (default false)

They can be customized by attaching or removing attributes. See attributes to learn more about configuring attributes.

router.yaml
telemetry:
instrumentation:
instruments:
default_requirement_level: required
router:
http.server.active_requests:
attributes:
http.request.method: true

Apollo standard instruments

To learn about standard metric instruments for the router's request lifecycle, see Apollo Router instruments.

Custom instruments

This feature is only available with a GraphOS Dedicated or Enterprise plan.
To compare GraphOS feature support across all plan types, see the pricing page.

You can define custom instruments on the router, , and services in the router pipeline.

NOTE

When defining a custom instrument, make sure to reference OpenTelemetry semantic conventions.

In the example configuration below, three custom instruments are defined (acme.request.duration, acme.graphql.requests, acme.graphql.subgraph.errors), one for each service of the router pipeline respectively (router, supergraph, subgraph):

router.yaml
telemetry:
instrumentation:
instruments:
router:
http.server.active_requests: true
acme.request.duration:
value: duration
type: counter
unit: kb
description: "my description"
condition:
eq:
- 200
- response_status: code
attributes:
http.response.status_code: true
"my_attribute":
response_header: "x-my-header"
supergraph:
acme.graphql.requests:
value: unit
type: counter
unit: count
description: "supergraph requests"
subgraph:
acme.graphql.subgraph.errors:
value: unit
type: counter
unit: count
description: "my description"

NOTE

Keep in mind that the amount of telemetry you add can impact your router's performance.

  • Custom metrics, events, and attributes consume more processing resources than standard metrics. Adding too many (standard or custom) can slow your router down.
  • Configurations such as events.*.request|error|response that produce output for all router lifecycle services should only be used for development or debugging, not for production.

For properly logged telemetry, you should use a log verbosity of info. Set the values of RUST_LOG or APOLLO_ROUTER_LOG environment variables and the --log CLI option to info. Using less verbose logging, such as error, can cause some attributes to be dropped.

Instrument naming conventions

Make sure to follow naming conventions for instruments. For reference, the OpenTelemetry semantic conventions can help guide you to:

  • Choose a good name for your instrument.
  • See which standard attributes can be attached to your instrument.

Some particular guidelines to note:

  • Don't include the unit name in the metric name. For example, size_kb should be size and the unit should be kb.
  • Don't include _total as a suffix. For example, use http.server.active_requests, not http.server.active_requests_total.
  • Use dot notation to separate namespaces in the metric name. For example, use http.server.active_requests, not http_server_active_requests.

Instrument configuration

default_requirement_level

The default_requirement_level option sets the default attributes to attach to default standard instruments, as defined by OpenTelemetry semantic conventions.

Valid values:

  • required (default) - required attributes will be attached to standard instruments by default.
  • recommended - recommended attributes will be attached to standard instruments by default.
router.yaml
telemetry:
instrumentation:
instruments:
# Set the default requirement level
default_requirement_level: required

Attributes can be configured individually, so that required attributes can be overridden or disabled. For example, http.response.status_code is set individually to override the standard value:

router.yaml
telemetry:
instrumentation:
instruments:
# Set the default requirement level
default_requirement_level: required
router:
# Standard metrics
http.server.request.body.size:
attributes:
# Standard attributes
http.response.status_code: false
# Custom attribute
"acme.my_attribute":
response_header: "x-my-header"
# Standard metrics
http.server.active_requests:
attributes:
# Standard attributes, different than other ones provides in standard metrics, custom attributes are not available on this standard metric
http.request.method: false
server.address: true
server.port: true
url.scheme: true

NOTE

The attributes that the OpenTelemetry spec defines as opt-in must be configured individually.

Router request lifecycle services

The 's request lifecycle has three major services:

  • Router service - Handles an incoming request before it is parsed. Works within a context of opaque bytes.
  • Supergraph service - Handles a request after it has been parsed and before it is sent to the subgraph. Works within a context.
  • Subgraph service - Handles a request after it has been sent to the subgraph. Works within a GraphQL context.

The router, supergraph and subgraph sections are used to define custom instruments for each service.

To define a custom instrument, add a new key to router.yaml as telemetry.instruments.<service>.<custom-instrument>. For example, add a custom instrument acme.request.duration:

router.yaml
telemetry:
instrumentation:
instruments:
router:
acme.request.duration: # The name of your custom instrument/metric
value: duration
type: counter
unit: s
description: "my description"

value

The value of an instrument is the value which will be drawn from. This can be one of the following:

  • duration - the duration of the pipeline service.
  • unit - the number of times the pipeline service has been executed.
  • custom - a custom value extracted from the pipeline service. See selectors for more information.
  • event_duration - the duration of an event in the pipeline service.
  • event_unit - the number of times an event in the pipeline service has been executed.
  • event_custom - a custom value extracted from the event in the pipeline service. See selectors for more information.
future.router.yaml
telemetry:
instrumentation:
instruments:
router:
acme.metric:
# ...
value: duration

event_* are mandantory when you want to use a selector on the supergraph response body (response_data and response_errors).

Values of custom metrics can be extracted from the pipeline using custom attributes. For example, to sum the contents of a request header, create a counter with value set as the request header:

future.router.yaml
telemetry:
instrumentation:
instruments:
router:
acme.metric:
# ...
type: counter
value:
request_header: "x-my-header"

NOTE

The value must be of the expected type for the instrument. For example, a counter must have a numeric value.

type

Instruments come in two different types:

  • counter - A monotonic counter. For example, requests served, tasks completed, or errors occurred.
  • histogram - A histogram of values. For example, request durations or response body sizes.
future.router.yaml
telemetry:
instrumentation:
instruments:
router:
acme.metric:
# ...
type: counter # counter, histogram

unit

A free format unit that is displayed in your APM.

A unit is recommended to use SI units and definitions from The Unified Code for Units of Measure.

future.router.yaml
telemetry:
instrumentation:
instruments:
router:
acme.metric:
# ...
unit: s # seconds

description

A free format description of the instrument that will be displayed in your APM.

future.router.yaml
telemetry:
instrumentation:
instruments:
router:
acme.metric:
# ...
description: "my description"

condition

You may only want to mutate an instrument under certain conditions. For example, you may only want to increment a counter if the response status code is 200.

To do this use a condition:

future.router.yaml
telemetry:
instrumentation:
instruments:
router:
acme.metric:
# ...
condition:
eq:
- 200
- response_status: code

attributes

Instruments may have attributes attached to them from the router pipeline. These attributes are used to filter and group metrics in your APM.

Attributes may be drawn from standard attributes or selectors except for the standard metric http.server.active_requests.

The attributes available depend on the service of the pipeline.

router.yaml
telemetry:
instrumentation:
instruments:
router:
# Standard metrics
http.server.request.body.size:
attributes:
# Standard attributes
http.response.status_code: false
# Custom attribute
"acme.my_attribute":
response_header: "x-my-header"
# Standard metrics
http.server.active_requests:
attributes:
# Standard attributes, different than other ones provides in standard metrics, custom attributes are not available on this standard metric
http.request.method: false
server.address: true
server.port: true
url.scheme: true
# Custom metric
acme.metric:
value: duration
type: counter
unit: s
description: "my description"
attributes:
http.response.status_code: true
"my_attribute":
# ...
response_header: "x-my-header"
subgraph:
requests.timeout:
value: unit
type: counter
unit: request
description: "subgraph requests containing subgraph timeout"
attributes:
subgraph.name: true
condition:
eq:
- "request timed out"
- error: reason

Instrument configuration reference

OptionValuesDefaultDescription
<attribute-name>The name of the custom attribute.
<instrument-name>The name of the custom instrument.
attributesstandard attributes or selectorsThe attributes of the custom instrument.
conditionconditionsThe condition for mutating the instrument.
default_requirement_levelrequired|recommendedrequiredThe default attribute requirement level.
typecounter|histogramThe name of the custom instrument.
unitA unit name, for example By or {request}.
descriptionThe description of the custom instrument.
valueunit|duration|<custom>The value of the instrument.
Previous
Zipkin
Next
Events
Edit on GitHubEditForumsDiscord

© 2024 Apollo Graph Inc.

Privacy Policy

Company