Skip to content

Commit

Permalink
add toggle for including error messages in reports
Browse files Browse the repository at this point in the history
We always send traces that includes an error node if the trace has an
error. In the case that sending errors is disabled, we replace the
message and remove the location.
  • Loading branch information
Evans Hauser committed Sep 4, 2018
1 parent b80a8f0 commit 11bab34
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
4 changes: 4 additions & 0 deletions docs/source/api/apollo-server.md
Expand Up @@ -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.

* `sendErrorTraces`: boolean

To remove errors from traces, set this to false. Defaults to true
8 changes: 5 additions & 3 deletions packages/apollo-engine-reporting/src/agent.ts
Expand Up @@ -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
Expand All @@ -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 errors from traces, set this to false. Defaults to true
sendErrorTraces?: 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
Expand Down
30 changes: 20 additions & 10 deletions packages/apollo-engine-reporting/src/extension.ts
Expand Up @@ -43,7 +43,10 @@ export class EngineReportingExtension<TContext = any>
options: EngineReportingOptions,
addTrace: (signature: string, operationName: string, trace: Trace) => void,
) {
this.options = options;
this.options = {
sendErrorTraces: true,
...options,
};
this.addTrace = addTrace;
const root = new Trace.Node();
this.trace.root = root;
Expand Down Expand Up @@ -225,15 +228,22 @@ export class EngineReportingExtension<TContext = any>
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),
}),
);

// With noErrorTraces, the Engine proxy strips all error information
// from the traces and sends error counts inside of the aggregated stats
// reports. To get similar behavior inside of the apollo server metrics
// reporting, we always send a trace and mask out the PII
const errorInfo = this.options.sendErrorTraces
? {
message: error.message,
location: (error.locations || []).map(
({ line, column }) => new Trace.Location({ line, column }),
),
json: JSON.stringify(error),
}
: { message: 'Masked by Apollo Engine Reporting' };

node!.error!.push(new Trace.Error(errorInfo));
});
}
}
Expand Down

0 comments on commit 11bab34

Please sign in to comment.