@opentelemetry/instrumentation-http 0.40.0 → 0.41.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,18 +14,9 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
18
- if (k2 === undefined) k2 = k;
19
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
20
- }) : (function(o, m, k, k2) {
21
- if (k2 === undefined) k2 = k;
22
- o[k2] = m[k];
23
- }));
24
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
25
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
26
- };
27
17
  Object.defineProperty(exports, "__esModule", { value: true });
28
- __exportStar(require("./http"), exports);
29
- __exportStar(require("./types"), exports);
30
- __exportStar(require("./utils"), exports);
18
+ const tslib_1 = require("tslib");
19
+ (0, tslib_1.__exportStar)(require("./http"), exports);
20
+ (0, tslib_1.__exportStar)(require("./types"), exports);
21
+ (0, tslib_1.__exportStar)(require("./utils"), exports);
31
22
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;AAEH,yCAAuB;AACvB,0CAAwB;AACxB,0CAAwB","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport * from './http';\nexport * from './types';\nexport * from './utils';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,sDAAuB;AACvB,uDAAwB;AACxB,uDAAwB","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport * from './http';\nexport * from './types';\nexport * from './utils';\n"]}
@@ -324,11 +324,12 @@ exports.getAttributesFromHttpKind = getAttributesFromHttpKind;
324
324
  */
325
325
  const getOutgoingRequestAttributesOnResponse = (response) => {
326
326
  const { statusCode, statusMessage, httpVersion, socket } = response;
327
- const { remoteAddress, remotePort } = socket;
328
- const attributes = {
329
- [semantic_conventions_1.SemanticAttributes.NET_PEER_IP]: remoteAddress,
330
- [semantic_conventions_1.SemanticAttributes.NET_PEER_PORT]: remotePort,
331
- };
327
+ const attributes = {};
328
+ if (socket) {
329
+ const { remoteAddress, remotePort } = socket;
330
+ attributes[semantic_conventions_1.SemanticAttributes.NET_PEER_IP] = remoteAddress;
331
+ attributes[semantic_conventions_1.SemanticAttributes.NET_PEER_PORT] = remotePort;
332
+ }
332
333
  (0, exports.setResponseContentLengthAttribute)(response, attributes);
333
334
  if (statusCode) {
334
335
  attributes[semantic_conventions_1.SemanticAttributes.HTTP_STATUS_CODE] = statusCode;
@@ -422,16 +423,17 @@ const getIncomingRequestAttributesOnResponse = (request, response) => {
422
423
  // since it may be detached from the response object in keep-alive mode
423
424
  const { socket } = request;
424
425
  const { statusCode, statusMessage } = response;
425
- const { localAddress, localPort, remoteAddress, remotePort } = socket;
426
426
  const rpcMetadata = (0, core_1.getRPCMetadata)(api_1.context.active());
427
- const attributes = {
428
- [semantic_conventions_1.SemanticAttributes.NET_HOST_IP]: localAddress,
429
- [semantic_conventions_1.SemanticAttributes.NET_HOST_PORT]: localPort,
430
- [semantic_conventions_1.SemanticAttributes.NET_PEER_IP]: remoteAddress,
431
- [semantic_conventions_1.SemanticAttributes.NET_PEER_PORT]: remotePort,
432
- [semantic_conventions_1.SemanticAttributes.HTTP_STATUS_CODE]: statusCode,
433
- [AttributeNames_1.AttributeNames.HTTP_STATUS_TEXT]: (statusMessage || '').toUpperCase(),
434
- };
427
+ const attributes = {};
428
+ if (socket) {
429
+ const { localAddress, localPort, remoteAddress, remotePort } = socket;
430
+ attributes[semantic_conventions_1.SemanticAttributes.NET_HOST_IP] = localAddress;
431
+ attributes[semantic_conventions_1.SemanticAttributes.NET_HOST_PORT] = localPort;
432
+ attributes[semantic_conventions_1.SemanticAttributes.NET_PEER_IP] = remoteAddress;
433
+ attributes[semantic_conventions_1.SemanticAttributes.NET_PEER_PORT] = remotePort;
434
+ }
435
+ attributes[semantic_conventions_1.SemanticAttributes.HTTP_STATUS_CODE] = statusCode;
436
+ attributes[AttributeNames_1.AttributeNames.HTTP_STATUS_TEXT] = (statusMessage || '').toUpperCase();
435
437
  if ((rpcMetadata === null || rpcMetadata === void 0 ? void 0 : rpcMetadata.type) === core_1.RPCType.HTTP && rpcMetadata.route !== undefined) {
436
438
  attributes[semantic_conventions_1.SemanticAttributes.HTTP_ROUTE] = rpcMetadata.route;
437
439
  }
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,4CAO4B;AAC5B,8EAG6C;AAQ7C,8CAA8D;AAC9D,2BAA2B;AAC3B,2DAAwD;AAGxD;;GAEG;AACI,MAAM,cAAc,GAAG,CAC5B,UAAuC,EACvC,OAAkD,EAClD,gBAAgB,GAAG,OA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K,CAAC,CAAC,CAAC;aACjC;SACF;IACH,CAAC,CAAC;AACJ,CAAC;AA9BD,sCA8BC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n MetricAttributes,\n SpanAttributes,\n SpanStatusCode,\n Span,\n context,\n SpanKind,\n} from '@opentelemetry/api';\nimport {\n NetTransportValues,\n SemanticAttributes,\n} from '@opentelemetry/semantic-conventions';\nimport {\n IncomingHttpHeaders,\n IncomingMessage,\n OutgoingHttpHeaders,\n RequestOptions,\n ServerResponse,\n} from 'http';\nimport { getRPCMetadata, RPCType } from '@opentelemetry/core';\nimport * as url from 'url';\nimport { AttributeNames } from './enums/AttributeNames';\nimport { Err, IgnoreMatcher, ParsedRequestOptions } from './types';\n\n/**\n * Get an absolute url\n */\nexport const getAbsoluteUrl = (\n requestUrl: ParsedRequestOptions | null,\n headers: IncomingHttpHeaders | OutgoingHttpHeaders,\n fallbackProtocol = 'http:'\n): string => {\n const reqUrlObject = requestUrl || {};\n const protocol = reqUrlObject.protocol || fallbackProtocol;\n const port = (reqUrlObject.port || '').toString();\n const path = reqUrlObject.path || '/';\n let host =\n reqUrlObject.host || reqUrlObject.hostname || headers.host || 'localhost';\n\n // if there is no port in host and there is a port\n // it should be displayed if it's not 80 and 443 (default ports)\n if (\n (host as string).indexOf(':') === -1 &&\n port &&\n port !== '80' &&\n port !== '443'\n ) {\n host += `:${port}`;\n }\n\n return `${protocol}//${host}${path}`;\n};\n\n/**\n * Parse status code from HTTP response. [More details](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/data-http.md#status)\n */\nexport const parseResponseStatus = (\n kind: SpanKind,\n statusCode?: number\n): SpanStatusCode => {\n const upperBound = kind === SpanKind.CLIENT ? 400 : 500;\n // 1xx, 2xx, 3xx are OK on client and server\n // 4xx is OK on server\n if (statusCode && statusCode >= 100 && statusCode < upperBound) {\n return SpanStatusCode.UNSET;\n }\n\n // All other codes are error\n return SpanStatusCode.ERROR;\n};\n\n/**\n * Check whether the given obj match pattern\n * @param constant e.g URL of request\n * @param pattern Match pattern\n */\nexport const satisfiesPattern = (\n constant: string,\n pattern: IgnoreMatcher\n): boolean => {\n if (typeof pattern === 'string') {\n return pattern === constant;\n } else if (pattern instanceof RegExp) {\n return pattern.test(constant);\n } else if (typeof pattern === 'function') {\n return pattern(constant);\n } else {\n throw new TypeError('Pattern is in unsupported datatype');\n }\n};\n\n/**\n * Check whether the given request is ignored by configuration\n * It will not re-throw exceptions from `list` provided by the client\n * @param constant e.g URL of request\n * @param [list] List of ignore patterns\n * @param [onException] callback for doing something when an exception has\n * occurred\n */\nexport const isIgnored = (\n constant: string,\n list?: IgnoreMatcher[],\n onException?: (error: unknown) => void\n): boolean => {\n if (!list) {\n // No ignored urls - trace everything\n return false;\n }\n // Try/catch outside the loop for failing fast\n try {\n for (const pattern of list) {\n if (satisfiesPattern(constant, pattern)) {\n return true;\n }\n }\n } catch (e) {\n if (onException) {\n onException(e);\n }\n }\n\n return false;\n};\n\n/**\n * Sets the span with the error passed in params\n * @param {Span} span the span that need to be set\n * @param {Error} error error that will be set to span\n */\nexport const setSpanWithError = (span: Span, error: Err): void => {\n const message = error.message;\n\n span.setAttributes({\n [AttributeNames.HTTP_ERROR_NAME]: error.name,\n [AttributeNames.HTTP_ERROR_MESSAGE]: message,\n });\n\n span.setStatus({ code: SpanStatusCode.ERROR, message });\n span.recordException(error);\n};\n\n/**\n * Adds attributes for request content-length and content-encoding HTTP headers\n * @param { IncomingMessage } Request object whose headers will be analyzed\n * @param { SpanAttributes } SpanAttributes object to be modified\n */\nexport const setRequestContentLengthAttribute = (\n request: IncomingMessage,\n attributes: SpanAttributes\n): void => {\n const length = getContentLength(request.headers);\n if (length === null) return;\n\n if (isCompressed(request.headers)) {\n attributes[SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH] = length;\n } else {\n attributes[SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH_UNCOMPRESSED] =\n length;\n }\n};\n\n/**\n * Adds attributes for response content-length and content-encoding HTTP headers\n * @param { IncomingMessage } Response object whose headers will be analyzed\n * @param { SpanAttributes } SpanAttributes object to be modified\n */\nexport const setResponseContentLengthAttribute = (\n response: IncomingMessage,\n attributes: SpanAttributes\n): void => {\n const length = getContentLength(response.headers);\n if (length === null) return;\n\n if (isCompressed(response.headers)) {\n attributes[SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH] = length;\n } else {\n attributes[SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH_UNCOMPRESSED] =\n length;\n }\n};\n\nfunction getContentLength(\n headers: OutgoingHttpHeaders | IncomingHttpHeaders\n): number | null {\n const contentLengthHeader = headers['content-length'];\n if (contentLengthHeader === undefined) return null;\n\n const contentLength = parseInt(contentLengthHeader as string, 10);\n if (isNaN(contentLength)) return null;\n\n return contentLength;\n}\n\nexport const isCompressed = (\n headers: OutgoingHttpHeaders | IncomingHttpHeaders\n): boolean => {\n const encoding = headers['content-encoding'];\n\n return !!encoding && encoding !== 'identity';\n};\n\n/**\n * Makes sure options is an url object\n * return an object with default value and parsed options\n * @param options original options for the request\n * @param [extraOptions] additional options for the request\n */\nexport const getRequestInfo = (\n options: url.URL | RequestOptions | string,\n extraOptions?: RequestOptions\n): {\n origin: string;\n pathname: string;\n method: string;\n optionsParsed: RequestOptions;\n} => {\n let pathname = '/';\n let origin = '';\n let optionsParsed: RequestOptions;\n if (typeof options === 'string') {\n optionsParsed = url.parse(options);\n pathname = (optionsParsed as url.UrlWithStringQuery).pathname || '/';\n origin = `${optionsParsed.protocol || 'http:'}//${optionsParsed.host}`;\n if (extraOptions !== undefined) {\n Object.assign(optionsParsed, extraOptions);\n }\n } else if (options instanceof url.URL) {\n optionsParsed = {\n protocol: options.protocol,\n hostname:\n typeof options.hostname === 'string' && options.hostname.startsWith('[')\n ? options.hostname.slice(1, -1)\n : options.hostname,\n path: `${options.pathname || ''}${options.search || ''}`,\n };\n if (options.port !== '') {\n optionsParsed.port = Number(options.port);\n }\n if (options.username || options.password) {\n optionsParsed.auth = `${options.username}:${options.password}`;\n }\n pathname = options.pathname;\n origin = options.origin;\n if (extraOptions !== undefined) {\n Object.assign(optionsParsed, extraOptions);\n }\n } else {\n optionsParsed = Object.assign(\n { protocol: options.host ? 'http:' : undefined },\n options\n );\n pathname = (options as url.URL).pathname;\n if (!pathname && optionsParsed.path) {\n pathname = url.parse(optionsParsed.path).pathname || '/';\n }\n const hostname =\n optionsParsed.host ||\n (optionsParsed.port != null\n ? `${optionsParsed.hostname}${optionsParsed.port}`\n : optionsParsed.hostname);\n origin = `${optionsParsed.protocol || 'http:'}//${hostname}`;\n }\n\n // some packages return method in lowercase..\n // ensure upperCase for consistency\n const method = optionsParsed.method\n ? optionsParsed.method.toUpperCase()\n : 'GET';\n\n return { origin, pathname, method, optionsParsed };\n};\n\n/**\n * Makes sure options is of type string or object\n * @param options for the request\n */\nexport const isValidOptionsType = (options: unknown): boolean => {\n if (!options) {\n return false;\n }\n\n const type = typeof options;\n return type === 'string' || (type === 'object' && !Array.isArray(options));\n};\n\nexport const extractHostnameAndPort = (\n requestOptions: Pick<\n ParsedRequestOptions,\n 'hostname' | 'host' | 'port' | 'protocol'\n >\n): { hostname: string; port: number | string } => {\n if (requestOptions.hostname && requestOptions.port) {\n return { hostname: requestOptions.hostname, port: requestOptions.port };\n }\n const matches = requestOptions.host?.match(/^([^:/ ]+)(:\\d{1,5})?/) || null;\n const hostname =\n requestOptions.hostname || (matches === null ? 'localhost' : matches[1]);\n let port = requestOptions.port;\n if (!port) {\n if (matches && matches[2]) {\n // remove the leading \":\". The extracted port would be something like \":8080\"\n port = matches[2].substring(1);\n } else {\n port = requestOptions.protocol === 'https:' ? '443' : '80';\n }\n }\n return { hostname, port };\n};\n\n/**\n * Returns outgoing request attributes scoped to the options passed to the request\n * @param {ParsedRequestOptions} requestOptions the same options used to make the request\n * @param {{ component: string, hostname: string, hookAttributes?: SpanAttributes }} options used to pass data needed to create attributes\n */\nexport const getOutgoingRequestAttributes = (\n requestOptions: ParsedRequestOptions,\n options: {\n component: string;\n hostname: string;\n port: string | number;\n hookAttributes?: SpanAttributes;\n }\n): SpanAttributes => {\n const hostname = options.hostname;\n const port = options.port;\n const requestMethod = requestOptions.method;\n const method = requestMethod ? requestMethod.toUpperCase() : 'GET';\n const headers = requestOptions.headers || {};\n const userAgent = headers['user-agent'];\n const attributes: SpanAttributes = {\n [SemanticAttributes.HTTP_URL]: getAbsoluteUrl(\n requestOptions,\n headers,\n `${options.component}:`\n ),\n [SemanticAttributes.HTTP_METHOD]: method,\n [SemanticAttributes.HTTP_TARGET]: requestOptions.path || '/',\n [SemanticAttributes.NET_PEER_NAME]: hostname,\n [SemanticAttributes.HTTP_HOST]:\n requestOptions.headers?.host ?? `${hostname}:${port}`,\n };\n\n if (userAgent !== undefined) {\n attributes[SemanticAttributes.HTTP_USER_AGENT] = userAgent;\n }\n return Object.assign(attributes, options.hookAttributes);\n};\n\n/**\n * Returns outgoing request Metric attributes scoped to the request data\n * @param {SpanAttributes} spanAttributes the span attributes\n */\nexport const getOutgoingRequestMetricAttributes = (\n spanAttributes: SpanAttributes\n): MetricAttributes => {\n const metricAttributes: MetricAttributes = {};\n metricAttributes[SemanticAttributes.HTTP_METHOD] =\n spanAttributes[SemanticAttributes.HTTP_METHOD];\n metricAttributes[SemanticAttributes.NET_PEER_NAME] =\n spanAttributes[SemanticAttributes.NET_PEER_NAME];\n //TODO: http.url attribute, it should susbtitute any parameters to avoid high cardinality.\n return metricAttributes;\n};\n\n/**\n * Returns attributes related to the kind of HTTP protocol used\n * @param {string} [kind] Kind of HTTP protocol used: \"1.0\", \"1.1\", \"2\", \"SPDY\" or \"QUIC\".\n */\nexport const getAttributesFromHttpKind = (kind?: string): SpanAttributes => {\n const attributes: SpanAttributes = {};\n if (kind) {\n attributes[SemanticAttributes.HTTP_FLAVOR] = kind;\n if (kind.toUpperCase() !== 'QUIC') {\n attributes[SemanticAttributes.NET_TRANSPORT] = NetTransportValues.IP_TCP;\n } else {\n attributes[SemanticAttributes.NET_TRANSPORT] = NetTransportValues.IP_UDP;\n }\n }\n return attributes;\n};\n\n/**\n * Returns outgoing request attributes scoped to the response data\n * @param {IncomingMessage} response the response object\n * @param {{ hostname: string }} options used to pass data needed to create attributes\n */\nexport const getOutgoingRequestAttributesOnResponse = (\n response: IncomingMessage\n): SpanAttributes => {\n const { statusCode, statusMessage, httpVersion, socket } = response;\n const { remoteAddress, remotePort } = socket;\n const attributes: SpanAttributes = {\n [SemanticAttributes.NET_PEER_IP]: remoteAddress,\n [SemanticAttributes.NET_PEER_PORT]: remotePort,\n };\n setResponseContentLengthAttribute(response, attributes);\n\n if (statusCode) {\n attributes[SemanticAttributes.HTTP_STATUS_CODE] = statusCode;\n attributes[AttributeNames.HTTP_STATUS_TEXT] = (\n statusMessage || ''\n ).toUpperCase();\n }\n\n const httpKindAttributes = getAttributesFromHttpKind(httpVersion);\n return Object.assign(attributes, httpKindAttributes);\n};\n\n/**\n * Returns outgoing request Metric attributes scoped to the response data\n * @param {SpanAttributes} spanAttributes the span attributes\n */\nexport const getOutgoingRequestMetricAttributesOnResponse = (\n spanAttributes: SpanAttributes\n): MetricAttributes => {\n const metricAttributes: MetricAttributes = {};\n metricAttributes[SemanticAttributes.NET_PEER_PORT] =\n spanAttributes[SemanticAttributes.NET_PEER_PORT];\n metricAttributes[SemanticAttributes.HTTP_STATUS_CODE] =\n spanAttributes[SemanticAttributes.HTTP_STATUS_CODE];\n metricAttributes[SemanticAttributes.HTTP_FLAVOR] =\n spanAttributes[SemanticAttributes.HTTP_FLAVOR];\n return metricAttributes;\n};\n\n/**\n * Returns incoming request attributes scoped to the request data\n * @param {IncomingMessage} request the request object\n * @param {{ component: string, serverName?: string, hookAttributes?: SpanAttributes }} options used to pass data needed to create attributes\n */\nexport const getIncomingRequestAttributes = (\n request: IncomingMessage,\n options: {\n component: string;\n serverName?: string;\n hookAttributes?: SpanAttributes;\n }\n): SpanAttributes => {\n const headers = request.headers;\n const userAgent = headers['user-agent'];\n const ips = headers['x-forwarded-for'];\n const method = request.method || 'GET';\n const httpVersion = request.httpVersion;\n const requestUrl = request.url ? url.parse(request.url) : null;\n const host = requestUrl?.host || headers.host;\n const hostname =\n requestUrl?.hostname ||\n host?.replace(/^(.*)(:[0-9]{1,5})/, '$1') ||\n 'localhost';\n const serverName = options.serverName;\n const attributes: SpanAttributes = {\n [SemanticAttributes.HTTP_URL]: getAbsoluteUrl(\n requestUrl,\n headers,\n `${options.component}:`\n ),\n [SemanticAttributes.HTTP_HOST]: host,\n [SemanticAttributes.NET_HOST_NAME]: hostname,\n [SemanticAttributes.HTTP_METHOD]: method,\n [SemanticAttributes.HTTP_SCHEME]: options.component,\n };\n\n if (typeof ips === 'string') {\n attributes[SemanticAttributes.HTTP_CLIENT_IP] = ips.split(',')[0];\n }\n\n if (typeof serverName === 'string') {\n attributes[SemanticAttributes.HTTP_SERVER_NAME] = serverName;\n }\n\n if (requestUrl) {\n attributes[SemanticAttributes.HTTP_TARGET] = requestUrl.path || '/';\n }\n\n if (userAgent !== undefined) {\n attributes[SemanticAttributes.HTTP_USER_AGENT] = userAgent;\n }\n setRequestContentLengthAttribute(request, attributes);\n\n const httpKindAttributes = getAttributesFromHttpKind(httpVersion);\n return Object.assign(attributes, httpKindAttributes, options.hookAttributes);\n};\n\n/**\n * Returns incoming request Metric attributes scoped to the request data\n * @param {SpanAttributes} spanAttributes the span attributes\n * @param {{ component: string }} options used to pass data needed to create attributes\n */\nexport const getIncomingRequestMetricAttributes = (\n spanAttributes: SpanAttributes\n): MetricAttributes => {\n const metricAttributes: MetricAttributes = {};\n metricAttributes[SemanticAttributes.HTTP_SCHEME] =\n spanAttributes[SemanticAttributes.HTTP_SCHEME];\n metricAttributes[SemanticAttributes.HTTP_METHOD] =\n spanAttributes[SemanticAttributes.HTTP_METHOD];\n metricAttributes[SemanticAttributes.NET_HOST_NAME] =\n spanAttributes[SemanticAttributes.NET_HOST_NAME];\n metricAttributes[SemanticAttributes.HTTP_FLAVOR] =\n spanAttributes[SemanticAttributes.HTTP_FLAVOR];\n //TODO: http.target attribute, it should susbtitute any parameters to avoid high cardinality.\n return metricAttributes;\n};\n\n/**\n * Returns incoming request attributes scoped to the response data\n * @param {(ServerResponse & { socket: Socket; })} response the response object\n */\nexport const getIncomingRequestAttributesOnResponse = (\n request: IncomingMessage,\n response: ServerResponse\n): SpanAttributes => {\n // take socket from the request,\n // since it may be detached from the response object in keep-alive mode\n const { socket } = request;\n const { statusCode, statusMessage } = response;\n const { localAddress, localPort, remoteAddress, remotePort } = socket;\n const rpcMetadata = getRPCMetadata(context.active());\n\n const attributes: SpanAttributes = {\n [SemanticAttributes.NET_HOST_IP]: localAddress,\n [SemanticAttributes.NET_HOST_PORT]: localPort,\n [SemanticAttributes.NET_PEER_IP]: remoteAddress,\n [SemanticAttributes.NET_PEER_PORT]: remotePort,\n [SemanticAttributes.HTTP_STATUS_CODE]: statusCode,\n [AttributeNames.HTTP_STATUS_TEXT]: (statusMessage || '').toUpperCase(),\n };\n\n if (rpcMetadata?.type === RPCType.HTTP && rpcMetadata.route !== undefined) {\n attributes[SemanticAttributes.HTTP_ROUTE] = rpcMetadata.route;\n }\n return attributes;\n};\n\n/**\n * Returns incoming request Metric attributes scoped to the request data\n * @param {SpanAttributes} spanAttributes the span attributes\n */\nexport const getIncomingRequestMetricAttributesOnResponse = (\n spanAttributes: SpanAttributes\n): MetricAttributes => {\n const metricAttributes: MetricAttributes = {};\n metricAttributes[SemanticAttributes.HTTP_STATUS_CODE] =\n spanAttributes[SemanticAttributes.HTTP_STATUS_CODE];\n metricAttributes[SemanticAttributes.NET_HOST_PORT] =\n spanAttributes[SemanticAttributes.NET_HOST_PORT];\n if (spanAttributes[SemanticAttributes.HTTP_ROUTE] !== undefined) {\n metricAttributes[SemanticAttributes.HTTP_ROUTE] =\n spanAttributes[SemanticAttributes.HTTP_ROUTE];\n }\n return metricAttributes;\n};\n\nexport function headerCapture(type: 'request' | 'response', headers: string[]) {\n const normalizedHeaders = new Map(\n headers.map(header => [\n header.toLowerCase(),\n header.toLowerCase().replace(/-/g, '_'),\n ])\n );\n\n return (\n span: Span,\n getHeader: (key: string) => undefined | string | string[] | number\n ) => {\n for (const [capturedHeader, normalizedHeader] of normalizedHeaders) {\n const value = getHeader(capturedHeader);\n\n if (value === undefined) {\n continue;\n }\n\n const key = `http.${type}.header.${normalizedHeader}`;\n\n if (typeof value === 'string') {\n span.setAttribute(key, [value]);\n } else if (Array.isArray(value)) {\n span.setAttribute(key, value);\n } else {\n span.setAttribute(key, [value]);\n }\n }\n };\n}\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,4CAO4B;AAC5B,8EAG6C;AAQ7C,8CAA8D;AAC9D,2BAA2B;AAC3B,2DAAwD;AAGxD;;GAEG;AACI,MAAM,cAAc,GAAG,CAC5B,UAAuC,EACvC,OAAkD,EAClD,gBAAgB,GAAG,OAAO,EAClB,EAAE;IACV,MAAM,YAAY,GAAG,UAAU,IAAI,EAAE,CAAC;IACtC,MAAM,QAAQ,GAAG,YAAY,CAAC,QAAQ,IAAI,gBAAgB,CAAC;IAC3D,MAAM,IAAI,GAAG,CAAC,YAAY,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC;IAClD,MAAM,IAAI,GAAG,YAAY,CAAC,IAAI,IAAI,GAAG,CAAC;IACtC,IAAI,IAAI,GACN,YAAY,CAAC,IAAI,IAAI,YAAY,CAAC,QAAQ,IAAI,OAAO,CAAC,IAAI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CAAkB,CAAC,UAAU,CAAC;YAC7C,cAAc,CAAC,yCAAkB,CAAC,UAAU,CAAC,CAAC;KACjD;IACD,OAAO,gBAAgB,CAAC;AAC1B,CAAC,CAAC;AAbW,QAAA,4CAA4C,gDAavD;AAEF,SAAgB,aAAa,CAAC,IAA4B,EAAE,OAAiB;IAC3E,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAC/B,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;QACpB,MAAM,CAAC,WAAW,EAAE;QACpB,MAAM,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC;KACxC,CAAC,CACH,CAAC;IAEF,OAAO,CACL,IAAU,EACV,SAAkE,EAClE,EAAE;QACF,KAAK,MAAM,CAAC,cAAc,EAAE,gBAAgB,CAAC,IAAI,iBAAiB,EAAE;YAClE,MAAM,KAAK,GAAG,SAAS,CAAC,cAAc,CAAC,CAAC;YAExC,IAAI,KAAK,KAAK,SAAS,EAAE;gBACvB,SAAS;aACV;YAED,MAAM,GAAG,GAAG,QAAQ,IAAI,WAAW,gBAAgB,EAAE,CAAC;YAEtD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;gBAC7B,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;aACjC;iBAAM,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;gBAC/B,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;aAC/B;iBAAM;gBACL,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;aACjC;SACF;IACH,CAAC,CAAC;AACJ,CAAC;AA9BD,sCA8BC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n MetricAttributes,\n SpanAttributes,\n SpanStatusCode,\n Span,\n context,\n SpanKind,\n} from '@opentelemetry/api';\nimport {\n NetTransportValues,\n SemanticAttributes,\n} from '@opentelemetry/semantic-conventions';\nimport {\n IncomingHttpHeaders,\n IncomingMessage,\n OutgoingHttpHeaders,\n RequestOptions,\n ServerResponse,\n} from 'http';\nimport { getRPCMetadata, RPCType } from '@opentelemetry/core';\nimport * as url from 'url';\nimport { AttributeNames } from './enums/AttributeNames';\nimport { Err, IgnoreMatcher, ParsedRequestOptions } from './types';\n\n/**\n * Get an absolute url\n */\nexport const getAbsoluteUrl = (\n requestUrl: ParsedRequestOptions | null,\n headers: IncomingHttpHeaders | OutgoingHttpHeaders,\n fallbackProtocol = 'http:'\n): string => {\n const reqUrlObject = requestUrl || {};\n const protocol = reqUrlObject.protocol || fallbackProtocol;\n const port = (reqUrlObject.port || '').toString();\n const path = reqUrlObject.path || '/';\n let host =\n reqUrlObject.host || reqUrlObject.hostname || headers.host || 'localhost';\n\n // if there is no port in host and there is a port\n // it should be displayed if it's not 80 and 443 (default ports)\n if (\n (host as string).indexOf(':') === -1 &&\n port &&\n port !== '80' &&\n port !== '443'\n ) {\n host += `:${port}`;\n }\n\n return `${protocol}//${host}${path}`;\n};\n\n/**\n * Parse status code from HTTP response. [More details](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/data-http.md#status)\n */\nexport const parseResponseStatus = (\n kind: SpanKind,\n statusCode?: number\n): SpanStatusCode => {\n const upperBound = kind === SpanKind.CLIENT ? 400 : 500;\n // 1xx, 2xx, 3xx are OK on client and server\n // 4xx is OK on server\n if (statusCode && statusCode >= 100 && statusCode < upperBound) {\n return SpanStatusCode.UNSET;\n }\n\n // All other codes are error\n return SpanStatusCode.ERROR;\n};\n\n/**\n * Check whether the given obj match pattern\n * @param constant e.g URL of request\n * @param pattern Match pattern\n */\nexport const satisfiesPattern = (\n constant: string,\n pattern: IgnoreMatcher\n): boolean => {\n if (typeof pattern === 'string') {\n return pattern === constant;\n } else if (pattern instanceof RegExp) {\n return pattern.test(constant);\n } else if (typeof pattern === 'function') {\n return pattern(constant);\n } else {\n throw new TypeError('Pattern is in unsupported datatype');\n }\n};\n\n/**\n * Check whether the given request is ignored by configuration\n * It will not re-throw exceptions from `list` provided by the client\n * @param constant e.g URL of request\n * @param [list] List of ignore patterns\n * @param [onException] callback for doing something when an exception has\n * occurred\n */\nexport const isIgnored = (\n constant: string,\n list?: IgnoreMatcher[],\n onException?: (error: unknown) => void\n): boolean => {\n if (!list) {\n // No ignored urls - trace everything\n return false;\n }\n // Try/catch outside the loop for failing fast\n try {\n for (const pattern of list) {\n if (satisfiesPattern(constant, pattern)) {\n return true;\n }\n }\n } catch (e) {\n if (onException) {\n onException(e);\n }\n }\n\n return false;\n};\n\n/**\n * Sets the span with the error passed in params\n * @param {Span} span the span that need to be set\n * @param {Error} error error that will be set to span\n */\nexport const setSpanWithError = (span: Span, error: Err): void => {\n const message = error.message;\n\n span.setAttributes({\n [AttributeNames.HTTP_ERROR_NAME]: error.name,\n [AttributeNames.HTTP_ERROR_MESSAGE]: message,\n });\n\n span.setStatus({ code: SpanStatusCode.ERROR, message });\n span.recordException(error);\n};\n\n/**\n * Adds attributes for request content-length and content-encoding HTTP headers\n * @param { IncomingMessage } Request object whose headers will be analyzed\n * @param { SpanAttributes } SpanAttributes object to be modified\n */\nexport const setRequestContentLengthAttribute = (\n request: IncomingMessage,\n attributes: SpanAttributes\n): void => {\n const length = getContentLength(request.headers);\n if (length === null) return;\n\n if (isCompressed(request.headers)) {\n attributes[SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH] = length;\n } else {\n attributes[SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH_UNCOMPRESSED] =\n length;\n }\n};\n\n/**\n * Adds attributes for response content-length and content-encoding HTTP headers\n * @param { IncomingMessage } Response object whose headers will be analyzed\n * @param { SpanAttributes } SpanAttributes object to be modified\n */\nexport const setResponseContentLengthAttribute = (\n response: IncomingMessage,\n attributes: SpanAttributes\n): void => {\n const length = getContentLength(response.headers);\n if (length === null) return;\n\n if (isCompressed(response.headers)) {\n attributes[SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH] = length;\n } else {\n attributes[SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH_UNCOMPRESSED] =\n length;\n }\n};\n\nfunction getContentLength(\n headers: OutgoingHttpHeaders | IncomingHttpHeaders\n): number | null {\n const contentLengthHeader = headers['content-length'];\n if (contentLengthHeader === undefined) return null;\n\n const contentLength = parseInt(contentLengthHeader as string, 10);\n if (isNaN(contentLength)) return null;\n\n return contentLength;\n}\n\nexport const isCompressed = (\n headers: OutgoingHttpHeaders | IncomingHttpHeaders\n): boolean => {\n const encoding = headers['content-encoding'];\n\n return !!encoding && encoding !== 'identity';\n};\n\n/**\n * Makes sure options is an url object\n * return an object with default value and parsed options\n * @param options original options for the request\n * @param [extraOptions] additional options for the request\n */\nexport const getRequestInfo = (\n options: url.URL | RequestOptions | string,\n extraOptions?: RequestOptions\n): {\n origin: string;\n pathname: string;\n method: string;\n optionsParsed: RequestOptions;\n} => {\n let pathname = '/';\n let origin = '';\n let optionsParsed: RequestOptions;\n if (typeof options === 'string') {\n optionsParsed = url.parse(options);\n pathname = (optionsParsed as url.UrlWithStringQuery).pathname || '/';\n origin = `${optionsParsed.protocol || 'http:'}//${optionsParsed.host}`;\n if (extraOptions !== undefined) {\n Object.assign(optionsParsed, extraOptions);\n }\n } else if (options instanceof url.URL) {\n optionsParsed = {\n protocol: options.protocol,\n hostname:\n typeof options.hostname === 'string' && options.hostname.startsWith('[')\n ? options.hostname.slice(1, -1)\n : options.hostname,\n path: `${options.pathname || ''}${options.search || ''}`,\n };\n if (options.port !== '') {\n optionsParsed.port = Number(options.port);\n }\n if (options.username || options.password) {\n optionsParsed.auth = `${options.username}:${options.password}`;\n }\n pathname = options.pathname;\n origin = options.origin;\n if (extraOptions !== undefined) {\n Object.assign(optionsParsed, extraOptions);\n }\n } else {\n optionsParsed = Object.assign(\n { protocol: options.host ? 'http:' : undefined },\n options\n );\n pathname = (options as url.URL).pathname;\n if (!pathname && optionsParsed.path) {\n pathname = url.parse(optionsParsed.path).pathname || '/';\n }\n const hostname =\n optionsParsed.host ||\n (optionsParsed.port != null\n ? `${optionsParsed.hostname}${optionsParsed.port}`\n : optionsParsed.hostname);\n origin = `${optionsParsed.protocol || 'http:'}//${hostname}`;\n }\n\n // some packages return method in lowercase..\n // ensure upperCase for consistency\n const method = optionsParsed.method\n ? optionsParsed.method.toUpperCase()\n : 'GET';\n\n return { origin, pathname, method, optionsParsed };\n};\n\n/**\n * Makes sure options is of type string or object\n * @param options for the request\n */\nexport const isValidOptionsType = (options: unknown): boolean => {\n if (!options) {\n return false;\n }\n\n const type = typeof options;\n return type === 'string' || (type === 'object' && !Array.isArray(options));\n};\n\nexport const extractHostnameAndPort = (\n requestOptions: Pick<\n ParsedRequestOptions,\n 'hostname' | 'host' | 'port' | 'protocol'\n >\n): { hostname: string; port: number | string } => {\n if (requestOptions.hostname && requestOptions.port) {\n return { hostname: requestOptions.hostname, port: requestOptions.port };\n }\n const matches = requestOptions.host?.match(/^([^:/ ]+)(:\\d{1,5})?/) || null;\n const hostname =\n requestOptions.hostname || (matches === null ? 'localhost' : matches[1]);\n let port = requestOptions.port;\n if (!port) {\n if (matches && matches[2]) {\n // remove the leading \":\". The extracted port would be something like \":8080\"\n port = matches[2].substring(1);\n } else {\n port = requestOptions.protocol === 'https:' ? '443' : '80';\n }\n }\n return { hostname, port };\n};\n\n/**\n * Returns outgoing request attributes scoped to the options passed to the request\n * @param {ParsedRequestOptions} requestOptions the same options used to make the request\n * @param {{ component: string, hostname: string, hookAttributes?: SpanAttributes }} options used to pass data needed to create attributes\n */\nexport const getOutgoingRequestAttributes = (\n requestOptions: ParsedRequestOptions,\n options: {\n component: string;\n hostname: string;\n port: string | number;\n hookAttributes?: SpanAttributes;\n }\n): SpanAttributes => {\n const hostname = options.hostname;\n const port = options.port;\n const requestMethod = requestOptions.method;\n const method = requestMethod ? requestMethod.toUpperCase() : 'GET';\n const headers = requestOptions.headers || {};\n const userAgent = headers['user-agent'];\n const attributes: SpanAttributes = {\n [SemanticAttributes.HTTP_URL]: getAbsoluteUrl(\n requestOptions,\n headers,\n `${options.component}:`\n ),\n [SemanticAttributes.HTTP_METHOD]: method,\n [SemanticAttributes.HTTP_TARGET]: requestOptions.path || '/',\n [SemanticAttributes.NET_PEER_NAME]: hostname,\n [SemanticAttributes.HTTP_HOST]:\n requestOptions.headers?.host ?? `${hostname}:${port}`,\n };\n\n if (userAgent !== undefined) {\n attributes[SemanticAttributes.HTTP_USER_AGENT] = userAgent;\n }\n return Object.assign(attributes, options.hookAttributes);\n};\n\n/**\n * Returns outgoing request Metric attributes scoped to the request data\n * @param {SpanAttributes} spanAttributes the span attributes\n */\nexport const getOutgoingRequestMetricAttributes = (\n spanAttributes: SpanAttributes\n): MetricAttributes => {\n const metricAttributes: MetricAttributes = {};\n metricAttributes[SemanticAttributes.HTTP_METHOD] =\n spanAttributes[SemanticAttributes.HTTP_METHOD];\n metricAttributes[SemanticAttributes.NET_PEER_NAME] =\n spanAttributes[SemanticAttributes.NET_PEER_NAME];\n //TODO: http.url attribute, it should susbtitute any parameters to avoid high cardinality.\n return metricAttributes;\n};\n\n/**\n * Returns attributes related to the kind of HTTP protocol used\n * @param {string} [kind] Kind of HTTP protocol used: \"1.0\", \"1.1\", \"2\", \"SPDY\" or \"QUIC\".\n */\nexport const getAttributesFromHttpKind = (kind?: string): SpanAttributes => {\n const attributes: SpanAttributes = {};\n if (kind) {\n attributes[SemanticAttributes.HTTP_FLAVOR] = kind;\n if (kind.toUpperCase() !== 'QUIC') {\n attributes[SemanticAttributes.NET_TRANSPORT] = NetTransportValues.IP_TCP;\n } else {\n attributes[SemanticAttributes.NET_TRANSPORT] = NetTransportValues.IP_UDP;\n }\n }\n return attributes;\n};\n\n/**\n * Returns outgoing request attributes scoped to the response data\n * @param {IncomingMessage} response the response object\n * @param {{ hostname: string }} options used to pass data needed to create attributes\n */\nexport const getOutgoingRequestAttributesOnResponse = (\n response: IncomingMessage\n): SpanAttributes => {\n const { statusCode, statusMessage, httpVersion, socket } = response;\n const attributes: SpanAttributes = {};\n if (socket) {\n const { remoteAddress, remotePort } = socket;\n attributes[SemanticAttributes.NET_PEER_IP] = remoteAddress;\n attributes[SemanticAttributes.NET_PEER_PORT] = remotePort;\n }\n setResponseContentLengthAttribute(response, attributes);\n\n if (statusCode) {\n attributes[SemanticAttributes.HTTP_STATUS_CODE] = statusCode;\n attributes[AttributeNames.HTTP_STATUS_TEXT] = (\n statusMessage || ''\n ).toUpperCase();\n }\n\n const httpKindAttributes = getAttributesFromHttpKind(httpVersion);\n return Object.assign(attributes, httpKindAttributes);\n};\n\n/**\n * Returns outgoing request Metric attributes scoped to the response data\n * @param {SpanAttributes} spanAttributes the span attributes\n */\nexport const getOutgoingRequestMetricAttributesOnResponse = (\n spanAttributes: SpanAttributes\n): MetricAttributes => {\n const metricAttributes: MetricAttributes = {};\n metricAttributes[SemanticAttributes.NET_PEER_PORT] =\n spanAttributes[SemanticAttributes.NET_PEER_PORT];\n metricAttributes[SemanticAttributes.HTTP_STATUS_CODE] =\n spanAttributes[SemanticAttributes.HTTP_STATUS_CODE];\n metricAttributes[SemanticAttributes.HTTP_FLAVOR] =\n spanAttributes[SemanticAttributes.HTTP_FLAVOR];\n return metricAttributes;\n};\n\n/**\n * Returns incoming request attributes scoped to the request data\n * @param {IncomingMessage} request the request object\n * @param {{ component: string, serverName?: string, hookAttributes?: SpanAttributes }} options used to pass data needed to create attributes\n */\nexport const getIncomingRequestAttributes = (\n request: IncomingMessage,\n options: {\n component: string;\n serverName?: string;\n hookAttributes?: SpanAttributes;\n }\n): SpanAttributes => {\n const headers = request.headers;\n const userAgent = headers['user-agent'];\n const ips = headers['x-forwarded-for'];\n const method = request.method || 'GET';\n const httpVersion = request.httpVersion;\n const requestUrl = request.url ? url.parse(request.url) : null;\n const host = requestUrl?.host || headers.host;\n const hostname =\n requestUrl?.hostname ||\n host?.replace(/^(.*)(:[0-9]{1,5})/, '$1') ||\n 'localhost';\n const serverName = options.serverName;\n const attributes: SpanAttributes = {\n [SemanticAttributes.HTTP_URL]: getAbsoluteUrl(\n requestUrl,\n headers,\n `${options.component}:`\n ),\n [SemanticAttributes.HTTP_HOST]: host,\n [SemanticAttributes.NET_HOST_NAME]: hostname,\n [SemanticAttributes.HTTP_METHOD]: method,\n [SemanticAttributes.HTTP_SCHEME]: options.component,\n };\n\n if (typeof ips === 'string') {\n attributes[SemanticAttributes.HTTP_CLIENT_IP] = ips.split(',')[0];\n }\n\n if (typeof serverName === 'string') {\n attributes[SemanticAttributes.HTTP_SERVER_NAME] = serverName;\n }\n\n if (requestUrl) {\n attributes[SemanticAttributes.HTTP_TARGET] = requestUrl.path || '/';\n }\n\n if (userAgent !== undefined) {\n attributes[SemanticAttributes.HTTP_USER_AGENT] = userAgent;\n }\n setRequestContentLengthAttribute(request, attributes);\n\n const httpKindAttributes = getAttributesFromHttpKind(httpVersion);\n return Object.assign(attributes, httpKindAttributes, options.hookAttributes);\n};\n\n/**\n * Returns incoming request Metric attributes scoped to the request data\n * @param {SpanAttributes} spanAttributes the span attributes\n * @param {{ component: string }} options used to pass data needed to create attributes\n */\nexport const getIncomingRequestMetricAttributes = (\n spanAttributes: SpanAttributes\n): MetricAttributes => {\n const metricAttributes: MetricAttributes = {};\n metricAttributes[SemanticAttributes.HTTP_SCHEME] =\n spanAttributes[SemanticAttributes.HTTP_SCHEME];\n metricAttributes[SemanticAttributes.HTTP_METHOD] =\n spanAttributes[SemanticAttributes.HTTP_METHOD];\n metricAttributes[SemanticAttributes.NET_HOST_NAME] =\n spanAttributes[SemanticAttributes.NET_HOST_NAME];\n metricAttributes[SemanticAttributes.HTTP_FLAVOR] =\n spanAttributes[SemanticAttributes.HTTP_FLAVOR];\n //TODO: http.target attribute, it should susbtitute any parameters to avoid high cardinality.\n return metricAttributes;\n};\n\n/**\n * Returns incoming request attributes scoped to the response data\n * @param {(ServerResponse & { socket: Socket; })} response the response object\n */\nexport const getIncomingRequestAttributesOnResponse = (\n request: IncomingMessage,\n response: ServerResponse\n): SpanAttributes => {\n // take socket from the request,\n // since it may be detached from the response object in keep-alive mode\n const { socket } = request;\n const { statusCode, statusMessage } = response;\n\n const rpcMetadata = getRPCMetadata(context.active());\n const attributes: SpanAttributes = {};\n if (socket) {\n const { localAddress, localPort, remoteAddress, remotePort } = socket;\n attributes[SemanticAttributes.NET_HOST_IP] = localAddress;\n attributes[SemanticAttributes.NET_HOST_PORT] = localPort;\n attributes[SemanticAttributes.NET_PEER_IP] = remoteAddress;\n attributes[SemanticAttributes.NET_PEER_PORT] = remotePort;\n }\n attributes[SemanticAttributes.HTTP_STATUS_CODE] = statusCode;\n attributes[AttributeNames.HTTP_STATUS_TEXT] = (\n statusMessage || ''\n ).toUpperCase();\n\n if (rpcMetadata?.type === RPCType.HTTP && rpcMetadata.route !== undefined) {\n attributes[SemanticAttributes.HTTP_ROUTE] = rpcMetadata.route;\n }\n return attributes;\n};\n\n/**\n * Returns incoming request Metric attributes scoped to the request data\n * @param {SpanAttributes} spanAttributes the span attributes\n */\nexport const getIncomingRequestMetricAttributesOnResponse = (\n spanAttributes: SpanAttributes\n): MetricAttributes => {\n const metricAttributes: MetricAttributes = {};\n metricAttributes[SemanticAttributes.HTTP_STATUS_CODE] =\n spanAttributes[SemanticAttributes.HTTP_STATUS_CODE];\n metricAttributes[SemanticAttributes.NET_HOST_PORT] =\n spanAttributes[SemanticAttributes.NET_HOST_PORT];\n if (spanAttributes[SemanticAttributes.HTTP_ROUTE] !== undefined) {\n metricAttributes[SemanticAttributes.HTTP_ROUTE] =\n spanAttributes[SemanticAttributes.HTTP_ROUTE];\n }\n return metricAttributes;\n};\n\nexport function headerCapture(type: 'request' | 'response', headers: string[]) {\n const normalizedHeaders = new Map(\n headers.map(header => [\n header.toLowerCase(),\n header.toLowerCase().replace(/-/g, '_'),\n ])\n );\n\n return (\n span: Span,\n getHeader: (key: string) => undefined | string | string[] | number\n ) => {\n for (const [capturedHeader, normalizedHeader] of normalizedHeaders) {\n const value = getHeader(capturedHeader);\n\n if (value === undefined) {\n continue;\n }\n\n const key = `http.${type}.header.${normalizedHeader}`;\n\n if (typeof value === 'string') {\n span.setAttribute(key, [value]);\n } else if (Array.isArray(value)) {\n span.setAttribute(key, value);\n } else {\n span.setAttribute(key, [value]);\n }\n }\n };\n}\n"]}
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.40.0";
1
+ export declare const VERSION = "0.41.0";
2
2
  //# sourceMappingURL=version.d.ts.map
@@ -17,5 +17,5 @@
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.VERSION = void 0;
19
19
  // this is autogenerated file, see scripts/version-update.js
20
- exports.VERSION = '0.40.0';
20
+ exports.VERSION = '0.41.0';
21
21
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4DAA4D;AAC/C,QAAA,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '0.40.0';\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4DAA4D;AAC/C,QAAA,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '0.41.0';\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentelemetry/instrumentation-http",
3
- "version": "0.40.0",
3
+ "version": "0.41.0",
4
4
  "description": "OpenTelemetry http/https automatic instrumentation package.",
5
5
  "main": "build/src/index.js",
6
6
  "types": "build/src/index.d.ts",
@@ -16,7 +16,7 @@
16
16
  "codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../../",
17
17
  "version": "node ../../../scripts/version-update.js",
18
18
  "watch": "tsc --build --watch",
19
- "precompile": "lerna run version --scope $(npm pkg get name) --include-dependencies",
19
+ "precompile": "cross-var lerna run version --scope $npm_package_name --include-dependencies",
20
20
  "prewatch": "node ../../../scripts/version-update.js",
21
21
  "peer-api-check": "node ../../../scripts/peer-api-check.js"
22
22
  },
@@ -46,25 +46,27 @@
46
46
  },
47
47
  "devDependencies": {
48
48
  "@opentelemetry/api": "1.4.1",
49
- "@opentelemetry/context-async-hooks": "1.14.0",
50
- "@opentelemetry/sdk-metrics": "1.14.0",
51
- "@opentelemetry/sdk-trace-base": "1.14.0",
52
- "@opentelemetry/sdk-trace-node": "1.14.0",
53
- "@types/mocha": "10.0.0",
49
+ "@opentelemetry/context-async-hooks": "1.15.0",
50
+ "@opentelemetry/sdk-metrics": "1.15.0",
51
+ "@opentelemetry/sdk-trace-base": "1.15.0",
52
+ "@opentelemetry/sdk-trace-node": "1.15.0",
53
+ "@types/mocha": "10.0.1",
54
54
  "@types/node": "18.6.5",
55
55
  "@types/request-promise-native": "1.0.18",
56
- "@types/semver": "7.3.9",
57
- "@types/sinon": "10.0.13",
58
- "@types/superagent": "4.1.13",
56
+ "@types/semver": "7.5.0",
57
+ "@types/sinon": "10.0.15",
58
+ "@types/superagent": "4.1.18",
59
59
  "axios": "1.4.0",
60
60
  "codecov": "3.8.3",
61
- "mocha": "10.0.0",
62
- "nock": "13.0.11",
61
+ "cross-var": "1.1.0",
62
+ "lerna": "7.1.1",
63
+ "mocha": "10.2.0",
64
+ "nock": "13.3.1",
63
65
  "nyc": "15.1.0",
64
66
  "request": "2.88.2",
65
67
  "request-promise-native": "1.0.9",
66
- "sinon": "15.0.0",
67
- "superagent": "8.0.0",
68
+ "sinon": "15.1.2",
69
+ "superagent": "8.0.9",
68
70
  "ts-mocha": "10.0.0",
69
71
  "typescript": "4.4.4"
70
72
  },
@@ -72,12 +74,13 @@
72
74
  "@opentelemetry/api": "^1.3.0"
73
75
  },
74
76
  "dependencies": {
75
- "@opentelemetry/core": "1.14.0",
76
- "@opentelemetry/instrumentation": "0.40.0",
77
- "@opentelemetry/semantic-conventions": "1.14.0",
78
- "semver": "^7.3.5"
77
+ "@opentelemetry/core": "1.15.0",
78
+ "@opentelemetry/instrumentation": "0.41.0",
79
+ "@opentelemetry/semantic-conventions": "1.15.0",
80
+ "semver": "^7.5.1",
81
+ "tslib": "^2.3.1"
79
82
  },
80
83
  "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/opentelemetry-instrumentation-http",
81
84
  "sideEffects": false,
82
- "gitHead": "edebbcc757535bc88f01340409dbbecc0bb6ccf8"
85
+ "gitHead": "06e919d6c909e8cc8e28b6624d9843f401d9b059"
83
86
  }