Skip to content

Commit

Permalink
fix(otlp-exporter-base): fix unhandled error when writing to destroye…
Browse files Browse the repository at this point in the history
…d http request (#5163)
  • Loading branch information
pichlermarc authored Nov 18, 2024
1 parent d3630af commit 9e4d36c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
2 changes: 1 addition & 1 deletion experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ All notable changes to experimental packages in this project will be documented
### :bug: (Bug Fix)

* fix(instrumentation-http): Fix the `OTEL_SEMCONV_STABILITY_OPT_IN` variable check. Using `of` instead of `in` [#5137](https://github.com/open-telemetry/opentelemetry-js/pull/5137)

* fix(instrumentation-http): drop url.parse in favor of URL constructor [#5091](https://github.com/open-telemetry/opentelemetry-js/pull/5091) @pichlermarc
* fixes a bug where using cyrillic characters in a client request string URL would throw an exception, whereas an un-instrumented client would accept the same input without throwing an exception
* fix(otlp-exporter-base): fix unhandled error when writing to destroyed http request [#5163](https://github.com/open-telemetry/opentelemetry-js/pull/5163) @pichlermarc

### :books: (Refine Doc)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export function sendWithHttp(
});
}

function compressAndSend(
export function compressAndSend(
req: http.ClientRequest,
compression: 'gzip' | 'none',
data: Uint8Array,
Expand All @@ -127,7 +127,7 @@ function compressAndSend(
.on('error', onError);
}

dataStream.pipe(req);
dataStream.pipe(req).on('error', onError);
}

function readableFromUint8Array(buff: string | Uint8Array): Readable {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as http from 'http';
import * as assert from 'assert';
import { compressAndSend } from '../../src/platform/node/http-transport-utils';

describe('compressAndSend', function () {
it('compressAndSend on destroyed request should handle error', function (done) {
const request = http.request({});
request.destroy();
compressAndSend(request, 'gzip', Buffer.from([1, 2, 3]), error => {
try {
assert.match(error.message, /socket hang up/);
done();
} catch (e) {
done(e);
}
});
});
});

0 comments on commit 9e4d36c

Please sign in to comment.