@elastic/transport
Advanced tools
Comparing version 8.6.1 to 8.7.0
@@ -53,2 +53,3 @@ /* | ||
TransportOptions, | ||
TransportRequestMetadata, | ||
TransportRequestParams, | ||
@@ -55,0 +56,0 @@ TransportRequestOptions, |
@@ -32,1 +32,2 @@ export declare const kSniffEnabled: unique symbol; | ||
export declare const kRetryBackoff: unique symbol; | ||
export declare const kOtelTracer: unique symbol; |
@@ -21,3 +21,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.kRetryBackoff = exports.kRedaction = exports.kAcceptHeader = exports.kNdjsonContentType = exports.kJsonContentType = exports.kMaxCompressedResponseSize = exports.kMaxResponseSize = exports.kCaFingerprint = exports.kProductCheck = exports.kStatus = exports.kJsonOptions = exports.kNodeSelector = exports.kNodeFilter = exports.kHeaders = exports.kDiagnostic = exports.kSerializer = exports.kConnectionPool = exports.kContext = exports.kGenerateRequestId = exports.kOpaqueIdPrefix = exports.kName = exports.kMaxRetries = exports.kCompression = exports.kRetryOnTimeout = exports.kRequestTimeout = exports.kSniffEndpoint = exports.kSniffOnConnectionFault = exports.kSniffInterval = exports.kIsSniffing = exports.kNextSniff = exports.kSniffEnabled = void 0; | ||
exports.kOtelTracer = exports.kRetryBackoff = exports.kRedaction = exports.kAcceptHeader = exports.kNdjsonContentType = exports.kJsonContentType = exports.kMaxCompressedResponseSize = exports.kMaxResponseSize = exports.kCaFingerprint = exports.kProductCheck = exports.kStatus = exports.kJsonOptions = exports.kNodeSelector = exports.kNodeFilter = exports.kHeaders = exports.kDiagnostic = exports.kSerializer = exports.kConnectionPool = exports.kContext = exports.kGenerateRequestId = exports.kOpaqueIdPrefix = exports.kName = exports.kMaxRetries = exports.kCompression = exports.kRetryOnTimeout = exports.kRequestTimeout = exports.kSniffEndpoint = exports.kSniffOnConnectionFault = exports.kSniffInterval = exports.kIsSniffing = exports.kNextSniff = exports.kSniffEnabled = void 0; | ||
exports.kSniffEnabled = Symbol('sniff enabled'); | ||
@@ -54,2 +54,3 @@ exports.kNextSniff = Symbol('next sniff'); | ||
exports.kRetryBackoff = Symbol('retry backoff'); | ||
exports.kOtelTracer = Symbol('opentelemetry tracer'); | ||
//# sourceMappingURL=symbols.js.map |
@@ -8,3 +8,4 @@ /// <reference types="node" /> | ||
import { nodeFilterFn, nodeSelectorFn, generateRequestIdFn, RequestBody, RequestNDBody, TransportResult, Context } from './types'; | ||
import { kSniffEnabled, kNextSniff, kIsSniffing, kSniffInterval, kSniffOnConnectionFault, kSniffEndpoint, kRequestTimeout, kRetryOnTimeout, kCompression, kMaxRetries, kName, kOpaqueIdPrefix, kGenerateRequestId, kContext, kConnectionPool, kSerializer, kDiagnostic, kHeaders, kNodeFilter, kNodeSelector, kProductCheck, kMaxResponseSize, kMaxCompressedResponseSize, kJsonContentType, kNdjsonContentType, kAcceptHeader, kRedaction, kRetryBackoff } from './symbols'; | ||
import { kSniffEnabled, kNextSniff, kIsSniffing, kSniffInterval, kSniffOnConnectionFault, kSniffEndpoint, kRequestTimeout, kRetryOnTimeout, kCompression, kMaxRetries, kName, kOpaqueIdPrefix, kGenerateRequestId, kContext, kConnectionPool, kSerializer, kDiagnostic, kHeaders, kNodeFilter, kNodeSelector, kProductCheck, kMaxResponseSize, kMaxCompressedResponseSize, kJsonContentType, kNdjsonContentType, kAcceptHeader, kRedaction, kRetryBackoff, kOtelTracer } from './symbols'; | ||
import { Tracer } from '@opentelemetry/api'; | ||
export interface TransportOptions { | ||
@@ -40,2 +41,6 @@ diagnostic?: Diagnostic; | ||
} | ||
export interface TransportRequestMetadata { | ||
name: string; | ||
pathParts?: Record<string, any>; | ||
} | ||
export interface TransportRequestParams { | ||
@@ -47,2 +52,3 @@ method: string; | ||
querystring?: Record<string, any> | string; | ||
meta?: TransportRequestMetadata; | ||
} | ||
@@ -137,2 +143,3 @@ export interface TransportRequestOptions { | ||
[kRetryBackoff]: (min: number, max: number, attempt: number) => number; | ||
[kOtelTracer]: Tracer; | ||
static sniffReasons: { | ||
@@ -152,2 +159,3 @@ SNIFF_ON_START: string; | ||
get diagnostic(): Diagnostic; | ||
private _request; | ||
request<TResponse = unknown>(params: TransportRequestParams, options?: TransportRequestOptionsWithOutMeta): Promise<TResponse>; | ||
@@ -154,0 +162,0 @@ request<TResponse = unknown, TContext = any>(params: TransportRequestParams, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<TResponse, TContext>>; |
@@ -20,3 +20,3 @@ "use strict"; | ||
*/ | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3; | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -36,2 +36,3 @@ exports.lowerCaseHeaders = exports.generateRequestId = void 0; | ||
const promises_1 = require("node:timers/promises"); | ||
const api_1 = tslib_1.__importStar(require("@opentelemetry/api")); | ||
const { version: clientVersion } = require('../package.json'); // eslint-disable-line | ||
@@ -45,3 +46,3 @@ const debug = (0, debug_1.default)('elasticsearch'); | ||
constructor(opts) { | ||
var _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25; | ||
var _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26; | ||
Object.defineProperty(this, _a, { | ||
@@ -215,2 +216,8 @@ enumerable: true, | ||
}); | ||
Object.defineProperty(this, _4, { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: void 0 | ||
}); | ||
if (opts.connectionPool == null) { | ||
@@ -232,12 +239,12 @@ throw new errors_1.ConfigurationError('The Connection Pool option is not defined'); | ||
} | ||
this[symbols_1.kNodeFilter] = (_4 = opts.nodeFilter) !== null && _4 !== void 0 ? _4 : defaultNodeFilter; | ||
this[symbols_1.kNodeSelector] = (_5 = opts.nodeSelector) !== null && _5 !== void 0 ? _5 : roundRobinSelector(); | ||
this[symbols_1.kNodeFilter] = (_5 = opts.nodeFilter) !== null && _5 !== void 0 ? _5 : defaultNodeFilter; | ||
this[symbols_1.kNodeSelector] = (_6 = opts.nodeSelector) !== null && _6 !== void 0 ? _6 : roundRobinSelector(); | ||
this[symbols_1.kHeaders] = Object.assign({}, { 'user-agent': userAgent }, opts.compression === true ? { 'accept-encoding': 'gzip,deflate' } : null, lowerCaseHeaders(opts.headers)); | ||
this[symbols_1.kDiagnostic] = (_6 = opts.diagnostic) !== null && _6 !== void 0 ? _6 : new Diagnostic_1.default(); | ||
this[symbols_1.kDiagnostic] = (_7 = opts.diagnostic) !== null && _7 !== void 0 ? _7 : new Diagnostic_1.default(); | ||
this[symbols_1.kConnectionPool] = opts.connectionPool; | ||
this[symbols_1.kSerializer] = (_7 = opts.serializer) !== null && _7 !== void 0 ? _7 : new Serializer_1.default(); | ||
this[symbols_1.kContext] = (_8 = opts.context) !== null && _8 !== void 0 ? _8 : null; | ||
this[symbols_1.kGenerateRequestId] = (_9 = opts.generateRequestId) !== null && _9 !== void 0 ? _9 : generateRequestId(); | ||
this[symbols_1.kOpaqueIdPrefix] = (_10 = opts.opaqueIdPrefix) !== null && _10 !== void 0 ? _10 : null; | ||
this[symbols_1.kName] = (_11 = opts.name) !== null && _11 !== void 0 ? _11 : 'elastic-transport-js'; | ||
this[symbols_1.kSerializer] = (_8 = opts.serializer) !== null && _8 !== void 0 ? _8 : new Serializer_1.default(); | ||
this[symbols_1.kContext] = (_9 = opts.context) !== null && _9 !== void 0 ? _9 : null; | ||
this[symbols_1.kGenerateRequestId] = (_10 = opts.generateRequestId) !== null && _10 !== void 0 ? _10 : generateRequestId(); | ||
this[symbols_1.kOpaqueIdPrefix] = (_11 = opts.opaqueIdPrefix) !== null && _11 !== void 0 ? _11 : null; | ||
this[symbols_1.kName] = (_12 = opts.name) !== null && _12 !== void 0 ? _12 : 'elastic-transport-js'; | ||
this[symbols_1.kMaxRetries] = typeof opts.maxRetries === 'number' ? opts.maxRetries : 3; | ||
@@ -247,16 +254,17 @@ this[symbols_1.kCompression] = opts.compression === true; | ||
this[symbols_1.kRetryOnTimeout] = opts.retryOnTimeout != null ? opts.retryOnTimeout : false; | ||
this[symbols_1.kSniffInterval] = (_12 = opts.sniffInterval) !== null && _12 !== void 0 ? _12 : false; | ||
this[symbols_1.kSniffInterval] = (_13 = opts.sniffInterval) !== null && _13 !== void 0 ? _13 : false; | ||
this[symbols_1.kSniffEnabled] = typeof this[symbols_1.kSniffInterval] === 'number'; | ||
this[symbols_1.kNextSniff] = this[symbols_1.kSniffEnabled] ? (Date.now() + this[symbols_1.kSniffInterval]) : 0; | ||
this[symbols_1.kIsSniffing] = false; | ||
this[symbols_1.kSniffOnConnectionFault] = (_13 = opts.sniffOnConnectionFault) !== null && _13 !== void 0 ? _13 : false; | ||
this[symbols_1.kSniffEndpoint] = (_14 = opts.sniffEndpoint) !== null && _14 !== void 0 ? _14 : null; | ||
this[symbols_1.kProductCheck] = (_15 = opts.productCheck) !== null && _15 !== void 0 ? _15 : null; | ||
this[symbols_1.kMaxResponseSize] = (_16 = opts.maxResponseSize) !== null && _16 !== void 0 ? _16 : buffer_1.default.constants.MAX_STRING_LENGTH; | ||
this[symbols_1.kMaxCompressedResponseSize] = (_17 = opts.maxCompressedResponseSize) !== null && _17 !== void 0 ? _17 : buffer_1.default.constants.MAX_LENGTH; | ||
this[symbols_1.kJsonContentType] = (_19 = (_18 = opts.vendoredHeaders) === null || _18 === void 0 ? void 0 : _18.jsonContentType) !== null && _19 !== void 0 ? _19 : 'application/json'; | ||
this[symbols_1.kNdjsonContentType] = (_21 = (_20 = opts.vendoredHeaders) === null || _20 === void 0 ? void 0 : _20.ndjsonContentType) !== null && _21 !== void 0 ? _21 : 'application/x-ndjson'; | ||
this[symbols_1.kAcceptHeader] = (_23 = (_22 = opts.vendoredHeaders) === null || _22 === void 0 ? void 0 : _22.accept) !== null && _23 !== void 0 ? _23 : 'application/json, text/plain'; | ||
this[symbols_1.kRedaction] = (_24 = opts.redaction) !== null && _24 !== void 0 ? _24 : { type: 'replace', additionalKeys: [] }; | ||
this[symbols_1.kRetryBackoff] = (_25 = opts.retryBackoff) !== null && _25 !== void 0 ? _25 : retryBackoff; | ||
this[symbols_1.kSniffOnConnectionFault] = (_14 = opts.sniffOnConnectionFault) !== null && _14 !== void 0 ? _14 : false; | ||
this[symbols_1.kSniffEndpoint] = (_15 = opts.sniffEndpoint) !== null && _15 !== void 0 ? _15 : null; | ||
this[symbols_1.kProductCheck] = (_16 = opts.productCheck) !== null && _16 !== void 0 ? _16 : null; | ||
this[symbols_1.kMaxResponseSize] = (_17 = opts.maxResponseSize) !== null && _17 !== void 0 ? _17 : buffer_1.default.constants.MAX_STRING_LENGTH; | ||
this[symbols_1.kMaxCompressedResponseSize] = (_18 = opts.maxCompressedResponseSize) !== null && _18 !== void 0 ? _18 : buffer_1.default.constants.MAX_LENGTH; | ||
this[symbols_1.kJsonContentType] = (_20 = (_19 = opts.vendoredHeaders) === null || _19 === void 0 ? void 0 : _19.jsonContentType) !== null && _20 !== void 0 ? _20 : 'application/json'; | ||
this[symbols_1.kNdjsonContentType] = (_22 = (_21 = opts.vendoredHeaders) === null || _21 === void 0 ? void 0 : _21.ndjsonContentType) !== null && _22 !== void 0 ? _22 : 'application/x-ndjson'; | ||
this[symbols_1.kAcceptHeader] = (_24 = (_23 = opts.vendoredHeaders) === null || _23 === void 0 ? void 0 : _23.accept) !== null && _24 !== void 0 ? _24 : 'application/json, text/plain'; | ||
this[symbols_1.kRedaction] = (_25 = opts.redaction) !== null && _25 !== void 0 ? _25 : { type: 'replace', additionalKeys: [] }; | ||
this[symbols_1.kRetryBackoff] = (_26 = opts.retryBackoff) !== null && _26 !== void 0 ? _26 : retryBackoff; | ||
this[symbols_1.kOtelTracer] = api_1.default.trace.getTracer('@elastic/transport', clientVersion); | ||
if (opts.sniffOnStart === true) { | ||
@@ -294,4 +302,4 @@ this.sniff({ | ||
} | ||
async request(params, options = {}) { | ||
var _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20; | ||
async _request(params, options = {}, otelSpan) { | ||
var _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21; | ||
const connectionParams = { | ||
@@ -306,3 +314,3 @@ method: params.method, | ||
options: options, | ||
id: (_4 = options.id) !== null && _4 !== void 0 ? _4 : this[symbols_1.kGenerateRequestId](params, options) | ||
id: (_5 = options.id) !== null && _5 !== void 0 ? _5 : this[symbols_1.kGenerateRequestId](params, options) | ||
}, | ||
@@ -314,3 +322,3 @@ name: this[symbols_1.kName], | ||
}; | ||
const returnMeta = (_5 = options.meta) !== null && _5 !== void 0 ? _5 : false; | ||
const returnMeta = (_6 = options.meta) !== null && _6 !== void 0 ? _6 : false; | ||
if (this[symbols_1.kContext] != null && options.context != null) { | ||
@@ -333,4 +341,4 @@ meta.context = Object.assign({}, this[symbols_1.kContext], options.context); | ||
get warnings() { | ||
var _4; | ||
if (((_4 = this.headers) === null || _4 === void 0 ? void 0 : _4.warning) == null) { | ||
var _5; | ||
if (((_5 = this.headers) === null || _5 === void 0 ? void 0 : _5.warning) == null) { | ||
return null; | ||
@@ -350,7 +358,7 @@ } | ||
// Furthermore, copying every time the stream is very a expensive operation. | ||
const maxRetries = isStream((_6 = params.body) !== null && _6 !== void 0 ? _6 : params.bulkBody) ? 0 : (typeof options.maxRetries === 'number' ? options.maxRetries : this[symbols_1.kMaxRetries]); | ||
const maxRetries = isStream((_7 = params.body) !== null && _7 !== void 0 ? _7 : params.bulkBody) ? 0 : (typeof options.maxRetries === 'number' ? options.maxRetries : this[symbols_1.kMaxRetries]); | ||
const compression = typeof options.compression === 'boolean' ? options.compression : this[symbols_1.kCompression]; | ||
const signal = options.signal; | ||
const maxResponseSize = (_7 = options.maxResponseSize) !== null && _7 !== void 0 ? _7 : this[symbols_1.kMaxResponseSize]; | ||
const maxCompressedResponseSize = (_8 = options.maxCompressedResponseSize) !== null && _8 !== void 0 ? _8 : this[symbols_1.kMaxCompressedResponseSize]; | ||
const maxResponseSize = (_8 = options.maxResponseSize) !== null && _8 !== void 0 ? _8 : this[symbols_1.kMaxResponseSize]; | ||
const maxCompressedResponseSize = (_9 = options.maxCompressedResponseSize) !== null && _9 !== void 0 ? _9 : this[symbols_1.kMaxCompressedResponseSize]; | ||
const errorOptions = { | ||
@@ -376,9 +384,9 @@ redaction: typeof options.redaction === 'object' ? options.redaction : this[symbols_1.kRedaction] | ||
} | ||
headers['content-type'] = (_9 = headers['content-type']) !== null && _9 !== void 0 ? _9 : this[symbols_1.kJsonContentType]; | ||
headers.accept = (_10 = headers.accept) !== null && _10 !== void 0 ? _10 : this[symbols_1.kJsonContentType]; | ||
headers['content-type'] = (_10 = headers['content-type']) !== null && _10 !== void 0 ? _10 : this[symbols_1.kJsonContentType]; | ||
headers.accept = (_11 = headers.accept) !== null && _11 !== void 0 ? _11 : this[symbols_1.kJsonContentType]; | ||
} | ||
else { | ||
if (params.body !== '') { | ||
headers['content-type'] = (_11 = headers['content-type']) !== null && _11 !== void 0 ? _11 : 'text/plain'; | ||
headers.accept = (_12 = headers.accept) !== null && _12 !== void 0 ? _12 : this[symbols_1.kAcceptHeader]; | ||
headers['content-type'] = (_12 = headers['content-type']) !== null && _12 !== void 0 ? _12 : 'text/plain'; | ||
headers.accept = (_13 = headers.accept) !== null && _13 !== void 0 ? _13 : this[symbols_1.kAcceptHeader]; | ||
} | ||
@@ -403,4 +411,4 @@ connectionParams.body = params.body; | ||
if (connectionParams.body !== '') { | ||
headers['content-type'] = (_13 = headers['content-type']) !== null && _13 !== void 0 ? _13 : this[symbols_1.kNdjsonContentType]; | ||
headers.accept = (_14 = headers.accept) !== null && _14 !== void 0 ? _14 : this[symbols_1.kJsonContentType]; | ||
headers['content-type'] = (_14 = headers['content-type']) !== null && _14 !== void 0 ? _14 : this[symbols_1.kNdjsonContentType]; | ||
headers.accept = (_15 = headers.accept) !== null && _15 !== void 0 ? _15 : this[symbols_1.kJsonContentType]; | ||
} | ||
@@ -440,3 +448,3 @@ } | ||
} | ||
headers.accept = (_15 = headers.accept) !== null && _15 !== void 0 ? _15 : this[symbols_1.kAcceptHeader]; | ||
headers.accept = (_16 = headers.accept) !== null && _16 !== void 0 ? _16 : this[symbols_1.kAcceptHeader]; | ||
connectionParams.headers = headers; | ||
@@ -455,2 +463,19 @@ while (meta.attempts <= maxRetries) { | ||
} | ||
// generate required OpenTelemetry attributes from the request URL | ||
const requestUrl = meta.connection.url; | ||
otelSpan === null || otelSpan === void 0 ? void 0 : otelSpan.setAttributes({ | ||
'url.full': requestUrl.toString(), | ||
'server.address': requestUrl.hostname | ||
}); | ||
if (requestUrl.port === '') { | ||
if (requestUrl.protocol === 'https:') { | ||
otelSpan === null || otelSpan === void 0 ? void 0 : otelSpan.setAttribute('server.port', 443); | ||
} | ||
else if (requestUrl.protocol === 'http:') { | ||
otelSpan === null || otelSpan === void 0 ? void 0 : otelSpan.setAttribute('server.port', 80); | ||
} | ||
} | ||
else if (requestUrl.port !== '9200') { | ||
otelSpan === null || otelSpan === void 0 ? void 0 : otelSpan.setAttribute('server.port', parseInt(requestUrl.port, 10)); | ||
} | ||
this[symbols_1.kDiagnostic].emit('request', null, result); | ||
@@ -470,2 +495,8 @@ // perform the actual http request | ||
result.headers = headers; | ||
if (headers['x-found-handling-cluster'] != null) { | ||
otelSpan === null || otelSpan === void 0 ? void 0 : otelSpan.setAttribute('db.elasticsearch.cluster.name', headers['x-found-handling-cluster']); | ||
} | ||
if (headers['x-found-handling-instance'] != null) { | ||
otelSpan === null || otelSpan === void 0 ? void 0 : otelSpan.setAttribute('db.elasticsearch.node.name', headers['x-found-handling-instance']); | ||
} | ||
if (this[symbols_1.kProductCheck] != null && headers['x-elastic-product'] !== this[symbols_1.kProductCheck] && statusCode >= 200 && statusCode < 300) { | ||
@@ -482,7 +513,7 @@ /* eslint-disable @typescript-eslint/prefer-ts-expect-error */ | ||
} | ||
const contentEncoding = ((_16 = headers['content-encoding']) !== null && _16 !== void 0 ? _16 : '').toLowerCase(); | ||
const contentEncoding = ((_17 = headers['content-encoding']) !== null && _17 !== void 0 ? _17 : '').toLowerCase(); | ||
if (contentEncoding.includes('gzip') || contentEncoding.includes('deflate')) { | ||
body = await unzip(body); | ||
} | ||
const isVectorTile = ((_17 = headers['content-type']) !== null && _17 !== void 0 ? _17 : '').includes('application/vnd.mapbox-vector-tile'); | ||
const isVectorTile = ((_18 = headers['content-type']) !== null && _18 !== void 0 ? _18 : '').includes('application/vnd.mapbox-vector-tile'); | ||
if (Buffer.isBuffer(body) && !isVectorTile) { | ||
@@ -497,4 +528,4 @@ body = body.toString(); | ||
if (headers['content-type'] !== undefined && | ||
(((_18 = headers['content-type']) === null || _18 === void 0 ? void 0 : _18.includes('application/json')) || | ||
((_19 = headers['content-type']) === null || _19 === void 0 ? void 0 : _19.includes('application/vnd.elasticsearch+json'))) && | ||
(((_19 = headers['content-type']) === null || _19 === void 0 ? void 0 : _19.includes('application/json')) || | ||
((_20 = headers['content-type']) === null || _20 === void 0 ? void 0 : _20.includes('application/vnd.elasticsearch+json'))) && | ||
!isHead && body !== '') { // eslint-disable-line | ||
@@ -581,3 +612,3 @@ result.body = this[symbols_1.kSerializer].deserialize(body); | ||
// exponential backoff on retries, with jitter | ||
const backoff = (_20 = options.retryBackoff) !== null && _20 !== void 0 ? _20 : this[symbols_1.kRetryBackoff]; | ||
const backoff = (_21 = options.retryBackoff) !== null && _21 !== void 0 ? _21 : this[symbols_1.kRetryBackoff]; | ||
const backoffWait = backoff(0, 4, meta.attempts); | ||
@@ -605,2 +636,39 @@ if (backoffWait > 0) { | ||
} | ||
async request(params, options = {}) { | ||
var _5, _6, _7; | ||
// wrap in OpenTelemetry span | ||
if (((_5 = params.meta) === null || _5 === void 0 ? void 0 : _5.name) != null) { | ||
// gather OpenTelemetry attributes | ||
const attributes = { | ||
'db.system': 'elasticsearch', | ||
'http.request.method': params.method, | ||
'db.operation.name': (_6 = params.meta) === null || _6 === void 0 ? void 0 : _6.name | ||
}; | ||
if (((_7 = params.meta) === null || _7 === void 0 ? void 0 : _7.pathParts) != null) { | ||
for (const key of Object.keys(params.meta.pathParts)) { | ||
attributes[`db.elasticsearch.path_parts.${key}`] = params.meta.pathParts[key]; | ||
} | ||
} | ||
return await this[symbols_1.kOtelTracer].startActiveSpan(params.meta.name, { attributes, kind: api_1.SpanKind.CLIENT }, async (otelSpan) => { | ||
var _5; | ||
let response; | ||
try { | ||
response = await this._request(params, options, otelSpan); | ||
} | ||
catch (err) { | ||
otelSpan.recordException(err); | ||
otelSpan.setStatus({ code: api_1.SpanStatusCode.ERROR }); | ||
otelSpan.setAttribute('error.type', (_5 = err.name) !== null && _5 !== void 0 ? _5 : 'Error'); | ||
throw err; | ||
} | ||
finally { | ||
otelSpan.end(); | ||
} | ||
return response; | ||
}); | ||
} | ||
else { | ||
return await this._request(params, options); | ||
} | ||
} | ||
getConnection(opts) { | ||
@@ -629,3 +697,3 @@ const now = Date.now(); | ||
exports.default = Transport; | ||
_a = symbols_1.kNodeFilter, _b = symbols_1.kNodeSelector, _c = symbols_1.kHeaders, _d = symbols_1.kDiagnostic, _e = symbols_1.kConnectionPool, _f = symbols_1.kSerializer, _g = symbols_1.kContext, _h = symbols_1.kGenerateRequestId, _j = symbols_1.kOpaqueIdPrefix, _k = symbols_1.kName, _l = symbols_1.kMaxRetries, _m = symbols_1.kCompression, _o = symbols_1.kRequestTimeout, _p = symbols_1.kRetryOnTimeout, _q = symbols_1.kSniffEnabled, _r = symbols_1.kNextSniff, _s = symbols_1.kIsSniffing, _t = symbols_1.kSniffInterval, _u = symbols_1.kSniffOnConnectionFault, _v = symbols_1.kSniffEndpoint, _w = symbols_1.kProductCheck, _x = symbols_1.kMaxResponseSize, _y = symbols_1.kMaxCompressedResponseSize, _z = symbols_1.kJsonContentType, _0 = symbols_1.kNdjsonContentType, _1 = symbols_1.kAcceptHeader, _2 = symbols_1.kRedaction, _3 = symbols_1.kRetryBackoff; | ||
_a = symbols_1.kNodeFilter, _b = symbols_1.kNodeSelector, _c = symbols_1.kHeaders, _d = symbols_1.kDiagnostic, _e = symbols_1.kConnectionPool, _f = symbols_1.kSerializer, _g = symbols_1.kContext, _h = symbols_1.kGenerateRequestId, _j = symbols_1.kOpaqueIdPrefix, _k = symbols_1.kName, _l = symbols_1.kMaxRetries, _m = symbols_1.kCompression, _o = symbols_1.kRequestTimeout, _p = symbols_1.kRetryOnTimeout, _q = symbols_1.kSniffEnabled, _r = symbols_1.kNextSniff, _s = symbols_1.kIsSniffing, _t = symbols_1.kSniffInterval, _u = symbols_1.kSniffOnConnectionFault, _v = symbols_1.kSniffEndpoint, _w = symbols_1.kProductCheck, _x = symbols_1.kMaxResponseSize, _y = symbols_1.kMaxCompressedResponseSize, _z = symbols_1.kJsonContentType, _0 = symbols_1.kNdjsonContentType, _1 = symbols_1.kAcceptHeader, _2 = symbols_1.kRedaction, _3 = symbols_1.kRetryBackoff, _4 = symbols_1.kOtelTracer; | ||
Object.defineProperty(Transport, "sniffReasons", { | ||
@@ -632,0 +700,0 @@ enumerable: true, |
{ | ||
"name": "@elastic/transport", | ||
"version": "8.6.1", | ||
"version": "8.7.0", | ||
"description": "Transport classes and utilities shared among Node.js Elastic client libraries", | ||
@@ -40,2 +40,3 @@ "main": "index.js", | ||
"devDependencies": { | ||
"@opentelemetry/sdk-trace-base": "^1.25.0", | ||
"@sinonjs/fake-timers": "github:sinonjs/fake-timers#0bfffc1", | ||
@@ -62,2 +63,3 @@ "@tapjs/clock": "^1.1.24", | ||
"dependencies": { | ||
"@opentelemetry/api": "1.x", | ||
"debug": "^4.3.4", | ||
@@ -73,5 +75,6 @@ "hpagent": "^1.0.0", | ||
"plugin": [ | ||
"@tapjs/clock" | ||
"@tapjs/clock", | ||
"@tapjs/before" | ||
] | ||
} | ||
} |
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
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
658023
9084
7
20
+ Added@opentelemetry/api@1.x
+ Added@opentelemetry/api@1.9.0(transitive)