Skip to content

Commit

Permalink
perf: lazy initialization of the gzip stream
Browse files Browse the repository at this point in the history
  • Loading branch information
fungiboletus authored Nov 2, 2021
1 parent 4e311bd commit e1ff0fd
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ import { OTLPExporterNodeConfigBase } from '.';
import { diag } from '@opentelemetry/api';
import { CompressionAlgorithm } from './types';

const gzip = zlib.createGzip();

let gzip: zlib.Gzip | undefined;
/**
* Sends data using http
* @param collector
Expand Down Expand Up @@ -83,6 +82,9 @@ export function sendWithHttp<ExportItem, ServiceRequest>(

switch (collector.compression) {
case CompressionAlgorithm.GZIP: {
if (!gzip) {
gzip = zlib.createGzip();
}
req.setHeader('Content-Encoding', 'gzip');
const dataStream = readableFromBuffer(data);
dataStream.on('error', onError)
Expand Down

0 comments on commit e1ff0fd

Please sign in to comment.