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

Apollo Gateway Errors on Subgraphs #4971

Open
dazlious opened this issue Dec 5, 2024 · 0 comments
Open

Apollo Gateway Errors on Subgraphs #4971

dazlious opened this issue Dec 5, 2024 · 0 comments

Comments

@dazlious
Copy link

dazlious commented Dec 5, 2024

Currently I am experiencing a behaviour I did not expect.

While I instrument all my subgraphs as well as the supergraph, I am seeing an unexpected behaviour in the apollo instrumentation.

on subgraphs and supergraphs we have implemented the following:

import{ tracer, Span } from 'dd-trace';

const BAD_USER_INPUT = 'BAD_USER_INPUT';
const NOT_AUTHORIZED = 'NOT_AUTHORIZED';
const USER_ALREADY_EXISTS = 'USER_ALREADY_EXISTS';

const notLoggableErrors = new Set([
  BAD_USER_INPUT,
  NOT_AUTHORIZED,
  USER_ALREADY_EXISTS,
]);

const isErrorLoggable = error => !notLoggableErrors.has(error?.extensions?.code);

tracer.init({
  plugins: false,
  runtimeMetrics: true,
  service: config.datadog.service,
});

tracer.use('graphql', {
  variables: variables => variables,
  hooks: {
    execute(span, _, res) {
      if (span && res.errors?.length) {
        const isError = res.errors.some(error => isErrorLoggable(error));
        span.setTag('error', isError);
      }
    },
  },
});

Reading about apollo instrumentation it says it is automatically added whenever the condition (Currently this plugin automatically instruments [@apollo/gateway](https://github.com/apollographql/federation) for module versions >= v2.3.0.) is true. Therefore I am able to see the instrumentation on our APM dashboard.

Now the big problem I have is that while I can hook into the graphql instrumentation, I cannot hook into the apollo one. I only see an ability to disable it, which is not what I want.

Am I missing something? How easy would it be to add something similar to apollo? From code perspective it looks like the error is being set based upon the last entry: https://github.com/DataDog/dd-trace-js/blob/master/packages/datadog-plugin-apollo/src/gateway/validate.js#L19

I would also be able to contribute here, if someone would guide me in the right direction.

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