diff --git a/CHANGELOG.md b/CHANGELOG.md index 326c2313773..4ee20fb870e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ All of the packages in the `apollo-server` repo are released with the same versi - Update `graphql-playground-html` to 1.7.4 [#1586](https://github.com/apollographql/apollo-server/pull/1586) - Add support for `graphql-js` v14 by augmenting typeDefs with the `@cacheControl` directive so SDL validation doesn't fail [#1595](https://github.com/apollographql/apollo-server/pull/1595) - Add `node-fetch` extensions typing to `RequestInit` [#1602](https://github.com/apollographql/apollo-server/pull/1602) +- Add toggle for including error messages in reports [#1615](https://github.com/apollographql/apollo-server/pull/1615) - Fix `apollo-server-cloud-functions` tests [#1611](https://github.com/apollographql/apollo-server/pull/1611/) ### v2.0.5 diff --git a/docs/source/api/apollo-server.md b/docs/source/api/apollo-server.md index 36fdc322e0c..3c2ddfcffe4 100644 --- a/docs/source/api/apollo-server.md +++ b/docs/source/api/apollo-server.md @@ -344,3 +344,7 @@ addMockFunctionsToSchema({ itself. Set this to false to disable. You can manually invoke 'stop()' and 'sendReport()' on other signals if you'd like. Note that 'sendReport()' does not run synchronously so it cannot work usefully in an 'exit' handler. + +* `maskErrorDetails`: boolean + + Set to true to remove error details from the traces sent to Apollo's servers. Defaults to false. diff --git a/packages/apollo-engine-reporting/src/agent.ts b/packages/apollo-engine-reporting/src/agent.ts index 1e3e6a48df1..fa655624215 100644 --- a/packages/apollo-engine-reporting/src/agent.ts +++ b/packages/apollo-engine-reporting/src/agent.ts @@ -60,9 +60,9 @@ export interface EngineReportingOptions { maxAttempts?: number; // Minimum backoff for retries. Defaults to 100ms. minimumRetryDelayMs?: number; - // By default, errors sending reports to Engine servers will be logged - // to standard error. Specify this function to process errors in a different - // way. + // By default, errors that occur when sending trace reports to Engine servers + // will be logged to standard error. Specify this function to process errors + // in a different way. reportErrorFunction?: (err: Error) => void; // A case-sensitive list of names of variables whose values should not be sent // to Apollo servers, or 'true' to leave out all variables. In the former @@ -81,6 +81,8 @@ export interface EngineReportingOptions { handleSignals?: boolean; // Sends the trace report immediately. This options is useful for stateless environments sendReportsImmediately?: boolean; + // To remove the error message from traces, set this to true. Defaults to false + maskErrorDetails?: boolean; // XXX Provide a way to set client_name, client_version, client_address, // service, and service_version fields. They are currently not revealed in the diff --git a/packages/apollo-engine-reporting/src/extension.ts b/packages/apollo-engine-reporting/src/extension.ts index 6cb73681a25..74a58efbfe2 100644 --- a/packages/apollo-engine-reporting/src/extension.ts +++ b/packages/apollo-engine-reporting/src/extension.ts @@ -43,7 +43,10 @@ export class EngineReportingExtension options: EngineReportingOptions, addTrace: (signature: string, operationName: string, trace: Trace) => void, ) { - this.options = options; + this.options = { + maskErrorDetails: false, + ...options, + }; this.addTrace = addTrace; const root = new Trace.Node(); this.trace.root = root; @@ -225,15 +228,19 @@ export class EngineReportingExtension node = specificNode; } } - node!.error!.push( - new Trace.Error({ - message: error.message, - location: (error.locations || []).map( - ({ line, column }) => new Trace.Location({ line, column }), - ), - json: JSON.stringify(error), - }), - ); + + // Always send the trace errors, so that the UI acknowledges that there is an error. + const errorInfo = this.options.maskErrorDetails + ? { message: '' } + : { + message: error.message, + location: (error.locations || []).map( + ({ line, column }) => new Trace.Location({ line, column }), + ), + json: JSON.stringify(error), + }; + + node!.error!.push(new Trace.Error(errorInfo)); }); } }