Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make debugPrintReports mildly more useful #4805

Merged
merged 1 commit into from
Dec 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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