Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.reportHeaders[schemaHash] = new ReportHeader({
...serviceHeaderDefaults,
schemaHash,
schemaTag:
this.options.schemaTag || process.env.ENGINE_SCHEMA_TAG || '',
});
// initializes this.reports[reportHash]
this.resetReport(schemaHash);
}
const report = this.reports[schemaHash];
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(
public format(): [string, string] | undefined {
if (!this.enabled) {
return;
}
if (this.done) {
throw Error('format called twice?');
}
// We record the end time at the latest possible time: right before serializing the trace.
// If we wait any longer, the time we record won't actually be sent anywhere!
this.treeBuilder.stopTiming();
this.done = true;
const encodedUint8Array = Trace.encode(this.treeBuilder.trace).finish();
const encodedBuffer = Buffer.from(
encodedUint8Array,
encodedUint8Array.byteOffset,
encodedUint8Array.byteLength,
);
return ['ftv1', encodedBuffer.toString('base64')];
}
}