Skip to content

Commit bc50c7b

Browse files
authored
feat: lazy initialization of the gzip stream (#2581)
1 parent 1abda14 commit bc50c7b

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

experimental/packages/opentelemetry-exporter-trace-otlp-http/src/platform/node/OTLPExporterNodeBase.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,7 @@ export abstract class OTLPExporterNodeBase<
9090
promise.then(popPromise, popPromise);
9191
}
9292

93+
// TODO: end gzip stream from util.ts if not undefined
94+
// It should perhaps be a class member here instead of a variable in util.ts
9395
onShutdown(): void {}
9496
}

experimental/packages/opentelemetry-exporter-trace-otlp-http/src/platform/node/util.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { OTLPExporterNodeConfigBase } from '.';
2424
import { diag } from '@opentelemetry/api';
2525
import { CompressionAlgorithm } from './types';
2626

27-
const gzip = zlib.createGzip();
27+
let gzip: zlib.Gzip | undefined;
2828

2929
/**
3030
* Sends data using http
@@ -83,6 +83,9 @@ export function sendWithHttp<ExportItem, ServiceRequest>(
8383

8484
switch (collector.compression) {
8585
case CompressionAlgorithm.GZIP: {
86+
if (!gzip) {
87+
gzip = zlib.createGzip();
88+
}
8689
req.setHeader('Content-Encoding', 'gzip');
8790
const dataStream = readableFromBuffer(data);
8891
dataStream.on('error', onError)

0 commit comments

Comments
 (0)