Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const protobufError = Trace.verify(trace);
if (protobufError) {
throw new Error(`Error encoding trace: ${protobufError}`);
}
const encodedTrace = Trace.encode(trace).finish();
const signature = await this.getTraceSignature({
queryHash,
documentAST,
queryString,
operationName,
});
const statsReportKey = `# ${operationName || '-'}\n${signature}`;
if (!report.tracesPerQuery.hasOwnProperty(statsReportKey)) {
report.tracesPerQuery[statsReportKey] = new Traces();
(report.tracesPerQuery[statsReportKey] as any).encodedTraces = [];
}
// See comment on our override of Traces.encode inside of
// apollo-engine-reporting-protobuf to learn more about this strategy.
(report.tracesPerQuery[statsReportKey] as any).encodedTraces.push(
encodedTrace,
);
this.reportSizes[schemaHash] +=
encodedTrace.length + Buffer.byteLength(statsReportKey);
// If the buffer gets big (according to our estimate), send.
if (
this.sendReportsImmediately ||
this.reportSizes[schemaHash] >=
(this.options.maxUncompressedReportSize || 4 * 1024 * 1024)
) {