Skip to content

Commit 3bf1284

Browse files
authored
feat(otlp-exporter-base): add http response body to exporter error (#5204)
1 parent 561f8ad commit 3bf1284

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

experimental/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ All notable changes to experimental packages in this project will be documented
2525
* feat(otlp-exporter-base): internally accept a http header provider function only [#5179](https://github.com/open-telemetry/opentelemetry-js/pull/5179) @pichlermarc
2626
* refactor(otlp-exporter-base): don't create blob before sending xhr [#5193](https://github.com/open-telemetry/opentelemetry-js/pull/5193) @pichlermarc
2727
* improves compatibility with some unsupported runtimes
28+
* feat(otlp-exporter-base): add http response body to exporter error [#5204](https://github.com/open-telemetry/opentelemetry-js/pull/5204) @pichlermarc
2829

2930
### :bug: (Bug Fix)
3031

experimental/packages/otlp-exporter-base/src/transport/http-transport-utils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ export function sendWithHttp(
7272
retryInMillis: parseRetryAfterToMills(res.headers['retry-after']),
7373
});
7474
} else {
75-
const error = new OTLPExporterError(res.statusMessage, res.statusCode);
75+
const error = new OTLPExporterError(
76+
res.statusMessage,
77+
res.statusCode,
78+
Buffer.concat(responseData).toString()
79+
);
7680
onDone({
7781
status: 'failure',
7882
error,

experimental/packages/otlp-exporter-base/test/node/http-exporter-transport.test.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
ExportResponseRetryable,
2323
ExportResponseFailure,
2424
ExportResponseSuccess,
25+
OTLPExporterError,
2526
} from '../../src';
2627
import * as zlib from 'zlib';
2728

@@ -123,7 +124,7 @@ describe('HttpExporterTransport', function () {
123124
// arrange
124125
server = http.createServer((_, res) => {
125126
res.statusCode = 404;
126-
res.end();
127+
res.end('response-body');
127128
});
128129
server.listen(8080);
129130

@@ -143,6 +144,14 @@ describe('HttpExporterTransport', function () {
143144
(result as ExportResponseFailure).error.message,
144145
'Not Found'
145146
);
147+
assert.strictEqual(
148+
((result as ExportResponseFailure).error as OTLPExporterError).data,
149+
'response-body'
150+
);
151+
assert.strictEqual(
152+
((result as ExportResponseFailure).error as OTLPExporterError).code,
153+
404
154+
);
146155
});
147156

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

0 commit comments

Comments
 (0)