Skip to content

New version of Apollo Server is not supported #6899

@vdyalex

Description

@vdyalex

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which package are you using?

@sentry/node

SDK Version

7.31.1

Framework Version

Apollo Server 4.3.1 (on @apollo/server)

Link to Sentry event

No response

SDK Setup

Setting file

const sentry = ({ config, db }: FastifyInstance): SentryPluginOptions => {
  // Get log level
  const log = config.get('log');
  const debug = getLogLevel(log) <= getLogLevel(LogLevel.DEBUG);

  // Get Sentry settings
  const { dsn, enabled, tracesSampleRate } = config.get('sentry');

  // Configure integrations
  const integrations = [
    new Integrations.Apollo(),
    new Integrations.Prisma({ client: db }),
  ];

  return {
    debug,
    dsn,
    enabled,
    integrations,
    tracesSampleRate,
  };
};

Plugin file

const pluggable: FastifyPluginAsync<SentryPluginOptions> = async (
  instance,
  opts,
) => {
  init(opts);

  const errorHandler = (error: FastifyError, request: FastifyRequest) => {
    const clientIp = requestIp.getClientIp(request);
    const user = {
      ip_address: clientIp ?? undefined,
    };

    const scopeHandler = (scope: Scope) => {
      scope.setUser(user);
      scope.setTag('path', request.raw.url);

      captureException(error);
    };

    withScope(scopeHandler);
  };

  instance.setErrorHandler(errorHandler);
};

export const SentryPlugin = plugin<SentryPluginOptions>(pluggable);

Steps to Reproduce

  1. After defining the whole stack (Fastify, Apollo Server)
  2. Install the latest Sentry Node SDK
  3. Configure the sentry environment variables with the correct DSN
  4. Try to connect the aforementioned plugin

Expected Result

Connect seamlessly using @apollo/server instead of apollo-server-core.

Actual Result

It throws the error:

Apollo Integration was unable to require apollo-server-core package

The reason is that the Apollo Server package is hardcoded into the SDK:
https://github.com/getsentry/sentry-javascript/blob/master/packages/tracing/src/integrations/node/apollo.ts#L42-L47

CleanShot 2023-01-23 at 07 07 06

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions