Join us from October 8-10 in New York City to learn the latest tips, trends, and news about GraphQL Federation and API platform engineering.Join us for GraphQL Summit 2024 in NYC
Docs
Start for Free

GraphOS reporting

Send router operation metrics to GraphOS


The and can report usage metrics to GraphOS that you can then visualize in . These metrics also enable powerful GraphOS features like schema checks.

Enabling usage reporting

You enable usage reporting in the by setting the following environment variables:

export APOLLO_KEY=<YOUR_GRAPH_API_KEY>
export APOLLO_GRAPH_REF=<YOUR_GRAPH_ID>@<VARIANT_NAME>

For more information, see Sending operation metrics to GraphOS.

Reporting field-level traces

In their responses to your router, your can include field-level traces that indicate how long the took to resolve each in an operation. By analyzing this data in GraphOS Studio, you can identify and optimize your slower fields:

Viewing a trace in GraphOS Studio

Your subgraph libraries must support federated tracing (also known as FTV1 tracing) to provide this data.

  • To confirm support, check the FEDERATED TRACING entry for your library on this page.
  • Consult your library's documentation to learn how to enable federated tracing.
    • If you use with @apollo/subgraph, federated tracing support is enabled automatically.

Subgraph trace sampling

By default, the router requests subgraph trace data from with a 1% sampling probability per operation. In most cases, this provides a sufficient sample size while minimizing latency for most operations (traces can affect latency because they increase the size of subgraph response payloads).

You can customize your router's trace sampling probability by setting the following options in your YAML config file:

router.yaml
telemetry:
apollo:
# In this example, the trace sampler is configured
# with a 50% probability of sampling a request.
# This value can't exceed the value of tracing.common.sampler.
field_level_instrumentation_sampler: 0.5
exporters:
tracing:
common:
# FTV1 uses the same trace sampling as other tracing options,
# so this value is also required.
sampler: 0.5

NOTE

Because field-level instrumentation is dependent on general-purpose OpenTelemetry tracing, the value of telemetry.apollo.field_level_instrumentation_sampler cannot exceed the value of telemetry.exporters.tracing.common.sampler.

Disabling field-level traces

To completely disable requesting and reporting subgraph trace data, set field_level_instrumentation_sampler to always_off:

router.yaml
telemetry:
apollo:
field_level_instrumentation_sampler: always_off

Experimental local field metrics

Apollo can send field-level metrics to without using FTV1 tracing. This feature is experimental and is not yet displayable in GraphOS Studio. To enable this feature, set the experimental_local_field_metrics option to true in your router configuration:

router.yaml
telemetry:
apollo:
experimental_local_field_metrics: true

Advanced configuration

send_headers

Provide this field to configure which request header names and values are included in trace data that's sent to GraphOS. By default, no header information is sent to GraphOS as a security measure.

router.yaml
telemetry:
apollo:
field_level_instrumentation_sampler: 0.01 # (default)
send_headers:
only: # Include only headers with these names
- referer

Supported values:

Value / TypeDescription
none

string

Set send_headers to the string value none to include no header information in reported traces.

send_headers: none

This is the default behavior.

all

string

Set send_headers to the string value all to include all header information in reported traces.

send_headers: all

⚠️ Use with caution! Headers might contain sensitive data (such as access tokens) that should not be reported to GraphOS.

only

array

An array of names for the headers that the router will report to GraphOS. All other headers are not reported. See the example above.

except

array

An array of names for the headers that the router will not report to GraphOS. All other headers are. Uses the same format as the only example above.

send_variable_values

Provide this field to configure which values are included in trace data that's sent to GraphOS. By default, no variable information is sent to GraphOS as a security measure.

router.yaml
telemetry:
apollo:
field_level_instrumentation_sampler: 0.01 # (default)
send_variable_values:
except: # Send all variables EXCEPT ones with these names
- first

Supported values:

Value / TypeDescription
none

string

Set send_variable_values to the string value none to include no variable information in reported traces.

send_variable_values: none

This is the default behavior.

all

string

Set send_variable_values to the string value all to include all variable information in reported traces.

send_variable_values: all

⚠️ Use with caution! GraphQL might contain sensitive data that should not be reported to GraphOS.

only

array

An array of names for the variables that the router will report to GraphOS. All other variables are not reported. Uses the same format as the except example above.

except

array

An array of names for the variables that the router will not report to GraphOS. All other variables are reported. See the example above.

router.yaml
telemetry:
apollo:
# The percentage of requests will include HTTP request and response headers in traces sent to GraphOS Studio.
# This is expensive and should be left at a low value.
# This cannot be higher than tracing->common->sampler
field_level_instrumentation_sampler: 0.01 # (default)
# Include HTTP request and response headers in traces sent to GraphOS Studio
send_headers: # other possible values are all, only (with an array), except (with an array), none (by default)
except: # Send all headers except referer
- referer
# Include variable values in Apollo in traces sent to GraphOS Studio
send_variable_values: # other possible values are all, only (with an array), except (with an array), none (by default)
except: # Send all variable values except for variable named first
- first
exporters:
tracing:
common:
sampler: 0.5 # The percentage of requests that will generate traces (a rate or `always_on` or `always_off`)

errors

You can configure whether the router reports GraphQL error information to GraphOS, and whether the details of those errors are redacted. You can customize this behavior globally and override that global behavior on a per-subgraph basis.

By default, your router does report error information, and it does redact the details of those errors.

  • To prevent your router from reporting error information at all, you can set the send option to false.
  • To include all error details in your router's reports to GraphOS, you can set the redact option to false.

Your subgraph libraries must support federated tracing (also known as FTV1 tracing) to provide errors to GraphOS. If you use Apollo Server with @apollo/subgraph, federated tracing support is enabled automatically.

To confirm support:

  • Check the FEDERATED TRACING entry for your library on the supported subgraphs page.
  • If federated tracing isn't enabled automatically for your library, consult its documentation to learn how to enable it.
  • Note that federated tracing can also be sampled (see above) so error messages might not be available for all your operations if you have sampled to a lower level.

See the example below:

router.yaml
telemetry:
apollo:
errors:
subgraph:
all:
# By default, subgraphs should report errors to GraphOS
send: true # (default: true)
redact: false # (default: true)
subgraphs:
account: # Override the default behavior for the "account" subgraph
send: false

NOTE

If you're writing a plugin, you can get the Studio Trace ID by reading the value of apollo_operation_id from the context.

Previous
Overview
Next
Client Awareness
Rate articleRateEdit on GitHubEditForumsDiscord

© 2024 Apollo Graph Inc., d/b/a Apollo GraphQL.

Privacy Policy

Company