Skip to content

Commit

Permalink
Capture non-ftv1 errors in metrics (#2242)
Browse files Browse the repository at this point in the history
This commit precedes apollographql/apollo-server#7136

For the mentioned PR (full context within), the gateway needs to capture error information from subgraphs with no trace data separately and report them within the metrics object that's shared with the inline trace plugin.

This change only takes effect for subgraphs with no ftv1 support or when fieldLevelInstrumentation on the inline trace plugin is set to 0 or returns 0.
  • Loading branch information
trevor-scheer authored Jan 25, 2023
1 parent 5beba1d commit de89708
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 43 deletions.
12 changes: 12 additions & 0 deletions .changeset/large-hornets-watch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"@apollo/gateway": patch
---

Capture non-ftv1 error information in metrics data. This
error information allows the inline trace plugin to correctly
aggregate stats about errors (where no federated trace data
is available) and stop reporting incomplete traces which
are missing unavailable error information.

This PR is a precursor to apollographql/apollo-server#7136

2 changes: 1 addition & 1 deletion gateway-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@apollo/composition": "2.3.0",
"@apollo/federation-internals": "2.3.0",
"@apollo/query-planner": "2.3.0",
"@apollo/server-gateway-interface": "^1.0.2",
"@apollo/server-gateway-interface": "^1.1.0",
"@apollo/usage-reporting-protobuf": "^4.0.0",
"@apollo/utils.createhash": "^1.1.0",
"@apollo/utils.fetcher": "^1.1.0",
Expand Down
1 change: 1 addition & 0 deletions gateway-js/src/__tests__/executeQueryPlan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ describe('executeQueryPlan', () => {
request: {
variables: {},
},
metrics: {},
};
}

Expand Down
12 changes: 12 additions & 0 deletions gateway-js/src/executeQueryPlan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,18 @@ async function executeFetch(
downstreamServiceError(error, fetch.serviceName, errorPathHelper),
);
context.errors.push(...errors);

if (!response.extensions?.ftv1) {
const errorPaths = response.errors.map((error) => ({
subgraph: fetch.serviceName,
path: error.path,
}));
if (context.requestContext.metrics.nonFtv1ErrorPaths) {
context.requestContext.metrics.nonFtv1ErrorPaths.push(...errorPaths);
} else {
context.requestContext.metrics.nonFtv1ErrorPaths = errorPaths;
}
}
}

// If we're capturing a trace for Studio, save the received trace into the
Expand Down
150 changes: 108 additions & 42 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit de89708

Please sign in to comment.