Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(otlp-exporter-base): add http response body to exporter error #5204

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
maryliag marked this conversation as resolved.
Show resolved Hide resolved
);
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