1 | const protobuf = require('./protobuf');
|
2 | const protobufJS = require('@apollo/protobufjs/minimal');
|
3 |
|
4 | // Remove Long support. Our uint64s tend to be small (less
|
5 | // than 104 days).
|
6 | // https://github.com/protobufjs/protobuf.js/issues/1253
|
7 | protobufJS.util.Long = undefined;
|
8 | protobufJS.configure();
|
9 |
|
10 | // Override the generated protobuf Traces.encode function so that it will look
|
11 | // for Traces that are already encoded to Buffer as well as unencoded
|
12 | // Traces. This amortizes the protobuf encoding time over each generated Trace
|
13 | // instead of bunching it all up at once at sendReport time. In load tests, this
|
14 | // change improved p99 end-to-end HTTP response times by a factor of 11 without
|
15 | // a casually noticeable effect on p50 times. This also makes it easier for us
|
16 | // to implement maxUncompressedReportSize as we know the encoded size of traces
|
17 | // as we go.
|
18 | const originalTracesAndStatsEncode = protobuf.TracesAndStats.encode;
|
19 | protobuf.TracesAndStats.encode = function(message, originalWriter) {
|
20 | const writer = originalTracesAndStatsEncode(message, originalWriter);
|
21 | const encodedTraces = message.encodedTraces;
|
22 | if (encodedTraces != null && encodedTraces.length) {
|
23 | for (let i = 0; i < encodedTraces.length; ++i) {
|
24 | writer.uint32(/* id 1, wireType 2 =*/ 10);
|
25 | writer.bytes(encodedTraces[i]);
|
26 | }
|
27 | }
|
28 | return writer;
|
29 | };
|
30 |
|
31 | module.exports = protobuf;
|