Skip to content

Commit

Permalink
fix(exporter-collector): node8 compatibility fix for exporter gzip co…
Browse files Browse the repository at this point in the history
…mpression
  • Loading branch information
alisabzevari committed Jul 8, 2021
1 parent 4c91cfb commit 508f7e8
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions packages/opentelemetry-exporter-collector/src/platform/node/util.ts
Expand Up @@ -17,7 +17,7 @@ import * as url from 'url';
import * as http from 'http';
import * as https from 'https';
import * as zlib from 'zlib';
import { pipeline, Readable } from 'stream';
import { Readable } from 'stream';
import * as collectorTypes from '../../types';
import { CollectorExporterNodeBase } from './CollectorExporterNodeBase';
import { CollectorExporterNodeConfigBase } from '.';
Expand Down Expand Up @@ -83,26 +83,24 @@ export function sendWithHttp<ExportItem, ServiceRequest>(
});

if (compress) {
const dataStream = Readable.from(data);
pipeline(dataStream, gzip, req, onGzipError(onError));
const dataStream = readableFromBuffer(data);
dataStream.on('error', onError)
.pipe(gzip).on('error', onError)
.pipe(req);
} else {
req.write(data);
req.end();
}
}

function onGzipError(onError: (error: collectorTypes.CollectorExporterError) => void) {
return (err: NodeJS.ErrnoException | null) => {
const error = new collectorTypes.CollectorExporterError(
err?.message,
500,
'Compressing the request body for collector exporter failed.'
);
onError(error)
}
function readableFromBuffer(buff: string | Buffer): Readable {
const readable = new Readable();
readable.push(buff);
readable.push(null);

return readable;
}


export function createHttpAgent(
config: CollectorExporterNodeConfigBase
): http.Agent | https.Agent | undefined {
Expand Down

0 comments on commit 508f7e8

Please sign in to comment.