Skip to content

Commit

Permalink
feat(otlp-exporter-base): add http response body to exporter error (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
pichlermarc authored Nov 27, 2024
1 parent 561f8ad commit 3bf1284
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ All notable changes to experimental packages in this project will be documented
* feat(otlp-exporter-base): internally accept a http header provider function only [#5179](https://github.com/open-telemetry/opentelemetry-js/pull/5179) @pichlermarc
* refactor(otlp-exporter-base): don't create blob before sending xhr [#5193](https://github.com/open-telemetry/opentelemetry-js/pull/5193) @pichlermarc
* improves compatibility with some unsupported runtimes
* feat(otlp-exporter-base): add http response body to exporter error [#5204](https://github.com/open-telemetry/opentelemetry-js/pull/5204) @pichlermarc

### :bug: (Bug Fix)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ export function sendWithHttp(
retryInMillis: parseRetryAfterToMills(res.headers['retry-after']),
});
} else {
const error = new OTLPExporterError(res.statusMessage, res.statusCode);
const error = new OTLPExporterError(
res.statusMessage,
res.statusCode,
Buffer.concat(responseData).toString()
);
onDone({
status: 'failure',
error,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
ExportResponseRetryable,
ExportResponseFailure,
ExportResponseSuccess,
OTLPExporterError,
} from '../../src';
import * as zlib from 'zlib';

Expand Down Expand Up @@ -123,7 +124,7 @@ describe('HttpExporterTransport', function () {
// arrange
server = http.createServer((_, res) => {
res.statusCode = 404;
res.end();
res.end('response-body');
});
server.listen(8080);

Expand All @@ -143,6 +144,14 @@ describe('HttpExporterTransport', function () {
(result as ExportResponseFailure).error.message,
'Not Found'
);
assert.strictEqual(
((result as ExportResponseFailure).error as OTLPExporterError).data,
'response-body'
);
assert.strictEqual(
((result as ExportResponseFailure).error as OTLPExporterError).code,
404
);
});

it('returns failure when request times out', function (done) {
Expand Down

0 comments on commit 3bf1284

Please sign in to comment.