From c24ae5a99e9616fc0f12580be4da7e215b1ef195 Mon Sep 17 00:00:00 2001 From: Onur Temizkan Date: Wed, 28 Sep 2022 19:50:27 +0100 Subject: [PATCH 1/2] fix(tracing): Warn if `resolvers` is not defined in `ApolloServer` config. --- .../tracing/src/integrations/node/apollo.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/tracing/src/integrations/node/apollo.ts b/packages/tracing/src/integrations/node/apollo.ts index 90ebbf889777..f0351b334dd8 100644 --- a/packages/tracing/src/integrations/node/apollo.ts +++ b/packages/tracing/src/integrations/node/apollo.ts @@ -43,7 +43,22 @@ export class Apollo implements Integration { * Iterate over resolvers of the ApolloServer instance before schemas are constructed. */ fill(pkg.ApolloServerBase.prototype, 'constructSchema', function (orig: () => unknown) { - return function (this: { config: { resolvers: ApolloModelResolvers[] } }) { + return function (this: { config: { resolvers?: ApolloModelResolvers[]; schema?: unknown; modules?: unknown } }) { + if (!this.config.resolvers) { + if (this.config.schema) { + logger.warn( + 'Apollo integration is not able to trace `ApolloServer` instances constructed via `schema` property.', + ); + } else if (this.config.modules) { + logger.warn( + 'Apollo integration is not able to trace `ApolloServer` instances constructed via `modules` property.', + ); + } + + logger.error('Skipping tracing as no resolvers found on the `ApolloServer` instance.'); + return orig.call(this); + } + const resolvers = arrayify(this.config.resolvers); this.config.resolvers = resolvers.map(model => { From efa7eb182f12dd11fe0493834b2f6b93a8230ee5 Mon Sep 17 00:00:00 2001 From: Onur Temizkan Date: Wed, 28 Sep 2022 21:02:00 +0100 Subject: [PATCH 2/2] Add `__DEBUG_BUILD__` flags to Apollo / GraphQL integration logs. --- .../tracing/src/integrations/node/apollo.ts | 23 +++++++++++-------- .../tracing/src/integrations/node/graphql.ts | 2 +- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/packages/tracing/src/integrations/node/apollo.ts b/packages/tracing/src/integrations/node/apollo.ts index f0351b334dd8..5046a1445d44 100644 --- a/packages/tracing/src/integrations/node/apollo.ts +++ b/packages/tracing/src/integrations/node/apollo.ts @@ -35,7 +35,7 @@ export class Apollo implements Integration { }>('apollo-server-core'); if (!pkg) { - logger.error('Apollo Integration was unable to require apollo-server-core package.'); + __DEBUG_BUILD__ && logger.error('Apollo Integration was unable to require apollo-server-core package.'); return; } @@ -45,17 +45,20 @@ export class Apollo implements Integration { fill(pkg.ApolloServerBase.prototype, 'constructSchema', function (orig: () => unknown) { return function (this: { config: { resolvers?: ApolloModelResolvers[]; schema?: unknown; modules?: unknown } }) { if (!this.config.resolvers) { - if (this.config.schema) { - logger.warn( - 'Apollo integration is not able to trace `ApolloServer` instances constructed via `schema` property.', - ); - } else if (this.config.modules) { - logger.warn( - 'Apollo integration is not able to trace `ApolloServer` instances constructed via `modules` property.', - ); + if (__DEBUG_BUILD__) { + if (this.config.schema) { + logger.warn( + 'Apollo integration is not able to trace `ApolloServer` instances constructed via `schema` property.', + ); + } else if (this.config.modules) { + logger.warn( + 'Apollo integration is not able to trace `ApolloServer` instances constructed via `modules` property.', + ); + } + + logger.error('Skipping tracing as no resolvers found on the `ApolloServer` instance.'); } - logger.error('Skipping tracing as no resolvers found on the `ApolloServer` instance.'); return orig.call(this); } diff --git a/packages/tracing/src/integrations/node/graphql.ts b/packages/tracing/src/integrations/node/graphql.ts index 1f16c7a69e41..099c4f84120d 100644 --- a/packages/tracing/src/integrations/node/graphql.ts +++ b/packages/tracing/src/integrations/node/graphql.ts @@ -23,7 +23,7 @@ export class GraphQL implements Integration { }>('graphql/execution/execute.js'); if (!pkg) { - logger.error('GraphQL Integration was unable to require graphql/execution package.'); + __DEBUG_BUILD__ && logger.error('GraphQL Integration was unable to require graphql/execution package.'); return; }