Skip to content

Commit ec88f76

Browse files
committed
fix(exporter-collector): node8 compatibility fix for exporter gzip compression
1 parent 62a34ee commit ec88f76

File tree

1 file changed

+11
-13
lines changed
  • packages/opentelemetry-exporter-collector/src/platform/node

1 file changed

+11
-13
lines changed

packages/opentelemetry-exporter-collector/src/platform/node/util.ts

+11-13
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import * as url from 'url';
1717
import * as http from 'http';
1818
import * as https from 'https';
1919
import * as zlib from 'zlib';
20-
import { pipeline, Readable } from 'stream';
20+
import { Readable } from 'stream';
2121
import * as collectorTypes from '../../types';
2222
import { CollectorExporterNodeBase } from './CollectorExporterNodeBase';
2323
import { CollectorExporterNodeConfigBase } from '.';
@@ -83,26 +83,24 @@ export function sendWithHttp<ExportItem, ServiceRequest>(
8383
});
8484

8585
if (compress) {
86-
const dataStream = Readable.from(data);
87-
pipeline(dataStream, gzip, req, onGzipError(onError));
86+
const dataStream = readableFromBuffer(data);
87+
dataStream.on('error', onError)
88+
.pipe(gzip).on('error', onError)
89+
.pipe(req);
8890
} else {
8991
req.write(data);
9092
req.end();
9193
}
9294
}
9395

94-
function onGzipError(onError: (error: collectorTypes.CollectorExporterError) => void) {
95-
return (err: NodeJS.ErrnoException | null) => {
96-
const error = new collectorTypes.CollectorExporterError(
97-
err?.message,
98-
500,
99-
'Compressing the request body for collector exporter failed.'
100-
);
101-
onError(error)
102-
}
96+
function readableFromBuffer(buff: string | Buffer): Readable {
97+
const readable = new Readable();
98+
readable.push(buff);
99+
readable.push(null);
100+
101+
return readable;
103102
}
104103

105-
106104
export function createHttpAgent(
107105
config: CollectorExporterNodeConfigBase
108106
): http.Agent | https.Agent | undefined {

0 commit comments

Comments
 (0)