Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
usage reporting plugin: add captureTraces option
The usage reporting plugin already has an includeRequest option which allows you to tell the plugin to completely ignore an operation. One reason you may have wanted to use this is to avoid the overhead of capturing a full field-by-field execution trace. But in this case, includeRequest=false is overkill: it removes the operation from aspects of Studio such as the Operations page and schema checks which don't require full execution traces to operate. This PR adds a new option, captureTraces, which is invoked after includeRequest returns true. If you return false from this operation, you won't incur the overhead of capturing a detailed trace (either directly in this process, or in subgraphs if this process is a Gateway). Most of Studio's features (including the newly-added "referencing operations" column on the Fields page) will still reflect the existence of this operation. As of the end of 2021, the features that this operation will not contribute to are: - The "field executions" column on the Fields page - The per-field timing hints shown in Explorer and in vscode-graphql - The trace view on the Operations page You can also pass a number between 0 or 1, which will be interpreted as randomly capturing traces that percent of a time. (Specifying this as a number rather than a function that invokes Math.random means that a future version of Apollo Server and Studio could include this number in the usage report and use it to let you view an estimate for total field executions based on using the number as a scale; this is however not yet implemented.) Since this may provide a common use case for running a GraphQL server without any need for per-field instrumentation, the request pipeline now only instruments the schema if it ever sees a willResolveField callback. This *almost* means that if you're running a monolithic server with captureTraces always returning false (or usage reporting disabled), or if you're running a subgraph whose gateway has captureTraces:false (and thus never receives a request with the `apollo-federation-include-trace` header), then execution won't have the small performance impact of instrumentation. In practice you need to also disable the cache control plugin to get this speedup, as it is installed by default and uses willResolveField to implement dynamic cache control. If this optimization proves to be important we can provide a mode of the cache control plugin that doesn't allow for dynamic cache control. (Alternatively we may eventually find a way to support the instrumentation of GraphQL execution with lower overhead.) Part of #5708.
- Loading branch information