Skip to content

Commit

Permalink
Make debugPrintReports mildly more useful (#4805)
Browse files Browse the repository at this point in the history
  • Loading branch information
glasser authored Dec 22, 2020
1 parent d0a32c9 commit 624c283
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/source/api/plugin/usage-reporting.md
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ The URL base that the plugin sends reports to (not including the path). This opt
</td>
<td>

If set, prints all reports as JSON when they are sent. (Note that this feature is not as useful as it might sound, because for technical reasons it currently does not include the actual traces.)
If set, prints all reports as JSON when they are sent. (Note that for technical reasons, traces embedded in a report are printed separately when they are added to a report.)
</td>
</tr>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ export interface ApolloServerPluginUsageReportingOptions<TContext> {
*/
endpointUrl?: string;
/**
* If set, prints all reports as JSON when they are sent. (Note that this
* feature is not as useful as it may sound because for technical reasons
* it currently does not include the actual traces.)
* If set, prints all reports as JSON when they are sent. (Note that for
* technical reasons, traces embedded in a report are printed separately when
* they are added to a report.)
*/
debugPrintReports?: boolean;
/**
Expand Down
18 changes: 12 additions & 6 deletions packages/apollo-server-core/src/plugin/usageReporting/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,9 @@ export function ApolloServerPluginUsageReporting<TContext>(
// `debugPrintReports`) just to reach the level of verbosity to
// produce the output would be a breaking change. The "warn" level is
// on by default. There is a similar theory and comment applied
// below. (Note that this feature is not as useful as it may sound
// because it currently does not include the actual traces which are
// "pre-encoded" and not accessible to `toJSON`.)
// below. (Note that the actual traces are "pre-encoded" and not
// accessible to `toJSON` but we do print them separately when we
// encode them.)
logger.warn(
`Apollo usage report: ${JSON.stringify(report.toJSON())}`,
);
Expand Down Expand Up @@ -483,9 +483,7 @@ export function ApolloServerPluginUsageReporting<TContext>(
}

if (statsReportKey) {
if (
options.sendUnexecutableOperationDocuments
) {
if (options.sendUnexecutableOperationDocuments) {
treeBuilder.trace.unexecutedOperationBody =
requestContext.source;
treeBuilder.trace.unexecutedOperationName = operationName;
Expand Down Expand Up @@ -515,6 +513,14 @@ export function ApolloServerPluginUsageReporting<TContext>(
reportData.size +=
encodedTrace.length + Buffer.byteLength(statsReportKey);

if (options.debugPrintReports) {
logger.warn(
`Apollo usage report trace: ${JSON.stringify(
treeBuilder.trace.toJSON(),
)}`,
);
}

// If the buffer gets big (according to our estimate), send.
if (
sendReportsImmediately ||
Expand Down

0 comments on commit 624c283

Please sign in to comment.