Skip to content

Commit 91ce78d

Browse files
pichlermarcZirak
authored andcommitted
fix(otlp-exporter-base): fix handling of destroyed requests (open-telemetry#4929)
1 parent e392adc commit 91ce78d

File tree

4 files changed

+333
-38
lines changed

4 files changed

+333
-38
lines changed

experimental/packages/exporter-trace-otlp-http/test/node/CollectorTraceExporter.test.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -576,10 +576,14 @@ describe('export - real http request destroyed before response received', () =>
576576

577577
setTimeout(() => {
578578
collectorExporter.export(spans, result => {
579-
assert.strictEqual(result.code, core.ExportResultCode.FAILED);
580-
const error = result.error as OTLPExporterError;
581-
assert.ok(error !== undefined);
582-
assert.strictEqual(error.message, 'Request Timeout');
579+
try {
580+
assert.strictEqual(result.code, core.ExportResultCode.FAILED);
581+
const error = result.error as OTLPExporterError;
582+
assert.ok(error !== undefined);
583+
assert.strictEqual(error.message, 'Request Timeout');
584+
} catch (e) {
585+
done(e);
586+
}
583587
done();
584588
});
585589
}, 0);

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,13 @@ import {
2525
} from '../../is-export-retryable';
2626
import { OTLPExporterError } from '../../types';
2727

28-
export const DEFAULT_EXPORT_INITIAL_BACKOFF = 1000;
29-
export const DEFAULT_EXPORT_MAX_BACKOFF = 5000;
30-
export const DEFAULT_EXPORT_BACKOFF_MULTIPLIER = 1.5;
31-
3228
/**
3329
* Sends data using http
3430
* @param params
3531
* @param agent
3632
* @param data
3733
* @param onDone
34+
* @param timeoutMillis
3835
*/
3936
export function sendWithHttp(
4037
params: HttpRequestParameters,
@@ -64,9 +61,6 @@ export function sendWithHttp(
6461
res.on('data', chunk => responseData.push(chunk));
6562

6663
res.on('end', () => {
67-
if (req.destroyed) {
68-
return;
69-
}
7064
if (res.statusCode && res.statusCode < 299) {
7165
onDone({
7266
status: 'success',

experimental/packages/otlp-exporter-base/src/platform/node/util.ts

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,36 +13,10 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
import * as url from 'url';
17-
import * as http from 'http';
18-
import * as https from 'https';
19-
import { OTLPExporterNodeConfigBase } from '.';
20-
import { diag } from '@opentelemetry/api';
16+
2117
import { CompressionAlgorithm } from './types';
2218
import { getEnv } from '@opentelemetry/core';
2319

24-
export function createHttpAgent(
25-
config: OTLPExporterNodeConfigBase
26-
): http.Agent | https.Agent | undefined {
27-
if (config.httpAgentOptions && config.keepAlive === false) {
28-
diag.warn('httpAgentOptions is used only when keepAlive is true');
29-
return undefined;
30-
}
31-
32-
if (config.keepAlive === false || !config.url) return undefined;
33-
34-
try {
35-
const parsedUrl = new url.URL(config.url as string);
36-
const Agent = parsedUrl.protocol === 'http:' ? http.Agent : https.Agent;
37-
return new Agent({ keepAlive: true, ...config.httpAgentOptions });
38-
} catch (err) {
39-
diag.error(
40-
`collector exporter failed to create http agent. err: ${err.message}`
41-
);
42-
return undefined;
43-
}
44-
}
45-
4620
export function configureCompression(
4721
compression: CompressionAlgorithm | undefined
4822
): CompressionAlgorithm {

0 commit comments

Comments
 (0)