Skip to content

Commit

Permalink
fix(otlp-exporter-base): fix handling of destroyed requests (#4929)
Browse files Browse the repository at this point in the history
  • Loading branch information
pichlermarc authored Aug 21, 2024
1 parent 583154c commit cd4e2bf
Show file tree
Hide file tree
Showing 4 changed files with 333 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -576,10 +576,14 @@ describe('export - real http request destroyed before response received', () =>

setTimeout(() => {
collectorExporter.export(spans, result => {
assert.strictEqual(result.code, core.ExportResultCode.FAILED);
const error = result.error as OTLPExporterError;
assert.ok(error !== undefined);
assert.strictEqual(error.message, 'Request Timeout');
try {
assert.strictEqual(result.code, core.ExportResultCode.FAILED);
const error = result.error as OTLPExporterError;
assert.ok(error !== undefined);
assert.strictEqual(error.message, 'Request Timeout');
} catch (e) {
done(e);
}
done();
});
}, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,13 @@ import {
} from '../../is-export-retryable';
import { OTLPExporterError } from '../../types';

export const DEFAULT_EXPORT_INITIAL_BACKOFF = 1000;
export const DEFAULT_EXPORT_MAX_BACKOFF = 5000;
export const DEFAULT_EXPORT_BACKOFF_MULTIPLIER = 1.5;

/**
* Sends data using http
* @param params
* @param agent
* @param data
* @param onDone
* @param timeoutMillis
*/
export function sendWithHttp(
params: HttpRequestParameters,
Expand Down Expand Up @@ -64,9 +61,6 @@ export function sendWithHttp(
res.on('data', chunk => responseData.push(chunk));

res.on('end', () => {
if (req.destroyed) {
return;
}
if (res.statusCode && res.statusCode < 299) {
onDone({
status: 'success',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as url from 'url';
import * as http from 'http';
import * as https from 'https';
import { OTLPExporterNodeConfigBase } from '.';
import { diag } from '@opentelemetry/api';

import { CompressionAlgorithm } from './types';
import { getEnv } from '@opentelemetry/core';

export function createHttpAgent(
config: OTLPExporterNodeConfigBase
): http.Agent | https.Agent | undefined {
if (config.httpAgentOptions && config.keepAlive === false) {
diag.warn('httpAgentOptions is used only when keepAlive is true');
return undefined;
}

if (config.keepAlive === false || !config.url) return undefined;

try {
const parsedUrl = new url.URL(config.url as string);
const Agent = parsedUrl.protocol === 'http:' ? http.Agent : https.Agent;
return new Agent({ keepAlive: true, ...config.httpAgentOptions });
} catch (err) {
diag.error(
`collector exporter failed to create http agent. err: ${err.message}`
);
return undefined;
}
}

export function configureCompression(
compression: CompressionAlgorithm | undefined
): CompressionAlgorithm {
Expand Down
Loading

0 comments on commit cd4e2bf

Please sign in to comment.