@opentelemetry/otlp-exporter-base
Advanced tools
Comparing version 0.28.0 to 0.29.0
@@ -11,2 +11,3 @@ import { SpanAttributes } from '@opentelemetry/api'; | ||
readonly attributes?: SpanAttributes; | ||
readonly timeoutMillis: number; | ||
protected _concurrencyLimit: number; | ||
@@ -13,0 +14,0 @@ protected _sendingPromises: Promise<unknown>[]; |
@@ -21,2 +21,3 @@ "use strict"; | ||
const core_1 = require("@opentelemetry/core"); | ||
const util_1 = require("./util"); | ||
/** | ||
@@ -42,2 +43,3 @@ * Collector Exporter abstract base class | ||
: Infinity; | ||
this.timeoutMillis = (0, util_1.configureExporterTimeout)(config.timeoutMillis); | ||
// platform dependent | ||
@@ -44,0 +46,0 @@ this.onInit(config); |
@@ -58,3 +58,3 @@ "use strict"; | ||
if (this._useXHR) { | ||
(0, util_2.sendWithXhr)(body, this.url, this._headers, resolve, reject); | ||
(0, util_2.sendWithXhr)(body, this.url, this._headers, this.timeoutMillis, resolve, reject); | ||
} | ||
@@ -61,0 +61,0 @@ else { |
@@ -20,3 +20,3 @@ import { OTLPExporterError } from '../../types'; | ||
*/ | ||
export declare function sendWithXhr(body: string, url: string, headers: Record<string, string>, onSuccess: () => void, onError: (error: OTLPExporterError) => void): void; | ||
export declare function sendWithXhr(body: string, url: string, headers: Record<string, string>, exporterTimeout: number, onSuccess: () => void, onError: (error: OTLPExporterError) => void): void; | ||
//# sourceMappingURL=util.d.ts.map |
@@ -49,3 +49,8 @@ "use strict"; | ||
*/ | ||
function sendWithXhr(body, url, headers, onSuccess, onError) { | ||
function sendWithXhr(body, url, headers, exporterTimeout, onSuccess, onError) { | ||
let reqIsDestroyed; | ||
const exporterTimer = setTimeout(() => { | ||
reqIsDestroyed = true; | ||
xhr.abort(); | ||
}, exporterTimeout); | ||
const xhr = new XMLHttpRequest(); | ||
@@ -64,7 +69,13 @@ xhr.open('POST', url); | ||
if (xhr.status >= 200 && xhr.status <= 299) { | ||
clearTimeout(exporterTimer); | ||
api_1.diag.debug('xhr success', body); | ||
onSuccess(); | ||
} | ||
else if (reqIsDestroyed) { | ||
const error = new types_1.OTLPExporterError('Request Timeout', xhr.status); | ||
onError(error); | ||
} | ||
else { | ||
const error = new types_1.OTLPExporterError(`Failed to export with XHR (status: ${xhr.status})`, xhr.status); | ||
clearTimeout(exporterTimer); | ||
onError(error); | ||
@@ -71,0 +82,0 @@ } |
@@ -38,3 +38,16 @@ "use strict"; | ||
function sendWithHttp(collector, data, contentType, onSuccess, onError) { | ||
const exporterTimeout = collector.timeoutMillis; | ||
const parsedUrl = new url.URL(collector.url); | ||
let reqIsDestroyed; | ||
const nodeVersion = Number(process.versions.node.split('.')[0]); | ||
const exporterTimer = setTimeout(() => { | ||
reqIsDestroyed = true; | ||
// req.abort() was deprecated since v14 | ||
if (nodeVersion >= 14) { | ||
req.destroy(); | ||
} | ||
else { | ||
req.abort(); | ||
} | ||
}, exporterTimeout); | ||
const options = { | ||
@@ -52,15 +65,31 @@ hostname: parsedUrl.hostname, | ||
res.on('data', chunk => (responseData += chunk)); | ||
res.on('aborted', () => { | ||
if (reqIsDestroyed) { | ||
const err = new types_2.OTLPExporterError('Request Timeout'); | ||
onError(err); | ||
} | ||
}); | ||
res.on('end', () => { | ||
if (res.statusCode && res.statusCode < 299) { | ||
api_1.diag.debug(`statusCode: ${res.statusCode}`, responseData); | ||
onSuccess(); | ||
if (!reqIsDestroyed) { | ||
if (res.statusCode && res.statusCode < 299) { | ||
api_1.diag.debug(`statusCode: ${res.statusCode}`, responseData); | ||
onSuccess(); | ||
} | ||
else { | ||
const error = new types_2.OTLPExporterError(res.statusMessage, res.statusCode, responseData); | ||
onError(error); | ||
} | ||
clearTimeout(exporterTimer); | ||
} | ||
else { | ||
const error = new types_2.OTLPExporterError(res.statusMessage, res.statusCode, responseData); | ||
onError(error); | ||
} | ||
}); | ||
}); | ||
req.on('error', (error) => { | ||
onError(error); | ||
if (reqIsDestroyed) { | ||
const err = new types_2.OTLPExporterError('Request Timeout', error.code); | ||
onError(err); | ||
} | ||
else { | ||
clearTimeout(exporterTimer); | ||
onError(error); | ||
} | ||
}); | ||
@@ -67,0 +96,0 @@ switch (collector.compression) { |
@@ -33,3 +33,6 @@ import { SpanAttributes } from '@opentelemetry/api'; | ||
concurrencyLimit?: number; | ||
/** Maximum time the OTLP exporter will wait for each batch export. | ||
* The default value is 10000ms. */ | ||
timeoutMillis?: number; | ||
} | ||
//# sourceMappingURL=types.d.ts.map |
@@ -6,3 +6,23 @@ /** | ||
export declare function parseHeaders(partialHeaders?: Partial<Record<string, unknown>>): Record<string, string>; | ||
export declare function appendResourcePathToUrlIfNotPresent(url: string, path: string): string; | ||
/** | ||
* Adds path (version + signal) to a no per-signal endpoint | ||
* @param url | ||
* @param path | ||
* @returns url + path | ||
*/ | ||
export declare function appendResourcePathToUrl(url: string, path: string): string; | ||
/** | ||
* Adds root path to signal specific endpoint when endpoint contains no path part and no root path | ||
* @param url | ||
* @param path | ||
* @returns url | ||
*/ | ||
export declare function appendRootPathToUrlIfNeeded(url: string, path: string): string; | ||
/** | ||
* Configure exporter trace timeout value from passed in value or environment variables | ||
* @param timeoutMillis | ||
* @returns timeout value in milliseconds | ||
*/ | ||
export declare function configureExporterTimeout(timeoutMillis: number | undefined): number; | ||
export declare function invalidTimeout(timeout: number, defaultTimeout: number): number; | ||
//# sourceMappingURL=util.d.ts.map |
@@ -18,4 +18,6 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.appendResourcePathToUrlIfNotPresent = exports.parseHeaders = void 0; | ||
exports.invalidTimeout = exports.configureExporterTimeout = exports.appendRootPathToUrlIfNeeded = exports.appendResourcePathToUrl = exports.parseHeaders = void 0; | ||
const api_1 = require("@opentelemetry/api"); | ||
const core_1 = require("@opentelemetry/core"); | ||
const DEFAULT_TRACE_TIMEOUT = 10000; | ||
/** | ||
@@ -38,8 +40,63 @@ * Parses headers from config leaving only those that have defined values | ||
exports.parseHeaders = parseHeaders; | ||
function appendResourcePathToUrlIfNotPresent(url, path) { | ||
if (url.match(/v\d\/(traces|metrics)$/)) | ||
return url; | ||
/** | ||
* Adds path (version + signal) to a no per-signal endpoint | ||
* @param url | ||
* @param path | ||
* @returns url + path | ||
*/ | ||
function appendResourcePathToUrl(url, path) { | ||
if (!url.endsWith('/')) { | ||
url = url + '/'; | ||
} | ||
return url + path; | ||
} | ||
exports.appendResourcePathToUrlIfNotPresent = appendResourcePathToUrlIfNotPresent; | ||
exports.appendResourcePathToUrl = appendResourcePathToUrl; | ||
/** | ||
* Adds root path to signal specific endpoint when endpoint contains no path part and no root path | ||
* @param url | ||
* @param path | ||
* @returns url | ||
*/ | ||
function appendRootPathToUrlIfNeeded(url, path) { | ||
if (!url.includes(path) && !url.endsWith('/')) { | ||
url = url + '/'; | ||
} | ||
return url; | ||
} | ||
exports.appendRootPathToUrlIfNeeded = appendRootPathToUrlIfNeeded; | ||
/** | ||
* Configure exporter trace timeout value from passed in value or environment variables | ||
* @param timeoutMillis | ||
* @returns timeout value in milliseconds | ||
*/ | ||
function configureExporterTimeout(timeoutMillis) { | ||
if (typeof timeoutMillis === 'number') { | ||
if (timeoutMillis <= 0) { | ||
// OTLP exporter configured timeout - using default value of 10000ms | ||
return invalidTimeout(timeoutMillis, DEFAULT_TRACE_TIMEOUT); | ||
} | ||
return timeoutMillis; | ||
} | ||
else { | ||
return getExporterTimeoutFromEnv(); | ||
} | ||
} | ||
exports.configureExporterTimeout = configureExporterTimeout; | ||
function getExporterTimeoutFromEnv() { | ||
var _a; | ||
const definedTimeout = Number((_a = (0, core_1.getEnv)().OTEL_EXPORTER_OTLP_TRACES_TIMEOUT) !== null && _a !== void 0 ? _a : (0, core_1.getEnv)().OTEL_EXPORTER_OTLP_TIMEOUT); | ||
if (definedTimeout <= 0) { | ||
// OTLP exporter configured timeout - using default value of 10000ms | ||
return invalidTimeout(definedTimeout, DEFAULT_TRACE_TIMEOUT); | ||
} | ||
else { | ||
return definedTimeout; | ||
} | ||
} | ||
// OTLP exporter configured timeout - using default value of 10000ms | ||
function invalidTimeout(timeout, defaultTimeout) { | ||
api_1.diag.warn('Timeout must be greater than 0', timeout); | ||
return defaultTimeout; | ||
} | ||
exports.invalidTimeout = invalidTimeout; | ||
//# sourceMappingURL=util.js.map |
@@ -1,2 +0,2 @@ | ||
export declare const VERSION = "0.28.0"; | ||
export declare const VERSION = "0.29.0"; | ||
//# sourceMappingURL=version.d.ts.map |
@@ -20,3 +20,3 @@ "use strict"; | ||
// this is autogenerated file, see scripts/version-update.js | ||
exports.VERSION = '0.28.0'; | ||
exports.VERSION = '0.29.0'; | ||
//# sourceMappingURL=version.js.map |
{ | ||
"name": "@opentelemetry/otlp-exporter-base", | ||
"version": "0.28.0", | ||
"version": "0.29.0", | ||
"description": "OpenTelemetry OTLP Exporter base (for internal use only)", | ||
@@ -48,2 +48,8 @@ "main": "build/src/index.js", | ||
"files": [ | ||
"build/esm/**/*.js", | ||
"build/esm/**/*.js.map", | ||
"build/esm/**/*.d.ts", | ||
"build/esnext/**/*.js", | ||
"build/esnext/**/*.js.map", | ||
"build/esnext/**/*.d.ts", | ||
"build/src/**/*.js", | ||
@@ -59,3 +65,3 @@ "build/src/**/*.js.map", | ||
"dependencies": { | ||
"@opentelemetry/core": "1.2.0" | ||
"@opentelemetry/core": "1.3.0" | ||
}, | ||
@@ -74,3 +80,3 @@ "devDependencies": { | ||
"ts-loader": "8.3.0", | ||
"ts-mocha": "8.0.0", | ||
"ts-mocha": "9.0.2", | ||
"typescript": "4.4.4" | ||
@@ -81,3 +87,3 @@ }, | ||
}, | ||
"gitHead": "a0a670a03fd35b0799bee8cc466f79e93b5b6dd2" | ||
"gitHead": "eda0b092db484855ded8b4837ba7fc19a377c5a7" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 2 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
249576
120
2775
7
+ Added@opentelemetry/core@1.3.0(transitive)
+ Added@opentelemetry/semantic-conventions@1.3.0(transitive)
- Removed@opentelemetry/core@1.2.0(transitive)
- Removed@opentelemetry/semantic-conventions@1.2.0(transitive)
Updated@opentelemetry/core@1.3.0