Docs
Try GraphOS

API Reference: Inline trace plugin


Using the plugin

📣 New in Apollo Server 4: error details are not included in traces by default. For more details, see Error Handling.

This article documents the options for the ApolloServerPluginInlineTrace plugin, which you can import from @apollo/server/plugin/inlineTrace.

This plugin enables your GraphQL server to include encoded performance and usage traces inside responses. This is primarily designed for use with Apollo Federation. Federated subgraphs use this plugin and include a trace in the ftv1 GraphQL response extension if requested to do so by the Apollo gateway. The gateway requests this trace by passing the HTTP header apollo-federation-include-trace: ftv1.

Apollo Server installs this plugin by default in all federated subgraphs, with its default configuration. Apollo Server inspects whether or not the schema it is serving includes a field _Service.sdl: String! (as well as its former, nullable version from Federation v1: _Service.sdl: String) to determine if it is a federated subgraph. You typically do not have to install this plugin yourself; you only need to do so if you want to provide non-default configuration.

If you want to configure the ApolloServerPluginInlineTrace plugin, import it and pass it to your ApolloServer constructor's plugins array:

import { ApolloServer } from '@apollo/server';
import { ApolloServerPluginInlineTrace } from '@apollo/server/plugin/inlineTrace';
const server = new ApolloServer({
typeDefs,
resolvers,
plugins: [
ApolloServerPluginInlineTrace({
includeErrors: { transform: (err) => (err.message.match(SENSITIVE_REGEX) ? null : err) },
}),
],
});
import { ApolloServer } from '@apollo/server';
import { ApolloServerPluginInlineTrace } from '@apollo/server/plugin/inlineTrace';
const server = new ApolloServer({
typeDefs,
resolvers,
plugins: [
ApolloServerPluginInlineTrace({
includeErrors: { transform: (err) => (err.message.match(SENSITIVE_REGEX) ? null : err) },
}),
],
});

If you don't want to use the inline trace plugin even though your schema defines _Service.sdl: String!, you can explicitly disable it with the ApolloServerPluginInlineTraceDisabled plugin:

import { ApolloServer } from '@apollo/server';
import { ApolloServerPluginInlineTraceDisabled } from '@apollo/server/plugin/disabled';
const server = new ApolloServer({
typeDefs,
resolvers,
plugins: [ApolloServerPluginInlineTraceDisabled()],
});
import { ApolloServer } from '@apollo/server';
import { ApolloServerPluginInlineTraceDisabled } from '@apollo/server/plugin/disabled';
const server = new ApolloServer({
typeDefs,
resolvers,
plugins: [ApolloServerPluginInlineTraceDisabled()],
});

Note that when this plugin is installed in your app, any client can request a trace for any operation they run, which may reveal information about your server that you consider sensitive (such as how long each individual field takes to execute). Federated subgraphs generally should not be directly exposed to the public Internet.

When using Federation, you typically run this plugin in subgraphs and you run the usage reporting plugin in gateways; this is how the default behavior works. If you include this plugin in a gateway, then the gateway will include a full trace including the query plan and all subgraph traces inline in its responses. This is not recommended for publicly exposed servers, but can be helpful when developing locally if you want to see the exact query plan generated by your gateway.

Options

Name /
Type
Description
includeErrors

Object

Provide this object to modify GraphQL operation errors before your server reports those errors in traces to Apollo Studio. Valid options are described in Valid includeErrors object signatures.

The default value is { masked: true }, which means error messages are masked and extensions are omitted. This is a security measure to prevent sensitive data from potentially reaching Apollo servers.

Valid includeErrors object signatures

ObjectDescription
{ masked: true }

If you provide this object, error messages are masked and extensions omitted in the traces sent to Apollo Studio. This is the default behavior.

{ unmodified: true }

If you provide this object, all error messages and extensions are included in traces

{ transform: (err: GraphQLError) => GraphQLError | null }

The value of transform is a function that receives each error (GraphQLError) and must also return a GraphQLError object (or null to prevent Apollo Server from reporting a particular error entirely).

The only properties of the reported error you can modify are its message and its extensions. See Masking and logging errors for more details.

Previous
Schema reporting
Next
Drain HTTP server
ForumsDiscord