Skip to content

Commit

Permalink
feat: lazy initialization of the gzip stream (#2581)
Browse files Browse the repository at this point in the history
  • Loading branch information
fungiboletus authored Nov 9, 2021
1 parent 1abda14 commit bc50c7b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,7 @@ export abstract class OTLPExporterNodeBase<
promise.then(popPromise, popPromise);
}

// TODO: end gzip stream from util.ts if not undefined
// It should perhaps be a class member here instead of a variable in util.ts
onShutdown(): void {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +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
Expand Down Expand Up @@ -83,6 +83,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 bc50c7b

Please sign in to comment.