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
Start for Free
Apollo Server 2 is officially end-of-life as of 22 October 2023. Learn more about upgrading.

Metrics and logging

How to monitor Apollo Server's performance

integrates seamlessly with Apollo Studio to help you monitor the execution of your . It also provides configurable mechanisms for logging each phase of a GraphQL operation.

Using Federation? Check out the documentation for federated tracing.

Sending metrics to Apollo Studio

Apollo Studio provides an integrated hub for all of your GraphQL performance data. It aggregates and displays information for your schema, queries, requests, and errors. You can also configure alerts that support Slack and Datadog integrations.

Connecting to Apollo Studio

To connect Apollo Server to Apollo Studio, first obtain a graph API key. To provide this key to Apollo Server, assign it to the APOLLO_KEY environment variable in your server's environment.

Then associate your server instance with a particular ID and graph variant by setting the APOLLO_GRAPH_ID and APOLLO_GRAPH_VARIANT environment variables.

You can set environment variable values on the command line as seen below, or with the dotenv npm package (or similar).

# Replace the example values below with values specific to your use case.
APOLLO_KEY=YOUR_API_KEY APOLLO_GRAPH_ID=mygraph APOLLO_GRAPH_VARIANT=development node start-server.js

Identifying distinct clients

Apollo Studio's client awareness feature enables you to view metrics for distinct versions of your clients. To enable this, your clients need to include some or all of the following identifying information in the headers of GraphQL requests they send to Apollo Server:

IdentifierHeader Name (default)Example Value
Client nameapollographql-client-nameiOS Native
Client versionapollographql-client-version1.0.1

Each of these can have any string value that's useful for your application. To simplify the browsing and sorting of your client data in Studio, a three-part version number (such as 1.0.1) is recommended for client versions.

Client version is not tied to your current version of (or any other client library). You define this value and are responsible for updating it whenever meaningful changes are made to your client.

Setting client awareness headers in Apollo Client

If you're using Apollo Client, you can set default values for client name and version in the ApolloClient constructor. All requests to Apollo Server will automatically include these values in the appropriate headers.

Using custom headers

For more advanced cases, or to use headers other than the default headers, pass a generateClientInfo function into the usage reporting plugin:

const { ApolloServer } = require("apollo-server");
const { ApolloServerPluginUsageReporting } = require("apollo-server-core");
const server = new ApolloServer({
plugins: [
generateClientInfo: ({
}) => {
const headers = request.http && request.http.headers;
if(headers) {
return {
clientName: headers['apollographql-client-name'],
clientVersion: headers['apollographql-client-version'],
} else {
return {
clientName: "Unknown Client",
clientVersion: "Unversioned",
server.listen().then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);


You can set up fine-grained logging in Apollo Server by defining a custom plugin. Apollo Server plugins enable you to perform actions in response to individual phases of the GraphQL request lifecycle, such as whenever a GraphQL request is received from a client.

The example below defines a plugin that responds to three different operation events. As it shows, you provide an array of your defined plugins to the ApolloServer constructor.

For a list of available lifecycle events and their descriptions, see Plugins.

const myPlugin = {
// Fires whenever a GraphQL request is received from a client.
requestDidStart(requestContext) {
console.log('Request started! Query:\n' +
return {
// Fires whenever Apollo Server will parse a GraphQL
// request to create its associated document AST.
parsingDidStart(requestContext) {
console.log('Parsing started!');
// Fires whenever Apollo Server will validate a
// request's document AST against your GraphQL schema.
validationDidStart(requestContext) {
console.log('Validation started!');
const server = new ApolloServer({
plugins: [
Google Cloud Functions
Health checks
Rate articleRateEdit on GitHubEditForumsDiscord

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

Privacy Policy