Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto correlation not working in apollo-gateway #949

Open
fibsifan opened this issue Apr 20, 2022 · 1 comment
Open

Auto correlation not working in apollo-gateway #949

fibsifan opened this issue Apr 20, 2022 · 1 comment

Comments

@fibsifan
Copy link

We're trying to use request correlation in apollo gateway. We want to correlate federated graphql requests in order to identify slow subgraphs.

Here's what we did: We set up an apollo-gateway as described in the federation documentation. And before anything else is called, we configure the applicationinsights as described in the node.js documentation for application insights.

The whole thing looks a bit like this (authentication code is left out. we also set context tags for application insights and filter some requests from the tracing, left out for brevity):

const instrumentationKey = process.env.AI_INSTRUMENTATION_KEY;
appInsights
  .setup(instrumentationKey)
  .setAutoDependencyCorrelation(true)
  .setAutoCollectRequests(true)
  .setAutoCollectPerformance(false)
  .setAutoCollectExceptions(true)
  .setAutoCollectDependencies(true)
  .setAutoCollectConsole(false)
  .setUseDiskRetryCaching(true)
  .setDistributedTracingMode(DistributedTracingModes.AI_AND_W3C)
  .start();

const gateway = new ApolloGateway({
  supergraphSdl
});

const server = new ApolloServer({
  gateway
});

server
  .listen({ port: 3000 })
  .then(({ url }) => {
    console.log(`🚀 Gateway ready at ${url}`);
  });

Although we set AutoCollectRequests and AutoCollectDependencies and autoDependencyCorrelation to true and we're using W3C correlation, there is no correlation between the incoming requests to the gateway and incoming requests on the subgraph(s). The subgraphs get correlation headers on their incoming requests, but the traceId differs from the traceId that's reported by the apollo-gateway.

This issue becomes most visible, when looking at the azure application map. No requests between the apollo-gateway and the subgraphs can be observed, instead the subgraphs appear as external dependencies on the map.

When debugging through the applicationinsights code I can observe, that the error exists on the apollo gateway. The traceIds for the incoming and the outgoing request differ in AutoCollectHttpRequests.trackRequest in HttpRequest.ts (for the incoming request) and in AutoCollectHttpDependencies.trackRequest in HttpDependencies.ts (for the outgoing request). Consequently, the headers for the outgoing request (which the subgraph receives) contain an unrelated traceId and correlation is not performed in Azure monitor.

I have tested with DistributedTracingModes.AI and wasn't able to get the correlation to work either, although I didn't analyze the error through debugging in this case. I'm assuming the behaviour is very similar.

Is this a bug in ApplicationInsights-node.js or are we missing something in the configuration of the apollo gateway?

@fibsifan
Copy link
Author

seems related to #566

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant