@opentelemetry/instrumentation-http 0.300.0 → 0.301.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.
- package/dist/utils.cjs +2 -2
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.mjs +2 -3
- package/dist/utils.mjs.map +1 -1
- package/dist/version.cjs +1 -1
- package/dist/version.cjs.map +1 -1
- package/dist/version.mjs +1 -1
- package/dist/version.mjs.map +1 -1
- package/package.json +9 -9
- package/dist/_virtual/_rolldown/runtime.mjs +0 -5
package/dist/utils.cjs
CHANGED
|
@@ -3,8 +3,8 @@ const require_internal_types = require("./internal-types.cjs");
|
|
|
3
3
|
let _opentelemetry_api = require("@opentelemetry/api");
|
|
4
4
|
let _opentelemetry_core = require("@opentelemetry/core");
|
|
5
5
|
let _opentelemetry_semantic_conventions = require("@opentelemetry/semantic-conventions");
|
|
6
|
+
let forwarded_parse = require("forwarded-parse");
|
|
6
7
|
//#region src/utils.ts
|
|
7
|
-
const forwardedParse = require("forwarded-parse");
|
|
8
8
|
const defaultQueryStringsToRedact = Array.from(require_internal_types.DEFAULT_QUERY_STRINGS_TO_REDACT);
|
|
9
9
|
/**
|
|
10
10
|
* Redacts sensitive query parameters from a query string (without leading '?').
|
|
@@ -459,7 +459,7 @@ function normalizeMethod(method) {
|
|
|
459
459
|
}
|
|
460
460
|
function parseForwardedHeader(header) {
|
|
461
461
|
try {
|
|
462
|
-
return
|
|
462
|
+
return (0, forwarded_parse.parse)(header);
|
|
463
463
|
} catch {
|
|
464
464
|
return [];
|
|
465
465
|
}
|
package/dist/utils.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.cjs","names":["DEFAULT_QUERY_STRINGS_TO_REDACT","STR_REDACTED","SpanKind","SpanStatusCode","ATTR_ERROR_TYPE","ATTR_HTTP_REQUEST_METHOD","ATTR_SERVER_ADDRESS","ATTR_SERVER_PORT","ATTR_URL_FULL","ATTR_USER_AGENT_ORIGINAL","ATTR_HTTP_REQUEST_METHOD_ORIGINAL","ATTR_USER_AGENT_SYNTHETIC_TYPE","SYNTHETIC_TEST_NAMES","USER_AGENT_SYNTHETIC_TYPE_VALUE_TEST","SYNTHETIC_BOT_NAMES","ATTR_HTTP_RESPONSE_STATUS_CODE","ATTR_NETWORK_PEER_ADDRESS","ATTR_NETWORK_PEER_PORT","ATTR_NETWORK_PROTOCOL_VERSION","ATTR_URL_SCHEME","ATTR_URL_PATH","ATTR_URL_QUERY","ATTR_CLIENT_ADDRESS","getRPCMetadata","context","RPCType","ATTR_HTTP_ROUTE"],"sources":["../src/utils.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\nimport type {\n Attributes,\n Span,\n DiagLogger,\n AttributeValue,\n} from '@opentelemetry/api';\nimport { SpanStatusCode, context, SpanKind } from '@opentelemetry/api';\nimport {\n ATTR_CLIENT_ADDRESS,\n ATTR_ERROR_TYPE,\n ATTR_HTTP_REQUEST_METHOD,\n ATTR_HTTP_REQUEST_METHOD_ORIGINAL,\n ATTR_HTTP_RESPONSE_STATUS_CODE,\n ATTR_HTTP_ROUTE,\n ATTR_NETWORK_PEER_ADDRESS,\n ATTR_NETWORK_PEER_PORT,\n ATTR_NETWORK_PROTOCOL_VERSION,\n ATTR_SERVER_ADDRESS,\n ATTR_SERVER_PORT,\n ATTR_URL_FULL,\n ATTR_URL_PATH,\n ATTR_URL_QUERY,\n ATTR_URL_SCHEME,\n ATTR_USER_AGENT_ORIGINAL,\n} from '@opentelemetry/semantic-conventions';\nimport {\n ATTR_USER_AGENT_SYNTHETIC_TYPE,\n USER_AGENT_SYNTHETIC_TYPE_VALUE_BOT,\n USER_AGENT_SYNTHETIC_TYPE_VALUE_TEST,\n} from './semconv';\nimport type {\n IncomingHttpHeaders,\n IncomingMessage,\n OutgoingHttpHeader,\n OutgoingHttpHeaders,\n RequestOptions,\n ServerResponse,\n} from 'http';\nimport { getRPCMetadata, RPCType } from '@opentelemetry/core';\nimport type * as url from 'url';\nimport type {\n Err,\n IgnoreMatcher,\n ParsedRequestOptions,\n} from './internal-types';\nimport { SYNTHETIC_BOT_NAMES, SYNTHETIC_TEST_NAMES } from './internal-types';\nimport {\n DEFAULT_QUERY_STRINGS_TO_REDACT,\n STR_REDACTED,\n} from './internal-types';\n// eslint-disable-next-line @typescript-eslint/no-require-imports\nimport forwardedParse = require('forwarded-parse');\n\nconst defaultQueryStringsToRedact = Array.from(DEFAULT_QUERY_STRINGS_TO_REDACT);\n\n/**\n * Redacts sensitive query parameters from a query string (without leading '?').\n * Returns the input unchanged if it cannot be parsed.\n */\nexport const redactQueryString = (\n searchParams: URLSearchParams,\n paramsToRedact: string[]\n): string => {\n const params = new URLSearchParams(searchParams);\n for (const param of paramsToRedact) {\n if (params.has(param)) {\n params.set(param, STR_REDACTED);\n }\n }\n return params.toString();\n};\n\n/**\n * Get an absolute url\n */\nexport const getAbsoluteUrl = (\n requestUrl: ParsedRequestOptions | null,\n headers: IncomingHttpHeaders | OutgoingHttpHeaders,\n fallbackProtocol = 'http:',\n redactedQueryParams: string[] = Array.from(DEFAULT_QUERY_STRINGS_TO_REDACT)\n): string => {\n const reqUrlObject = requestUrl || {};\n const protocol = reqUrlObject.protocol || fallbackProtocol;\n const port = (reqUrlObject.port || '').toString();\n let path = reqUrlObject.path || '/';\n // `host`, `hostname` and the `host` header may hold values of unexpected\n // types at runtime. Node.js itself ignores non-string values when it can\n // derive the target from another option (e.g. it uses `hostname` when\n // `host` is not a valid string), so skip non-string candidates instead of\n // crashing on them.\n let host: string =\n (typeof reqUrlObject.host === 'string' && reqUrlObject.host) ||\n (typeof reqUrlObject.hostname === 'string' && reqUrlObject.hostname) ||\n (typeof headers.host === 'string' && headers.host) ||\n 'localhost';\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 (host.indexOf(':') === -1 && port && port !== '80' && port !== '443') {\n host += `:${port}`;\n }\n // Redact sensitive query parameters\n if (typeof path === 'string' && path.includes('?')) {\n try {\n const parsedUrl = new URL(path, 'http://localhost');\n const redacted = redactQueryString(\n parsedUrl.searchParams,\n redactedQueryParams\n );\n path = `${parsedUrl.pathname}?${redacted}`;\n } catch {\n // Ignore error, as the path was not a valid URL.\n }\n }\n const authPart = reqUrlObject.auth ? `${STR_REDACTED}:${STR_REDACTED}@` : '';\n return `${protocol}//${authPart}${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 * Returns the `error.type` value for a response status code, or undefined when\n * the code is not an error for this span kind. Semconv asks for the status code\n * as a string once a response was received.\n */\nexport const parseErrorType = (\n kind: SpanKind,\n statusCode?: unknown\n): string | undefined => {\n const lowerBound = kind === SpanKind.CLIENT ? 400 : 500;\n if (\n typeof statusCode === 'number' &&\n statusCode >= lowerBound &&\n statusCode < 600\n ) {\n return String(statusCode);\n }\n\n return undefined;\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 * 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 span.setAttribute(ATTR_ERROR_TYPE, error.name);\n span.setStatus({ code: SpanStatusCode.ERROR, message });\n span.recordException(error);\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 * Mimics Node.js conversion of URL strings to RequestOptions expected by\n * `http.request` and `https.request` APIs.\n *\n * See https://github.com/nodejs/node/blob/2505e217bba05fc581b572c685c5cf280a16c5a3/lib/internal/url.js#L1415-L1437\n *\n * @param stringUrl\n * @throws TypeError if the URL is not valid.\n */\nfunction stringUrlToHttpOptions(\n stringUrl: string\n): RequestOptions & { pathname: string } {\n // This is heavily inspired by Node.js handling of the same situation, trying\n // to follow it as closely as possible while keeping in mind that we only\n // deal with string URLs, not URL objects.\n const {\n hostname,\n pathname,\n port,\n username,\n password,\n search,\n protocol,\n hash,\n href,\n origin,\n host,\n } = new URL(stringUrl);\n\n const options: RequestOptions & {\n pathname: string;\n hash: string;\n search: string;\n href: string;\n origin: string;\n } = {\n protocol: protocol,\n hostname:\n hostname && hostname[0] === '[' ? hostname.slice(1, -1) : hostname,\n hash: hash,\n search: search,\n pathname: pathname,\n path: `${pathname || ''}${search || ''}`,\n href: href,\n origin: origin,\n host: host,\n };\n if (port !== '') {\n options.port = Number(port);\n }\n if (username || password) {\n options.auth = `${decodeURIComponent(username)}:${decodeURIComponent(\n password\n )}`;\n }\n return options;\n}\n\n/**\n * Mirrors how Node.js detects WHATWG `URL` objects passed to `http.request`\n * and `https.request`: by shape rather than by `instanceof`, so that URL\n * objects from other realms (e.g. `vm` contexts) or WHATWG URL polyfills are\n * handled the same way Node.js handles them.\n *\n * This mirrors Node's `isURL()` predicate exactly. The `auth`/`path` guards\n * matter: they keep options objects and legacy `url.parse()` results (both\n * carry `path`) off the URL code path.\n *\n * See https://github.com/nodejs/node/blob/2505e217bba05fc581b572c685c5cf280a16c5a3/lib/internal/url.js#L756-L773\n */\nexport const isURLLike = (value: unknown): value is url.URL => {\n const candidate = value as\n | (url.URL & { auth?: unknown; path?: unknown })\n | undefined;\n return Boolean(\n candidate?.href &&\n candidate.protocol &&\n candidate.auth === undefined &&\n candidate.path === undefined\n );\n};\n\n/**\n * Makes sure options is an url object\n * return an object with default value and parsed options\n * @param logger component logger\n * @param options original options for the request\n * @param [extraOptions] additional options for the request\n */\nexport const getRequestInfo = (\n logger: DiagLogger,\n options: url.URL | RequestOptions | string,\n extraOptions?: RequestOptions\n): {\n origin: string;\n pathname: string;\n method: string;\n invalidUrl: boolean;\n optionsParsed: RequestOptions;\n} => {\n let pathname: string;\n let origin: string;\n let optionsParsed: RequestOptions;\n let invalidUrl = false;\n if (typeof options === 'string') {\n try {\n const convertedOptions = stringUrlToHttpOptions(options);\n optionsParsed = convertedOptions;\n pathname = convertedOptions.pathname || '/';\n } catch (e) {\n invalidUrl = true;\n logger.verbose(\n 'Unable to parse URL provided to HTTP request, using fallback to determine path. Original error:',\n e\n );\n // for backward compatibility with how url.parse() behaved.\n optionsParsed = {\n path: options,\n };\n pathname = optionsParsed.path || '/';\n }\n\n origin = `${optionsParsed.protocol || 'http:'}//${optionsParsed.host}`;\n if (extraOptions !== undefined) {\n Object.assign(optionsParsed, extraOptions);\n }\n } else if (isURLLike(options)) {\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\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 pathname = (options as url.URL).pathname;\n if (!pathname && optionsParsed.path) {\n try {\n const parsedUrl = new URL(optionsParsed.path, origin);\n pathname = parsedUrl.pathname || '/';\n } catch {\n pathname = '/';\n }\n }\n }\n\n // some packages return method in lowercase..\n // ensure upperCase for consistency\n // Note: a non-string `method` is rejected by Node.js itself; skip it here\n // so the resulting error comes from Node.js and not the instrumentation.\n const method =\n optionsParsed.method && typeof optionsParsed.method === 'string'\n ? optionsParsed.method.toUpperCase()\n : 'GET';\n\n return { origin, pathname, method, optionsParsed, invalidUrl };\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 // `hostname`, `host` and `port` may hold values of unexpected types at\n // runtime. Node.js itself ignores non-string values when it can derive the\n // target from another option (e.g. it uses `hostname` when `host` is not a\n // valid string), so skip non-string candidates instead of crashing on them.\n const optionsHostname =\n typeof requestOptions.hostname === 'string'\n ? requestOptions.hostname\n : undefined;\n const optionsHost =\n typeof requestOptions.host === 'string' ? requestOptions.host : undefined;\n const optionsPort =\n typeof requestOptions.port === 'string' ||\n typeof requestOptions.port === 'number'\n ? requestOptions.port\n : undefined;\n\n if (optionsHostname && optionsPort) {\n return { hostname: optionsHostname, port: optionsPort };\n }\n const matches = optionsHost?.match(/^([^:/ ]+)(:\\d{1,5})?/) || null;\n const hostname =\n optionsHostname || (matches === null ? 'localhost' : matches[1]);\n let port = optionsPort;\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?: Attributes }} 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?: Attributes;\n redactedQueryParams?: string[];\n },\n enableSyntheticSourceDetection: boolean\n): Attributes => {\n const hostname = options.hostname;\n const port = options.port;\n const method = requestOptions.method ?? 'GET';\n const normalizedMethod = normalizeMethod(method);\n const headers = (requestOptions.headers || {}) as OutgoingHttpHeaders;\n const userAgent = headers['user-agent'];\n const urlFull = getAbsoluteUrl(\n requestOptions,\n headers,\n `${options.component}:`,\n options.redactedQueryParams\n );\n\n const attributes: Attributes = {\n // Required attributes\n [ATTR_HTTP_REQUEST_METHOD]: normalizedMethod,\n [ATTR_SERVER_ADDRESS]: hostname,\n [ATTR_SERVER_PORT]: Number(port),\n [ATTR_URL_FULL]: urlFull,\n [ATTR_USER_AGENT_ORIGINAL]: userAgent,\n // leaving out protocol version, it is not yet negotiated\n // leaving out protocol name, it is only required when protocol version is set\n // retries and redirects not supported\n\n // Opt-in attributes left off for now\n };\n\n // conditionally required if request method required case normalization\n if (method !== normalizedMethod) {\n attributes[ATTR_HTTP_REQUEST_METHOD_ORIGINAL] = method;\n }\n\n if (enableSyntheticSourceDetection && userAgent) {\n attributes[ATTR_USER_AGENT_SYNTHETIC_TYPE] = getSyntheticType(userAgent);\n }\n return Object.assign(attributes, options.hookAttributes);\n};\n\n/**\n * Returns the type of synthetic source based on the user agent\n * @param {OutgoingHttpHeader} userAgent the user agent string\n */\nconst getSyntheticType = (\n userAgent: OutgoingHttpHeader\n): AttributeValue | undefined => {\n const userAgentString: string = String(userAgent).toLowerCase();\n for (const name of SYNTHETIC_TEST_NAMES) {\n if (userAgentString.includes(name)) {\n return USER_AGENT_SYNTHETIC_TYPE_VALUE_TEST;\n }\n }\n for (const name of SYNTHETIC_BOT_NAMES) {\n if (userAgentString.includes(name)) {\n return USER_AGENT_SYNTHETIC_TYPE_VALUE_BOT;\n }\n }\n return;\n};\n\n/**\n * Returns outgoing request attributes scoped to the response data\n * @param {IncomingMessage} response the response object\n */\nexport const getOutgoingRequestAttributesOnResponse = (\n response: IncomingMessage\n): Attributes => {\n const { statusCode, socket } = response;\n const attributes: Attributes = {};\n\n if (statusCode != null) {\n attributes[ATTR_HTTP_RESPONSE_STATUS_CODE] = statusCode;\n }\n\n if (socket) {\n const { remoteAddress, remotePort } = socket;\n\n // Recommended\n attributes[ATTR_NETWORK_PEER_ADDRESS] = remoteAddress;\n attributes[ATTR_NETWORK_PEER_PORT] = remotePort;\n attributes[ATTR_NETWORK_PROTOCOL_VERSION] = response.httpVersion;\n }\n return attributes;\n};\n\n/**\n * Returns outgoing request Metric attributes scoped to the response data\n * @param {Attributes} spanAttributes the span attributes\n */\nexport const getOutgoingStableRequestMetricAttributesOnResponse = (\n spanAttributes: Attributes\n): Attributes => {\n const metricAttributes: Attributes = {};\n\n if (spanAttributes[ATTR_NETWORK_PROTOCOL_VERSION]) {\n metricAttributes[ATTR_NETWORK_PROTOCOL_VERSION] =\n spanAttributes[ATTR_NETWORK_PROTOCOL_VERSION];\n }\n\n const statusCode = spanAttributes[ATTR_HTTP_RESPONSE_STATUS_CODE];\n if (statusCode) {\n metricAttributes[ATTR_HTTP_RESPONSE_STATUS_CODE] = statusCode;\n const errorType = parseErrorType(SpanKind.CLIENT, statusCode);\n if (errorType !== undefined) {\n metricAttributes[ATTR_ERROR_TYPE] ??= errorType;\n }\n }\n return metricAttributes;\n};\n\nfunction parseHostHeader(\n hostHeader: string,\n proto?: string\n): { host: string; port?: string } {\n const parts = hostHeader.split(':');\n\n // no semicolon implies ipv4 dotted syntax or host name without port\n // x.x.x.x\n // example.com\n if (parts.length === 1) {\n if (proto === 'http') {\n return { host: parts[0], port: '80' };\n }\n\n if (proto === 'https') {\n return { host: parts[0], port: '443' };\n }\n\n return { host: parts[0] };\n }\n\n // single semicolon implies ipv4 dotted syntax or host name with port\n // x.x.x.x:yyyy\n // example.com:yyyy\n if (parts.length === 2) {\n return {\n host: parts[0],\n port: parts[1],\n };\n }\n\n // more than 2 parts implies ipv6 syntax with multiple colons\n // [x:x:x:x:x:x:x:x]\n // [x:x:x:x:x:x:x:x]:yyyy\n if (parts[0].startsWith('[')) {\n if (parts[parts.length - 1].endsWith(']')) {\n if (proto === 'http') {\n return { host: hostHeader, port: '80' };\n }\n\n if (proto === 'https') {\n return { host: hostHeader, port: '443' };\n }\n } else if (parts[parts.length - 2].endsWith(']')) {\n return {\n host: parts.slice(0, -1).join(':'),\n port: parts[parts.length - 1],\n };\n }\n }\n\n // if nothing above matches just return the host header\n return { host: hostHeader };\n}\n\n/**\n * Get server.address and port according to http semconv 1.27\n * https://github.com/open-telemetry/semantic-conventions/blob/bf0a2c1134f206f034408b201dbec37960ed60ec/docs/http/http-spans.md#setting-serveraddress-and-serverport-attributes\n */\nfunction getServerAddress(\n request: IncomingMessage,\n component: 'http' | 'https'\n): { host: string; port?: string } | null {\n const forwardedHeader = request.headers['forwarded'];\n if (forwardedHeader) {\n for (const entry of parseForwardedHeader(forwardedHeader)) {\n if (entry.host) {\n return parseHostHeader(entry.host, entry.proto);\n }\n }\n }\n\n const xForwardedHost = request.headers['x-forwarded-host'];\n if (typeof xForwardedHost === 'string') {\n if (typeof request.headers['x-forwarded-proto'] === 'string') {\n return parseHostHeader(\n xForwardedHost,\n request.headers['x-forwarded-proto']\n );\n }\n\n if (Array.isArray(request.headers['x-forwarded-proto'])) {\n return parseHostHeader(\n xForwardedHost,\n request.headers['x-forwarded-proto'][0]\n );\n }\n\n return parseHostHeader(xForwardedHost);\n } else if (\n Array.isArray(xForwardedHost) &&\n typeof xForwardedHost[0] === 'string' &&\n xForwardedHost[0].length > 0\n ) {\n if (typeof request.headers['x-forwarded-proto'] === 'string') {\n return parseHostHeader(\n xForwardedHost[0],\n request.headers['x-forwarded-proto']\n );\n }\n\n if (Array.isArray(request.headers['x-forwarded-proto'])) {\n return parseHostHeader(\n xForwardedHost[0],\n request.headers['x-forwarded-proto'][0]\n );\n }\n\n return parseHostHeader(xForwardedHost[0]);\n }\n\n const host = request.headers['host'];\n if (typeof host === 'string' && host.length > 0) {\n return parseHostHeader(host, component);\n }\n\n return null;\n}\n\n/**\n * Get server.address and port according to http semconv 1.27\n * https://github.com/open-telemetry/semantic-conventions/blob/bf0a2c1134f206f034408b201dbec37960ed60ec/docs/http/http-spans.md#setting-serveraddress-and-serverport-attributes\n */\nexport function getRemoteClientAddress(\n request: IncomingMessage\n): string | null {\n const forwardedHeader = request.headers['forwarded'];\n if (forwardedHeader) {\n for (const entry of parseForwardedHeader(forwardedHeader)) {\n if (entry.for) {\n return removePortFromAddress(entry.for);\n }\n }\n }\n\n const xForwardedFor = request.headers['x-forwarded-for'];\n if (xForwardedFor) {\n let xForwardedForVal;\n if (typeof xForwardedFor === 'string') {\n xForwardedForVal = xForwardedFor;\n } else if (Array.isArray(xForwardedFor)) {\n xForwardedForVal = xForwardedFor[0];\n }\n\n if (typeof xForwardedForVal === 'string') {\n xForwardedForVal = xForwardedForVal.split(',')[0].trim();\n return removePortFromAddress(xForwardedForVal);\n }\n }\n\n const remote = request.socket.remoteAddress;\n if (remote) {\n return remote;\n }\n\n return null;\n}\n\nfunction removePortFromAddress(input: string): string {\n // This function can be replaced with SocketAddress.parse() once the minimum\n // supported Node.js version allows it.\n try {\n const { hostname: address } = new URL(`http://${input}`);\n\n if (address.startsWith('[') && address.endsWith(']')) {\n return address.slice(1, -1);\n }\n\n return address;\n } catch {\n return input;\n }\n}\n\nfunction getInfoFromIncomingMessage(\n component: 'http' | 'https',\n request: IncomingMessage,\n logger: DiagLogger\n): { pathname?: string; search?: string; toString: () => string } {\n try {\n if (request.headers.host) {\n return new URL(\n request.url ?? '/',\n `${component}://${request.headers.host}`\n );\n } else {\n const unsafeParsedUrl = new URL(\n request.url ?? '/',\n // using localhost as a workaround to still use the URL constructor for parsing\n `${component}://localhost`\n );\n // since we use localhost as a workaround, ensure we hide the rest of the properties to avoid\n // our workaround leaking though.\n return {\n pathname: unsafeParsedUrl.pathname,\n search: unsafeParsedUrl.search,\n toString: function () {\n // we cannot use the result of unsafeParsedUrl.toString as it's potentially wrong.\n return unsafeParsedUrl.pathname + unsafeParsedUrl.search;\n },\n };\n }\n } catch (e) {\n // something is wrong, use undefined - this *should* never happen, logging\n // for troubleshooting in case it does happen.\n logger.verbose('Unable to get URL from request', e);\n return {};\n }\n}\n\n/**\n * Returns incoming request attributes scoped to the request data\n * @param {IncomingMessage} request the request object\n * @param {{ component: string, hookAttributes?: Attributes, enableSyntheticSourceDetection: boolean }} options used to pass data needed to create attributes\n */\nexport const getIncomingRequestAttributes = (\n request: IncomingMessage,\n options: {\n component: 'http' | 'https';\n hookAttributes?: Attributes;\n enableSyntheticSourceDetection: boolean;\n redactedQueryParams?: string[];\n },\n logger: DiagLogger\n): Attributes => {\n const {\n component,\n enableSyntheticSourceDetection,\n hookAttributes,\n redactedQueryParams,\n } = options;\n const { headers, method } = request;\n const { 'user-agent': userAgent } = headers;\n const parsedUrl = getInfoFromIncomingMessage(component, request, logger);\n\n // Stable attributes are used.\n const normalizedMethod = normalizeMethod(method);\n const serverAddress = getServerAddress(request, component);\n const remoteClientAddress = getRemoteClientAddress(request);\n\n const attributes: Attributes = {\n [ATTR_HTTP_REQUEST_METHOD]: normalizedMethod,\n [ATTR_URL_SCHEME]: component,\n [ATTR_SERVER_ADDRESS]: serverAddress?.host,\n [ATTR_NETWORK_PEER_ADDRESS]: request.socket.remoteAddress,\n [ATTR_NETWORK_PEER_PORT]: request.socket.remotePort,\n [ATTR_NETWORK_PROTOCOL_VERSION]: request.httpVersion,\n [ATTR_USER_AGENT_ORIGINAL]: userAgent,\n };\n\n if (parsedUrl.pathname != null) {\n attributes[ATTR_URL_PATH] = parsedUrl.pathname;\n }\n\n if (parsedUrl.search) {\n // Remove leading '?' from URL search (https://developer.mozilla.org/en-US/docs/Web/API/URL/search).\n const paramsToRedact = redactedQueryParams ?? defaultQueryStringsToRedact;\n attributes[ATTR_URL_QUERY] = redactQueryString(\n new URLSearchParams(parsedUrl.search.slice(1)),\n paramsToRedact\n );\n }\n\n if (remoteClientAddress != null) {\n attributes[ATTR_CLIENT_ADDRESS] = remoteClientAddress;\n }\n\n if (serverAddress?.port != null) {\n attributes[ATTR_SERVER_PORT] = Number(serverAddress.port);\n }\n\n // Conditionally required if request method required case normalization.\n if (method !== normalizedMethod) {\n attributes[ATTR_HTTP_REQUEST_METHOD_ORIGINAL] = method;\n }\n\n if (enableSyntheticSourceDetection && userAgent) {\n attributes[ATTR_USER_AGENT_SYNTHETIC_TYPE] = getSyntheticType(userAgent);\n }\n\n return Object.assign(attributes, hookAttributes);\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 response: ServerResponse\n): Attributes => {\n const { statusCode } = response;\n\n const attributes: Attributes = {\n [ATTR_HTTP_RESPONSE_STATUS_CODE]: statusCode,\n };\n\n const rpcMetadata = getRPCMetadata(context.active());\n if (rpcMetadata?.type === RPCType.HTTP && rpcMetadata.route !== undefined) {\n attributes[ATTR_HTTP_ROUTE] = rpcMetadata.route;\n }\n\n return attributes;\n};\n\n/**\n * Returns incoming stable request Metric attributes scoped to the request data\n * @param {Attributes} spanAttributes the span attributes\n */\nexport const getIncomingStableRequestMetricAttributesOnResponse = (\n spanAttributes: Attributes\n): Attributes => {\n const metricAttributes: Attributes = {};\n if (spanAttributes[ATTR_HTTP_ROUTE] !== undefined) {\n metricAttributes[ATTR_HTTP_ROUTE] = spanAttributes[ATTR_HTTP_ROUTE];\n }\n\n // required if and only if one was sent, same as span requirement\n const statusCode = spanAttributes[ATTR_HTTP_RESPONSE_STATUS_CODE];\n if (statusCode) {\n metricAttributes[ATTR_HTTP_RESPONSE_STATUS_CODE] = statusCode;\n const errorType = parseErrorType(SpanKind.SERVER, statusCode);\n if (errorType !== undefined) {\n metricAttributes[ATTR_ERROR_TYPE] ??= errorType;\n }\n }\n\n return metricAttributes;\n};\n\nexport function headerCapture(type: 'request' | 'response', headers: string[]) {\n const normalizedHeaders = new Map<string, string>();\n for (let i = 0, len = headers.length; i < len; i++) {\n const capturedHeader = headers[i].toLowerCase();\n normalizedHeaders.set(capturedHeader, capturedHeader);\n }\n\n return (\n getHeader: (key: string) => undefined | string | string[] | number\n ): Attributes => {\n const attributes: Attributes = {};\n for (const capturedHeader of normalizedHeaders.keys()) {\n const value = getHeader(capturedHeader);\n\n if (value === undefined) {\n continue;\n }\n\n const normalizedHeader = normalizedHeaders.get(capturedHeader);\n const key = `http.${type}.header.${normalizedHeader}`;\n\n if (typeof value === 'string') {\n attributes[key] = [value];\n } else if (Array.isArray(value)) {\n attributes[key] = value;\n } else {\n attributes[key] = [value];\n }\n }\n return attributes;\n };\n}\n\nconst KNOWN_METHODS = new Set([\n // methods from https://www.rfc-editor.org/rfc/rfc9110.html#name-methods\n 'GET',\n 'HEAD',\n 'POST',\n 'PUT',\n 'DELETE',\n 'CONNECT',\n 'OPTIONS',\n 'TRACE',\n\n // PATCH from https://www.rfc-editor.org/rfc/rfc5789.html\n 'PATCH',\n\n // QUERY from https://datatracker.ietf.org/doc/draft-ietf-httpbis-safe-method-w-body/\n 'QUERY',\n]);\n\nfunction normalizeMethod(method?: string | null) {\n if (method == null) {\n return 'GET';\n }\n\n const upper = method.toUpperCase();\n if (KNOWN_METHODS.has(upper)) {\n return upper;\n }\n\n return '_OTHER';\n}\n\nfunction parseForwardedHeader(header: string): Record<string, string>[] {\n try {\n return forwardedParse(header);\n } catch {\n return [];\n }\n}\n"],"mappings":";;;;;;AAuDO,MAAA,iBAAA,QAAyB,iBAAA;AAEhC,MAAM,8BAA8B,MAAM,KAAKA,uBAAAA,+BAA+B;;;;;AAM9E,MA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CACA;CACA;CACA;CACA;CAGA;CAGA;AACF,CAAC;AAED,SAAS,gBAAgB,QAAwB;CAC/C,IAAI,UAAU,MACZ,OAAO;CAGT,MAAM,QAAQ,OAAO,YAAY;CACjC,IAAI,cAAc,IAAI,KAAK,GACzB,OAAO;CAGT,OAAO;AACT;AAEA,SAAS,qBAAqB,QAA0C;CACtE,IAAI;EACF,OAAO,eAAe,MAAM;CAC9B,QAAQ;EACN,OAAO,CAAC;CACV;AACF"}
|
|
1
|
+
{"version":3,"file":"utils.cjs","names":["DEFAULT_QUERY_STRINGS_TO_REDACT","STR_REDACTED","SpanKind","SpanStatusCode","ATTR_ERROR_TYPE","ATTR_HTTP_REQUEST_METHOD","ATTR_SERVER_ADDRESS","ATTR_SERVER_PORT","ATTR_URL_FULL","ATTR_USER_AGENT_ORIGINAL","ATTR_HTTP_REQUEST_METHOD_ORIGINAL","ATTR_USER_AGENT_SYNTHETIC_TYPE","SYNTHETIC_TEST_NAMES","USER_AGENT_SYNTHETIC_TYPE_VALUE_TEST","SYNTHETIC_BOT_NAMES","ATTR_HTTP_RESPONSE_STATUS_CODE","ATTR_NETWORK_PEER_ADDRESS","ATTR_NETWORK_PEER_PORT","ATTR_NETWORK_PROTOCOL_VERSION","ATTR_URL_SCHEME","ATTR_URL_PATH","ATTR_URL_QUERY","ATTR_CLIENT_ADDRESS","getRPCMetadata","context","RPCType","ATTR_HTTP_ROUTE","forwardedParse"],"sources":["../src/utils.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\nimport type {\n Attributes,\n Span,\n DiagLogger,\n AttributeValue,\n} from '@opentelemetry/api';\nimport { SpanStatusCode, context, SpanKind } from '@opentelemetry/api';\nimport {\n ATTR_CLIENT_ADDRESS,\n ATTR_ERROR_TYPE,\n ATTR_HTTP_REQUEST_METHOD,\n ATTR_HTTP_REQUEST_METHOD_ORIGINAL,\n ATTR_HTTP_RESPONSE_STATUS_CODE,\n ATTR_HTTP_ROUTE,\n ATTR_NETWORK_PEER_ADDRESS,\n ATTR_NETWORK_PEER_PORT,\n ATTR_NETWORK_PROTOCOL_VERSION,\n ATTR_SERVER_ADDRESS,\n ATTR_SERVER_PORT,\n ATTR_URL_FULL,\n ATTR_URL_PATH,\n ATTR_URL_QUERY,\n ATTR_URL_SCHEME,\n ATTR_USER_AGENT_ORIGINAL,\n} from '@opentelemetry/semantic-conventions';\nimport {\n ATTR_USER_AGENT_SYNTHETIC_TYPE,\n USER_AGENT_SYNTHETIC_TYPE_VALUE_BOT,\n USER_AGENT_SYNTHETIC_TYPE_VALUE_TEST,\n} from './semconv';\nimport type {\n IncomingHttpHeaders,\n IncomingMessage,\n OutgoingHttpHeader,\n OutgoingHttpHeaders,\n RequestOptions,\n ServerResponse,\n} from 'http';\nimport { getRPCMetadata, RPCType } from '@opentelemetry/core';\nimport type * as url from 'url';\nimport type {\n Err,\n IgnoreMatcher,\n ParsedRequestOptions,\n} from './internal-types';\nimport { SYNTHETIC_BOT_NAMES, SYNTHETIC_TEST_NAMES } from './internal-types';\nimport {\n DEFAULT_QUERY_STRINGS_TO_REDACT,\n STR_REDACTED,\n} from './internal-types';\nimport { parse as forwardedParse } from 'forwarded-parse';\n\nconst defaultQueryStringsToRedact = Array.from(DEFAULT_QUERY_STRINGS_TO_REDACT);\n\n/**\n * Redacts sensitive query parameters from a query string (without leading '?').\n * Returns the input unchanged if it cannot be parsed.\n */\nexport const redactQueryString = (\n searchParams: URLSearchParams,\n paramsToRedact: string[]\n): string => {\n const params = new URLSearchParams(searchParams);\n for (const param of paramsToRedact) {\n if (params.has(param)) {\n params.set(param, STR_REDACTED);\n }\n }\n return params.toString();\n};\n\n/**\n * Get an absolute url\n */\nexport const getAbsoluteUrl = (\n requestUrl: ParsedRequestOptions | null,\n headers: IncomingHttpHeaders | OutgoingHttpHeaders,\n fallbackProtocol = 'http:',\n redactedQueryParams: string[] = Array.from(DEFAULT_QUERY_STRINGS_TO_REDACT)\n): string => {\n const reqUrlObject = requestUrl || {};\n const protocol = reqUrlObject.protocol || fallbackProtocol;\n const port = (reqUrlObject.port || '').toString();\n let path = reqUrlObject.path || '/';\n // `host`, `hostname` and the `host` header may hold values of unexpected\n // types at runtime. Node.js itself ignores non-string values when it can\n // derive the target from another option (e.g. it uses `hostname` when\n // `host` is not a valid string), so skip non-string candidates instead of\n // crashing on them.\n let host: string =\n (typeof reqUrlObject.host === 'string' && reqUrlObject.host) ||\n (typeof reqUrlObject.hostname === 'string' && reqUrlObject.hostname) ||\n (typeof headers.host === 'string' && headers.host) ||\n 'localhost';\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 (host.indexOf(':') === -1 && port && port !== '80' && port !== '443') {\n host += `:${port}`;\n }\n // Redact sensitive query parameters\n if (typeof path === 'string' && path.includes('?')) {\n try {\n const parsedUrl = new URL(path, 'http://localhost');\n const redacted = redactQueryString(\n parsedUrl.searchParams,\n redactedQueryParams\n );\n path = `${parsedUrl.pathname}?${redacted}`;\n } catch {\n // Ignore error, as the path was not a valid URL.\n }\n }\n const authPart = reqUrlObject.auth ? `${STR_REDACTED}:${STR_REDACTED}@` : '';\n return `${protocol}//${authPart}${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 * Returns the `error.type` value for a response status code, or undefined when\n * the code is not an error for this span kind. Semconv asks for the status code\n * as a string once a response was received.\n */\nexport const parseErrorType = (\n kind: SpanKind,\n statusCode?: unknown\n): string | undefined => {\n const lowerBound = kind === SpanKind.CLIENT ? 400 : 500;\n if (\n typeof statusCode === 'number' &&\n statusCode >= lowerBound &&\n statusCode < 600\n ) {\n return String(statusCode);\n }\n\n return undefined;\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 * 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 span.setAttribute(ATTR_ERROR_TYPE, error.name);\n span.setStatus({ code: SpanStatusCode.ERROR, message });\n span.recordException(error);\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 * Mimics Node.js conversion of URL strings to RequestOptions expected by\n * `http.request` and `https.request` APIs.\n *\n * See https://github.com/nodejs/node/blob/2505e217bba05fc581b572c685c5cf280a16c5a3/lib/internal/url.js#L1415-L1437\n *\n * @param stringUrl\n * @throws TypeError if the URL is not valid.\n */\nfunction stringUrlToHttpOptions(\n stringUrl: string\n): RequestOptions & { pathname: string } {\n // This is heavily inspired by Node.js handling of the same situation, trying\n // to follow it as closely as possible while keeping in mind that we only\n // deal with string URLs, not URL objects.\n const {\n hostname,\n pathname,\n port,\n username,\n password,\n search,\n protocol,\n hash,\n href,\n origin,\n host,\n } = new URL(stringUrl);\n\n const options: RequestOptions & {\n pathname: string;\n hash: string;\n search: string;\n href: string;\n origin: string;\n } = {\n protocol: protocol,\n hostname:\n hostname && hostname[0] === '[' ? hostname.slice(1, -1) : hostname,\n hash: hash,\n search: search,\n pathname: pathname,\n path: `${pathname || ''}${search || ''}`,\n href: href,\n origin: origin,\n host: host,\n };\n if (port !== '') {\n options.port = Number(port);\n }\n if (username || password) {\n options.auth = `${decodeURIComponent(username)}:${decodeURIComponent(\n password\n )}`;\n }\n return options;\n}\n\n/**\n * Mirrors how Node.js detects WHATWG `URL` objects passed to `http.request`\n * and `https.request`: by shape rather than by `instanceof`, so that URL\n * objects from other realms (e.g. `vm` contexts) or WHATWG URL polyfills are\n * handled the same way Node.js handles them.\n *\n * This mirrors Node's `isURL()` predicate exactly. The `auth`/`path` guards\n * matter: they keep options objects and legacy `url.parse()` results (both\n * carry `path`) off the URL code path.\n *\n * See https://github.com/nodejs/node/blob/2505e217bba05fc581b572c685c5cf280a16c5a3/lib/internal/url.js#L756-L773\n */\nexport const isURLLike = (value: unknown): value is url.URL => {\n const candidate = value as\n | (url.URL & { auth?: unknown; path?: unknown })\n | undefined;\n return Boolean(\n candidate?.href &&\n candidate.protocol &&\n candidate.auth === undefined &&\n candidate.path === undefined\n );\n};\n\n/**\n * Makes sure options is an url object\n * return an object with default value and parsed options\n * @param logger component logger\n * @param options original options for the request\n * @param [extraOptions] additional options for the request\n */\nexport const getRequestInfo = (\n logger: DiagLogger,\n options: url.URL | RequestOptions | string,\n extraOptions?: RequestOptions\n): {\n origin: string;\n pathname: string;\n method: string;\n invalidUrl: boolean;\n optionsParsed: RequestOptions;\n} => {\n let pathname: string;\n let origin: string;\n let optionsParsed: RequestOptions;\n let invalidUrl = false;\n if (typeof options === 'string') {\n try {\n const convertedOptions = stringUrlToHttpOptions(options);\n optionsParsed = convertedOptions;\n pathname = convertedOptions.pathname || '/';\n } catch (e) {\n invalidUrl = true;\n logger.verbose(\n 'Unable to parse URL provided to HTTP request, using fallback to determine path. Original error:',\n e\n );\n // for backward compatibility with how url.parse() behaved.\n optionsParsed = {\n path: options,\n };\n pathname = optionsParsed.path || '/';\n }\n\n origin = `${optionsParsed.protocol || 'http:'}//${optionsParsed.host}`;\n if (extraOptions !== undefined) {\n Object.assign(optionsParsed, extraOptions);\n }\n } else if (isURLLike(options)) {\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\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 pathname = (options as url.URL).pathname;\n if (!pathname && optionsParsed.path) {\n try {\n const parsedUrl = new URL(optionsParsed.path, origin);\n pathname = parsedUrl.pathname || '/';\n } catch {\n pathname = '/';\n }\n }\n }\n\n // some packages return method in lowercase..\n // ensure upperCase for consistency\n // Note: a non-string `method` is rejected by Node.js itself; skip it here\n // so the resulting error comes from Node.js and not the instrumentation.\n const method =\n optionsParsed.method && typeof optionsParsed.method === 'string'\n ? optionsParsed.method.toUpperCase()\n : 'GET';\n\n return { origin, pathname, method, optionsParsed, invalidUrl };\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 // `hostname`, `host` and `port` may hold values of unexpected types at\n // runtime. Node.js itself ignores non-string values when it can derive the\n // target from another option (e.g. it uses `hostname` when `host` is not a\n // valid string), so skip non-string candidates instead of crashing on them.\n const optionsHostname =\n typeof requestOptions.hostname === 'string'\n ? requestOptions.hostname\n : undefined;\n const optionsHost =\n typeof requestOptions.host === 'string' ? requestOptions.host : undefined;\n const optionsPort =\n typeof requestOptions.port === 'string' ||\n typeof requestOptions.port === 'number'\n ? requestOptions.port\n : undefined;\n\n if (optionsHostname && optionsPort) {\n return { hostname: optionsHostname, port: optionsPort };\n }\n const matches = optionsHost?.match(/^([^:/ ]+)(:\\d{1,5})?/) || null;\n const hostname =\n optionsHostname || (matches === null ? 'localhost' : matches[1]);\n let port = optionsPort;\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?: Attributes }} 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?: Attributes;\n redactedQueryParams?: string[];\n },\n enableSyntheticSourceDetection: boolean\n): Attributes => {\n const hostname = options.hostname;\n const port = options.port;\n const method = requestOptions.method ?? 'GET';\n const normalizedMethod = normalizeMethod(method);\n const headers = (requestOptions.headers || {}) as OutgoingHttpHeaders;\n const userAgent = headers['user-agent'];\n const urlFull = getAbsoluteUrl(\n requestOptions,\n headers,\n `${options.component}:`,\n options.redactedQueryParams\n );\n\n const attributes: Attributes = {\n // Required attributes\n [ATTR_HTTP_REQUEST_METHOD]: normalizedMethod,\n [ATTR_SERVER_ADDRESS]: hostname,\n [ATTR_SERVER_PORT]: Number(port),\n [ATTR_URL_FULL]: urlFull,\n [ATTR_USER_AGENT_ORIGINAL]: userAgent,\n // leaving out protocol version, it is not yet negotiated\n // leaving out protocol name, it is only required when protocol version is set\n // retries and redirects not supported\n\n // Opt-in attributes left off for now\n };\n\n // conditionally required if request method required case normalization\n if (method !== normalizedMethod) {\n attributes[ATTR_HTTP_REQUEST_METHOD_ORIGINAL] = method;\n }\n\n if (enableSyntheticSourceDetection && userAgent) {\n attributes[ATTR_USER_AGENT_SYNTHETIC_TYPE] = getSyntheticType(userAgent);\n }\n return Object.assign(attributes, options.hookAttributes);\n};\n\n/**\n * Returns the type of synthetic source based on the user agent\n * @param {OutgoingHttpHeader} userAgent the user agent string\n */\nconst getSyntheticType = (\n userAgent: OutgoingHttpHeader\n): AttributeValue | undefined => {\n const userAgentString: string = String(userAgent).toLowerCase();\n for (const name of SYNTHETIC_TEST_NAMES) {\n if (userAgentString.includes(name)) {\n return USER_AGENT_SYNTHETIC_TYPE_VALUE_TEST;\n }\n }\n for (const name of SYNTHETIC_BOT_NAMES) {\n if (userAgentString.includes(name)) {\n return USER_AGENT_SYNTHETIC_TYPE_VALUE_BOT;\n }\n }\n return;\n};\n\n/**\n * Returns outgoing request attributes scoped to the response data\n * @param {IncomingMessage} response the response object\n */\nexport const getOutgoingRequestAttributesOnResponse = (\n response: IncomingMessage\n): Attributes => {\n const { statusCode, socket } = response;\n const attributes: Attributes = {};\n\n if (statusCode != null) {\n attributes[ATTR_HTTP_RESPONSE_STATUS_CODE] = statusCode;\n }\n\n if (socket) {\n const { remoteAddress, remotePort } = socket;\n\n // Recommended\n attributes[ATTR_NETWORK_PEER_ADDRESS] = remoteAddress;\n attributes[ATTR_NETWORK_PEER_PORT] = remotePort;\n attributes[ATTR_NETWORK_PROTOCOL_VERSION] = response.httpVersion;\n }\n return attributes;\n};\n\n/**\n * Returns outgoing request Metric attributes scoped to the response data\n * @param {Attributes} spanAttributes the span attributes\n */\nexport const getOutgoingStableRequestMetricAttributesOnResponse = (\n spanAttributes: Attributes\n): Attributes => {\n const metricAttributes: Attributes = {};\n\n if (spanAttributes[ATTR_NETWORK_PROTOCOL_VERSION]) {\n metricAttributes[ATTR_NETWORK_PROTOCOL_VERSION] =\n spanAttributes[ATTR_NETWORK_PROTOCOL_VERSION];\n }\n\n const statusCode = spanAttributes[ATTR_HTTP_RESPONSE_STATUS_CODE];\n if (statusCode) {\n metricAttributes[ATTR_HTTP_RESPONSE_STATUS_CODE] = statusCode;\n const errorType = parseErrorType(SpanKind.CLIENT, statusCode);\n if (errorType !== undefined) {\n metricAttributes[ATTR_ERROR_TYPE] ??= errorType;\n }\n }\n return metricAttributes;\n};\n\nfunction parseHostHeader(\n hostHeader: string,\n proto?: string\n): { host: string; port?: string } {\n const parts = hostHeader.split(':');\n\n // no semicolon implies ipv4 dotted syntax or host name without port\n // x.x.x.x\n // example.com\n if (parts.length === 1) {\n if (proto === 'http') {\n return { host: parts[0], port: '80' };\n }\n\n if (proto === 'https') {\n return { host: parts[0], port: '443' };\n }\n\n return { host: parts[0] };\n }\n\n // single semicolon implies ipv4 dotted syntax or host name with port\n // x.x.x.x:yyyy\n // example.com:yyyy\n if (parts.length === 2) {\n return {\n host: parts[0],\n port: parts[1],\n };\n }\n\n // more than 2 parts implies ipv6 syntax with multiple colons\n // [x:x:x:x:x:x:x:x]\n // [x:x:x:x:x:x:x:x]:yyyy\n if (parts[0].startsWith('[')) {\n if (parts[parts.length - 1].endsWith(']')) {\n if (proto === 'http') {\n return { host: hostHeader, port: '80' };\n }\n\n if (proto === 'https') {\n return { host: hostHeader, port: '443' };\n }\n } else if (parts[parts.length - 2].endsWith(']')) {\n return {\n host: parts.slice(0, -1).join(':'),\n port: parts[parts.length - 1],\n };\n }\n }\n\n // if nothing above matches just return the host header\n return { host: hostHeader };\n}\n\n/**\n * Get server.address and port according to http semconv 1.27\n * https://github.com/open-telemetry/semantic-conventions/blob/bf0a2c1134f206f034408b201dbec37960ed60ec/docs/http/http-spans.md#setting-serveraddress-and-serverport-attributes\n */\nfunction getServerAddress(\n request: IncomingMessage,\n component: 'http' | 'https'\n): { host: string; port?: string } | null {\n const forwardedHeader = request.headers['forwarded'];\n if (forwardedHeader) {\n for (const entry of parseForwardedHeader(forwardedHeader)) {\n if (entry.host) {\n return parseHostHeader(entry.host, entry.proto);\n }\n }\n }\n\n const xForwardedHost = request.headers['x-forwarded-host'];\n if (typeof xForwardedHost === 'string') {\n if (typeof request.headers['x-forwarded-proto'] === 'string') {\n return parseHostHeader(\n xForwardedHost,\n request.headers['x-forwarded-proto']\n );\n }\n\n if (Array.isArray(request.headers['x-forwarded-proto'])) {\n return parseHostHeader(\n xForwardedHost,\n request.headers['x-forwarded-proto'][0]\n );\n }\n\n return parseHostHeader(xForwardedHost);\n } else if (\n Array.isArray(xForwardedHost) &&\n typeof xForwardedHost[0] === 'string' &&\n xForwardedHost[0].length > 0\n ) {\n if (typeof request.headers['x-forwarded-proto'] === 'string') {\n return parseHostHeader(\n xForwardedHost[0],\n request.headers['x-forwarded-proto']\n );\n }\n\n if (Array.isArray(request.headers['x-forwarded-proto'])) {\n return parseHostHeader(\n xForwardedHost[0],\n request.headers['x-forwarded-proto'][0]\n );\n }\n\n return parseHostHeader(xForwardedHost[0]);\n }\n\n const host = request.headers['host'];\n if (typeof host === 'string' && host.length > 0) {\n return parseHostHeader(host, component);\n }\n\n return null;\n}\n\n/**\n * Get server.address and port according to http semconv 1.27\n * https://github.com/open-telemetry/semantic-conventions/blob/bf0a2c1134f206f034408b201dbec37960ed60ec/docs/http/http-spans.md#setting-serveraddress-and-serverport-attributes\n */\nexport function getRemoteClientAddress(\n request: IncomingMessage\n): string | null {\n const forwardedHeader = request.headers['forwarded'];\n if (forwardedHeader) {\n for (const entry of parseForwardedHeader(forwardedHeader)) {\n if (entry.for) {\n return removePortFromAddress(entry.for);\n }\n }\n }\n\n const xForwardedFor = request.headers['x-forwarded-for'];\n if (xForwardedFor) {\n let xForwardedForVal;\n if (typeof xForwardedFor === 'string') {\n xForwardedForVal = xForwardedFor;\n } else if (Array.isArray(xForwardedFor)) {\n xForwardedForVal = xForwardedFor[0];\n }\n\n if (typeof xForwardedForVal === 'string') {\n xForwardedForVal = xForwardedForVal.split(',')[0].trim();\n return removePortFromAddress(xForwardedForVal);\n }\n }\n\n const remote = request.socket.remoteAddress;\n if (remote) {\n return remote;\n }\n\n return null;\n}\n\nfunction removePortFromAddress(input: string): string {\n // This function can be replaced with SocketAddress.parse() once the minimum\n // supported Node.js version allows it.\n try {\n const { hostname: address } = new URL(`http://${input}`);\n\n if (address.startsWith('[') && address.endsWith(']')) {\n return address.slice(1, -1);\n }\n\n return address;\n } catch {\n return input;\n }\n}\n\nfunction getInfoFromIncomingMessage(\n component: 'http' | 'https',\n request: IncomingMessage,\n logger: DiagLogger\n): { pathname?: string; search?: string; toString: () => string } {\n try {\n if (request.headers.host) {\n return new URL(\n request.url ?? '/',\n `${component}://${request.headers.host}`\n );\n } else {\n const unsafeParsedUrl = new URL(\n request.url ?? '/',\n // using localhost as a workaround to still use the URL constructor for parsing\n `${component}://localhost`\n );\n // since we use localhost as a workaround, ensure we hide the rest of the properties to avoid\n // our workaround leaking though.\n return {\n pathname: unsafeParsedUrl.pathname,\n search: unsafeParsedUrl.search,\n toString: function () {\n // we cannot use the result of unsafeParsedUrl.toString as it's potentially wrong.\n return unsafeParsedUrl.pathname + unsafeParsedUrl.search;\n },\n };\n }\n } catch (e) {\n // something is wrong, use undefined - this *should* never happen, logging\n // for troubleshooting in case it does happen.\n logger.verbose('Unable to get URL from request', e);\n return {};\n }\n}\n\n/**\n * Returns incoming request attributes scoped to the request data\n * @param {IncomingMessage} request the request object\n * @param {{ component: string, hookAttributes?: Attributes, enableSyntheticSourceDetection: boolean }} options used to pass data needed to create attributes\n */\nexport const getIncomingRequestAttributes = (\n request: IncomingMessage,\n options: {\n component: 'http' | 'https';\n hookAttributes?: Attributes;\n enableSyntheticSourceDetection: boolean;\n redactedQueryParams?: string[];\n },\n logger: DiagLogger\n): Attributes => {\n const {\n component,\n enableSyntheticSourceDetection,\n hookAttributes,\n redactedQueryParams,\n } = options;\n const { headers, method } = request;\n const { 'user-agent': userAgent } = headers;\n const parsedUrl = getInfoFromIncomingMessage(component, request, logger);\n\n // Stable attributes are used.\n const normalizedMethod = normalizeMethod(method);\n const serverAddress = getServerAddress(request, component);\n const remoteClientAddress = getRemoteClientAddress(request);\n\n const attributes: Attributes = {\n [ATTR_HTTP_REQUEST_METHOD]: normalizedMethod,\n [ATTR_URL_SCHEME]: component,\n [ATTR_SERVER_ADDRESS]: serverAddress?.host,\n [ATTR_NETWORK_PEER_ADDRESS]: request.socket.remoteAddress,\n [ATTR_NETWORK_PEER_PORT]: request.socket.remotePort,\n [ATTR_NETWORK_PROTOCOL_VERSION]: request.httpVersion,\n [ATTR_USER_AGENT_ORIGINAL]: userAgent,\n };\n\n if (parsedUrl.pathname != null) {\n attributes[ATTR_URL_PATH] = parsedUrl.pathname;\n }\n\n if (parsedUrl.search) {\n // Remove leading '?' from URL search (https://developer.mozilla.org/en-US/docs/Web/API/URL/search).\n const paramsToRedact = redactedQueryParams ?? defaultQueryStringsToRedact;\n attributes[ATTR_URL_QUERY] = redactQueryString(\n new URLSearchParams(parsedUrl.search.slice(1)),\n paramsToRedact\n );\n }\n\n if (remoteClientAddress != null) {\n attributes[ATTR_CLIENT_ADDRESS] = remoteClientAddress;\n }\n\n if (serverAddress?.port != null) {\n attributes[ATTR_SERVER_PORT] = Number(serverAddress.port);\n }\n\n // Conditionally required if request method required case normalization.\n if (method !== normalizedMethod) {\n attributes[ATTR_HTTP_REQUEST_METHOD_ORIGINAL] = method;\n }\n\n if (enableSyntheticSourceDetection && userAgent) {\n attributes[ATTR_USER_AGENT_SYNTHETIC_TYPE] = getSyntheticType(userAgent);\n }\n\n return Object.assign(attributes, hookAttributes);\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 response: ServerResponse\n): Attributes => {\n const { statusCode } = response;\n\n const attributes: Attributes = {\n [ATTR_HTTP_RESPONSE_STATUS_CODE]: statusCode,\n };\n\n const rpcMetadata = getRPCMetadata(context.active());\n if (rpcMetadata?.type === RPCType.HTTP && rpcMetadata.route !== undefined) {\n attributes[ATTR_HTTP_ROUTE] = rpcMetadata.route;\n }\n\n return attributes;\n};\n\n/**\n * Returns incoming stable request Metric attributes scoped to the request data\n * @param {Attributes} spanAttributes the span attributes\n */\nexport const getIncomingStableRequestMetricAttributesOnResponse = (\n spanAttributes: Attributes\n): Attributes => {\n const metricAttributes: Attributes = {};\n if (spanAttributes[ATTR_HTTP_ROUTE] !== undefined) {\n metricAttributes[ATTR_HTTP_ROUTE] = spanAttributes[ATTR_HTTP_ROUTE];\n }\n\n // required if and only if one was sent, same as span requirement\n const statusCode = spanAttributes[ATTR_HTTP_RESPONSE_STATUS_CODE];\n if (statusCode) {\n metricAttributes[ATTR_HTTP_RESPONSE_STATUS_CODE] = statusCode;\n const errorType = parseErrorType(SpanKind.SERVER, statusCode);\n if (errorType !== undefined) {\n metricAttributes[ATTR_ERROR_TYPE] ??= errorType;\n }\n }\n\n return metricAttributes;\n};\n\nexport function headerCapture(type: 'request' | 'response', headers: string[]) {\n const normalizedHeaders = new Map<string, string>();\n for (let i = 0, len = headers.length; i < len; i++) {\n const capturedHeader = headers[i].toLowerCase();\n normalizedHeaders.set(capturedHeader, capturedHeader);\n }\n\n return (\n getHeader: (key: string) => undefined | string | string[] | number\n ): Attributes => {\n const attributes: Attributes = {};\n for (const capturedHeader of normalizedHeaders.keys()) {\n const value = getHeader(capturedHeader);\n\n if (value === undefined) {\n continue;\n }\n\n const normalizedHeader = normalizedHeaders.get(capturedHeader);\n const key = `http.${type}.header.${normalizedHeader}`;\n\n if (typeof value === 'string') {\n attributes[key] = [value];\n } else if (Array.isArray(value)) {\n attributes[key] = value;\n } else {\n attributes[key] = [value];\n }\n }\n return attributes;\n };\n}\n\nconst KNOWN_METHODS = new Set([\n // methods from https://www.rfc-editor.org/rfc/rfc9110.html#name-methods\n 'GET',\n 'HEAD',\n 'POST',\n 'PUT',\n 'DELETE',\n 'CONNECT',\n 'OPTIONS',\n 'TRACE',\n\n // PATCH from https://www.rfc-editor.org/rfc/rfc5789.html\n 'PATCH',\n\n // QUERY from https://datatracker.ietf.org/doc/draft-ietf-httpbis-safe-method-w-body/\n 'QUERY',\n]);\n\nfunction normalizeMethod(method?: string | null) {\n if (method == null) {\n return 'GET';\n }\n\n const upper = method.toUpperCase();\n if (KNOWN_METHODS.has(upper)) {\n return upper;\n }\n\n return '_OTHER';\n}\n\nfunction parseForwardedHeader(header: string): Record<string, string>[] {\n try {\n return forwardedParse(header);\n } catch {\n return [];\n }\n}\n"],"mappings":";;;;;;;AAwDA,MAAM,8BAA8B,MAAM,KAAKA,uBAAAA,+BAA+B;;;;;AAM9E,MAAa,qBACX,cACA,mBACW;CACX,MAAM,SAAS,IAAI,gBAAgB,YAAY;CAC/C,KAAK,MAAM,SAAS,gBAClB,IAAI,OAAO,IAAI,KAAK,GAClB,OAAO,IAAI,OAAOC,uBAAAA,YAAY;CAGlC,OAAO,OAAO,SAAS;AACzB;;;;AAKA,MAAa,kBACX,YACA,SACA,mBAAmB,SACnB,sBAAgC,MAAM,KAAKD,uBAAAA,+BAA+B,MAC/D;CACX,MAAM,eAAe,cAAc,CAAC;CACpC,MAAM,WAAW,aAAa,YAAY;CAC1C,MAAM,QAAQ,aAAa,QAAQ,GAAA,CAAI,SAAS;CAChD,IAAI,OAAO,aAAa,QAAQ;CAMhC,IAAI,OACD,OAAO,aAAa,SAAS,YAAY,aAAa,QACtD,OAAO,aAAa,aAAa,YAAY,aAAa,YAC1D,OAAO,QAAQ,SAAS,YAAY,QAAQ,QAC7C;CAGF,IAAI,KAAK,QAAQ,GAAG,MAAM,MAAM,QAAQ,SAAS,QAAQ,SAAS,OAChE,QAAQ,IAAI;CAGd,IAAI,OAAO,SAAS,YAAY,KAAK,SAAS,GAAG,GAC/C,IAAI;EACF,MAAM,YAAY,IAAI,IAAI,MAAM,kBAAkB;EAClD,MAAM,WAAW,kBACf,UAAU,cACV,mBACF;EACA,O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gBAAgB,cAAc;CACtD;CAEA,QACE,cACe;EACf,MAAM,aAAyB,CAAC;EAChC,KAAK,MAAM,kBAAkB,kBAAkB,KAAK,GAAG;GACrD,MAAM,QAAQ,UAAU,cAAc;GAEtC,IAAI,UAAU,KAAA,GACZ;GAIF,MAAM,MAAM,QAAQ,KAAK,UADA,kBAAkB,IAAI,cACG;GAElD,IAAI,OAAO,UAAU,UACnB,WAAW,OAAO,CAAC,KAAK;QACnB,IAAI,MAAM,QAAQ,KAAK,GAC5B,WAAW,OAAO;QAElB,WAAW,OAAO,CAAC,KAAK;EAE5B;EACA,OAAO;CACT;AACF;AAEA,MAAM,gCAAgB,IAAI,IAAI;CAE5B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAGA;CAGA;AACF,CAAC;AAED,SAAS,gBAAgB,QAAwB;CAC/C,IAAI,UAAU,MACZ,OAAO;CAGT,MAAM,QAAQ,OAAO,YAAY;CACjC,IAAI,cAAc,IAAI,KAAK,GACzB,OAAO;CAGT,OAAO;AACT;AAEA,SAAS,qBAAqB,QAA0C;CACtE,IAAI;EACF,QAAA,GAAOuB,gBAAAA,MAAAA,CAAe,MAAM;CAC9B,QAAQ;EACN,OAAO,CAAC;CACV;AACF"}
|
package/dist/utils.mjs
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { __require } from "./_virtual/_rolldown/runtime.mjs";
|
|
2
1
|
import { ATTR_USER_AGENT_SYNTHETIC_TYPE, USER_AGENT_SYNTHETIC_TYPE_VALUE_TEST } from "./semconv.mjs";
|
|
3
2
|
import { DEFAULT_QUERY_STRINGS_TO_REDACT, STR_REDACTED, SYNTHETIC_BOT_NAMES, SYNTHETIC_TEST_NAMES } from "./internal-types.mjs";
|
|
4
3
|
import { SpanKind, SpanStatusCode, context } from "@opentelemetry/api";
|
|
5
4
|
import { RPCType, getRPCMetadata } from "@opentelemetry/core";
|
|
6
5
|
import { ATTR_CLIENT_ADDRESS, ATTR_ERROR_TYPE, ATTR_HTTP_REQUEST_METHOD, ATTR_HTTP_REQUEST_METHOD_ORIGINAL, ATTR_HTTP_RESPONSE_STATUS_CODE, ATTR_HTTP_ROUTE, ATTR_NETWORK_PEER_ADDRESS, ATTR_NETWORK_PEER_PORT, ATTR_NETWORK_PROTOCOL_VERSION, ATTR_SERVER_ADDRESS, ATTR_SERVER_PORT, ATTR_URL_FULL, ATTR_URL_PATH, ATTR_URL_QUERY, ATTR_URL_SCHEME, ATTR_USER_AGENT_ORIGINAL } from "@opentelemetry/semantic-conventions";
|
|
6
|
+
import { parse } from "forwarded-parse";
|
|
7
7
|
//#region src/utils.ts
|
|
8
|
-
const forwardedParse = __require("forwarded-parse");
|
|
9
8
|
const defaultQueryStringsToRedact = Array.from(DEFAULT_QUERY_STRINGS_TO_REDACT);
|
|
10
9
|
/**
|
|
11
10
|
* Redacts sensitive query parameters from a query string (without leading '?').
|
|
@@ -460,7 +459,7 @@ function normalizeMethod(method) {
|
|
|
460
459
|
}
|
|
461
460
|
function parseForwardedHeader(header) {
|
|
462
461
|
try {
|
|
463
|
-
return
|
|
462
|
+
return parse(header);
|
|
464
463
|
} catch {
|
|
465
464
|
return [];
|
|
466
465
|
}
|
package/dist/utils.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.mjs","names":[],"sources":["../src/utils.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\nimport type {\n Attributes,\n Span,\n DiagLogger,\n AttributeValue,\n} from '@opentelemetry/api';\nimport { SpanStatusCode, context, SpanKind } from '@opentelemetry/api';\nimport {\n ATTR_CLIENT_ADDRESS,\n ATTR_ERROR_TYPE,\n ATTR_HTTP_REQUEST_METHOD,\n ATTR_HTTP_REQUEST_METHOD_ORIGINAL,\n ATTR_HTTP_RESPONSE_STATUS_CODE,\n ATTR_HTTP_ROUTE,\n ATTR_NETWORK_PEER_ADDRESS,\n ATTR_NETWORK_PEER_PORT,\n ATTR_NETWORK_PROTOCOL_VERSION,\n ATTR_SERVER_ADDRESS,\n ATTR_SERVER_PORT,\n ATTR_URL_FULL,\n ATTR_URL_PATH,\n ATTR_URL_QUERY,\n ATTR_URL_SCHEME,\n ATTR_USER_AGENT_ORIGINAL,\n} from '@opentelemetry/semantic-conventions';\nimport {\n ATTR_USER_AGENT_SYNTHETIC_TYPE,\n USER_AGENT_SYNTHETIC_TYPE_VALUE_BOT,\n USER_AGENT_SYNTHETIC_TYPE_VALUE_TEST,\n} from './semconv';\nimport type {\n IncomingHttpHeaders,\n IncomingMessage,\n OutgoingHttpHeader,\n OutgoingHttpHeaders,\n RequestOptions,\n ServerResponse,\n} from 'http';\nimport { getRPCMetadata, RPCType } from '@opentelemetry/core';\nimport type * as url from 'url';\nimport type {\n Err,\n IgnoreMatcher,\n ParsedRequestOptions,\n} from './internal-types';\nimport { SYNTHETIC_BOT_NAMES, SYNTHETIC_TEST_NAMES } from './internal-types';\nimport {\n DEFAULT_QUERY_STRINGS_TO_REDACT,\n STR_REDACTED,\n} from './internal-types';\n// eslint-disable-next-line @typescript-eslint/no-require-imports\nimport forwardedParse = require('forwarded-parse');\n\nconst defaultQueryStringsToRedact = Array.from(DEFAULT_QUERY_STRINGS_TO_REDACT);\n\n/**\n * Redacts sensitive query parameters from a query string (without leading '?').\n * Returns the input unchanged if it cannot be parsed.\n */\nexport const redactQueryString = (\n searchParams: URLSearchParams,\n paramsToRedact: string[]\n): string => {\n const params = new URLSearchParams(searchParams);\n for (const param of paramsToRedact) {\n if (params.has(param)) {\n params.set(param, STR_REDACTED);\n }\n }\n return params.toString();\n};\n\n/**\n * Get an absolute url\n */\nexport const getAbsoluteUrl = (\n requestUrl: ParsedRequestOptions | null,\n headers: IncomingHttpHeaders | OutgoingHttpHeaders,\n fallbackProtocol = 'http:',\n redactedQueryParams: string[] = Array.from(DEFAULT_QUERY_STRINGS_TO_REDACT)\n): string => {\n const reqUrlObject = requestUrl || {};\n const protocol = reqUrlObject.protocol || fallbackProtocol;\n const port = (reqUrlObject.port || '').toString();\n let path = reqUrlObject.path || '/';\n // `host`, `hostname` and the `host` header may hold values of unexpected\n // types at runtime. Node.js itself ignores non-string values when it can\n // derive the target from another option (e.g. it uses `hostname` when\n // `host` is not a valid string), so skip non-string candidates instead of\n // crashing on them.\n let host: string =\n (typeof reqUrlObject.host === 'string' && reqUrlObject.host) ||\n (typeof reqUrlObject.hostname === 'string' && reqUrlObject.hostname) ||\n (typeof headers.host === 'string' && headers.host) ||\n 'localhost';\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 (host.indexOf(':') === -1 && port && port !== '80' && port !== '443') {\n host += `:${port}`;\n }\n // Redact sensitive query parameters\n if (typeof path === 'string' && path.includes('?')) {\n try {\n const parsedUrl = new URL(path, 'http://localhost');\n const redacted = redactQueryString(\n parsedUrl.searchParams,\n redactedQueryParams\n );\n path = `${parsedUrl.pathname}?${redacted}`;\n } catch {\n // Ignore error, as the path was not a valid URL.\n }\n }\n const authPart = reqUrlObject.auth ? `${STR_REDACTED}:${STR_REDACTED}@` : '';\n return `${protocol}//${authPart}${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 * Returns the `error.type` value for a response status code, or undefined when\n * the code is not an error for this span kind. Semconv asks for the status code\n * as a string once a response was received.\n */\nexport const parseErrorType = (\n kind: SpanKind,\n statusCode?: unknown\n): string | undefined => {\n const lowerBound = kind === SpanKind.CLIENT ? 400 : 500;\n if (\n typeof statusCode === 'number' &&\n statusCode >= lowerBound &&\n statusCode < 600\n ) {\n return String(statusCode);\n }\n\n return undefined;\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 * 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 span.setAttribute(ATTR_ERROR_TYPE, error.name);\n span.setStatus({ code: SpanStatusCode.ERROR, message });\n span.recordException(error);\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 * Mimics Node.js conversion of URL strings to RequestOptions expected by\n * `http.request` and `https.request` APIs.\n *\n * See https://github.com/nodejs/node/blob/2505e217bba05fc581b572c685c5cf280a16c5a3/lib/internal/url.js#L1415-L1437\n *\n * @param stringUrl\n * @throws TypeError if the URL is not valid.\n */\nfunction stringUrlToHttpOptions(\n stringUrl: string\n): RequestOptions & { pathname: string } {\n // This is heavily inspired by Node.js handling of the same situation, trying\n // to follow it as closely as possible while keeping in mind that we only\n // deal with string URLs, not URL objects.\n const {\n hostname,\n pathname,\n port,\n username,\n password,\n search,\n protocol,\n hash,\n href,\n origin,\n host,\n } = new URL(stringUrl);\n\n const options: RequestOptions & {\n pathname: string;\n hash: string;\n search: string;\n href: string;\n origin: string;\n } = {\n protocol: protocol,\n hostname:\n hostname && hostname[0] === '[' ? hostname.slice(1, -1) : hostname,\n hash: hash,\n search: search,\n pathname: pathname,\n path: `${pathname || ''}${search || ''}`,\n href: href,\n origin: origin,\n host: host,\n };\n if (port !== '') {\n options.port = Number(port);\n }\n if (username || password) {\n options.auth = `${decodeURIComponent(username)}:${decodeURIComponent(\n password\n )}`;\n }\n return options;\n}\n\n/**\n * Mirrors how Node.js detects WHATWG `URL` objects passed to `http.request`\n * and `https.request`: by shape rather than by `instanceof`, so that URL\n * objects from other realms (e.g. `vm` contexts) or WHATWG URL polyfills are\n * handled the same way Node.js handles them.\n *\n * This mirrors Node's `isURL()` predicate exactly. The `auth`/`path` guards\n * matter: they keep options objects and legacy `url.parse()` results (both\n * carry `path`) off the URL code path.\n *\n * See https://github.com/nodejs/node/blob/2505e217bba05fc581b572c685c5cf280a16c5a3/lib/internal/url.js#L756-L773\n */\nexport const isURLLike = (value: unknown): value is url.URL => {\n const candidate = value as\n | (url.URL & { auth?: unknown; path?: unknown })\n | undefined;\n return Boolean(\n candidate?.href &&\n candidate.protocol &&\n candidate.auth === undefined &&\n candidate.path === undefined\n );\n};\n\n/**\n * Makes sure options is an url object\n * return an object with default value and parsed options\n * @param logger component logger\n * @param options original options for the request\n * @param [extraOptions] additional options for the request\n */\nexport const getRequestInfo = (\n logger: DiagLogger,\n options: url.URL | RequestOptions | string,\n extraOptions?: RequestOptions\n): {\n origin: string;\n pathname: string;\n method: string;\n invalidUrl: boolean;\n optionsParsed: RequestOptions;\n} => {\n let pathname: string;\n let origin: string;\n let optionsParsed: RequestOptions;\n let invalidUrl = false;\n if (typeof options === 'string') {\n try {\n const convertedOptions = stringUrlToHttpOptions(options);\n optionsParsed = convertedOptions;\n pathname = convertedOptions.pathname || '/';\n } catch (e) {\n invalidUrl = true;\n logger.verbose(\n 'Unable to parse URL provided to HTTP request, using fallback to determine path. Original error:',\n e\n );\n // for backward compatibility with how url.parse() behaved.\n optionsParsed = {\n path: options,\n };\n pathname = optionsParsed.path || '/';\n }\n\n origin = `${optionsParsed.protocol || 'http:'}//${optionsParsed.host}`;\n if (extraOptions !== undefined) {\n Object.assign(optionsParsed, extraOptions);\n }\n } else if (isURLLike(options)) {\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\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 pathname = (options as url.URL).pathname;\n if (!pathname && optionsParsed.path) {\n try {\n const parsedUrl = new URL(optionsParsed.path, origin);\n pathname = parsedUrl.pathname || '/';\n } catch {\n pathname = '/';\n }\n }\n }\n\n // some packages return method in lowercase..\n // ensure upperCase for consistency\n // Note: a non-string `method` is rejected by Node.js itself; skip it here\n // so the resulting error comes from Node.js and not the instrumentation.\n const method =\n optionsParsed.method && typeof optionsParsed.method === 'string'\n ? optionsParsed.method.toUpperCase()\n : 'GET';\n\n return { origin, pathname, method, optionsParsed, invalidUrl };\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 // `hostname`, `host` and `port` may hold values of unexpected types at\n // runtime. Node.js itself ignores non-string values when it can derive the\n // target from another option (e.g. it uses `hostname` when `host` is not a\n // valid string), so skip non-string candidates instead of crashing on them.\n const optionsHostname =\n typeof requestOptions.hostname === 'string'\n ? requestOptions.hostname\n : undefined;\n const optionsHost =\n typeof requestOptions.host === 'string' ? requestOptions.host : undefined;\n const optionsPort =\n typeof requestOptions.port === 'string' ||\n typeof requestOptions.port === 'number'\n ? requestOptions.port\n : undefined;\n\n if (optionsHostname && optionsPort) {\n return { hostname: optionsHostname, port: optionsPort };\n }\n const matches = optionsHost?.match(/^([^:/ ]+)(:\\d{1,5})?/) || null;\n const hostname =\n optionsHostname || (matches === null ? 'localhost' : matches[1]);\n let port = optionsPort;\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?: Attributes }} 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?: Attributes;\n redactedQueryParams?: string[];\n },\n enableSyntheticSourceDetection: boolean\n): Attributes => {\n const hostname = options.hostname;\n const port = options.port;\n const method = requestOptions.method ?? 'GET';\n const normalizedMethod = normalizeMethod(method);\n const headers = (requestOptions.headers || {}) as OutgoingHttpHeaders;\n const userAgent = headers['user-agent'];\n const urlFull = getAbsoluteUrl(\n requestOptions,\n headers,\n `${options.component}:`,\n options.redactedQueryParams\n );\n\n const attributes: Attributes = {\n // Required attributes\n [ATTR_HTTP_REQUEST_METHOD]: normalizedMethod,\n [ATTR_SERVER_ADDRESS]: hostname,\n [ATTR_SERVER_PORT]: Number(port),\n [ATTR_URL_FULL]: urlFull,\n [ATTR_USER_AGENT_ORIGINAL]: userAgent,\n // leaving out protocol version, it is not yet negotiated\n // leaving out protocol name, it is only required when protocol version is set\n // retries and redirects not supported\n\n // Opt-in attributes left off for now\n };\n\n // conditionally required if request method required case normalization\n if (method !== normalizedMethod) {\n attributes[ATTR_HTTP_REQUEST_METHOD_ORIGINAL] = method;\n }\n\n if (enableSyntheticSourceDetection && userAgent) {\n attributes[ATTR_USER_AGENT_SYNTHETIC_TYPE] = getSyntheticType(userAgent);\n }\n return Object.assign(attributes, options.hookAttributes);\n};\n\n/**\n * Returns the type of synthetic source based on the user agent\n * @param {OutgoingHttpHeader} userAgent the user agent string\n */\nconst getSyntheticType = (\n userAgent: OutgoingHttpHeader\n): AttributeValue | undefined => {\n const userAgentString: string = String(userAgent).toLowerCase();\n for (const name of SYNTHETIC_TEST_NAMES) {\n if (userAgentString.includes(name)) {\n return USER_AGENT_SYNTHETIC_TYPE_VALUE_TEST;\n }\n }\n for (const name of SYNTHETIC_BOT_NAMES) {\n if (userAgentString.includes(name)) {\n return USER_AGENT_SYNTHETIC_TYPE_VALUE_BOT;\n }\n }\n return;\n};\n\n/**\n * Returns outgoing request attributes scoped to the response data\n * @param {IncomingMessage} response the response object\n */\nexport const getOutgoingRequestAttributesOnResponse = (\n response: IncomingMessage\n): Attributes => {\n const { statusCode, socket } = response;\n const attributes: Attributes = {};\n\n if (statusCode != null) {\n attributes[ATTR_HTTP_RESPONSE_STATUS_CODE] = statusCode;\n }\n\n if (socket) {\n const { remoteAddress, remotePort } = socket;\n\n // Recommended\n attributes[ATTR_NETWORK_PEER_ADDRESS] = remoteAddress;\n attributes[ATTR_NETWORK_PEER_PORT] = remotePort;\n attributes[ATTR_NETWORK_PROTOCOL_VERSION] = response.httpVersion;\n }\n return attributes;\n};\n\n/**\n * Returns outgoing request Metric attributes scoped to the response data\n * @param {Attributes} spanAttributes the span attributes\n */\nexport const getOutgoingStableRequestMetricAttributesOnResponse = (\n spanAttributes: Attributes\n): Attributes => {\n const metricAttributes: Attributes = {};\n\n if (spanAttributes[ATTR_NETWORK_PROTOCOL_VERSION]) {\n metricAttributes[ATTR_NETWORK_PROTOCOL_VERSION] =\n spanAttributes[ATTR_NETWORK_PROTOCOL_VERSION];\n }\n\n const statusCode = spanAttributes[ATTR_HTTP_RESPONSE_STATUS_CODE];\n if (statusCode) {\n metricAttributes[ATTR_HTTP_RESPONSE_STATUS_CODE] = statusCode;\n const errorType = parseErrorType(SpanKind.CLIENT, statusCode);\n if (errorType !== undefined) {\n metricAttributes[ATTR_ERROR_TYPE] ??= errorType;\n }\n }\n return metricAttributes;\n};\n\nfunction parseHostHeader(\n hostHeader: string,\n proto?: string\n): { host: string; port?: string } {\n const parts = hostHeader.split(':');\n\n // no semicolon implies ipv4 dotted syntax or host name without port\n // x.x.x.x\n // example.com\n if (parts.length === 1) {\n if (proto === 'http') {\n return { host: parts[0], port: '80' };\n }\n\n if (proto === 'https') {\n return { host: parts[0], port: '443' };\n }\n\n return { host: parts[0] };\n }\n\n // single semicolon implies ipv4 dotted syntax or host name with port\n // x.x.x.x:yyyy\n // example.com:yyyy\n if (parts.length === 2) {\n return {\n host: parts[0],\n port: parts[1],\n };\n }\n\n // more than 2 parts implies ipv6 syntax with multiple colons\n // [x:x:x:x:x:x:x:x]\n // [x:x:x:x:x:x:x:x]:yyyy\n if (parts[0].startsWith('[')) {\n if (parts[parts.length - 1].endsWith(']')) {\n if (proto === 'http') {\n return { host: hostHeader, port: '80' };\n }\n\n if (proto === 'https') {\n return { host: hostHeader, port: '443' };\n }\n } else if (parts[parts.length - 2].endsWith(']')) {\n return {\n host: parts.slice(0, -1).join(':'),\n port: parts[parts.length - 1],\n };\n }\n }\n\n // if nothing above matches just return the host header\n return { host: hostHeader };\n}\n\n/**\n * Get server.address and port according to http semconv 1.27\n * https://github.com/open-telemetry/semantic-conventions/blob/bf0a2c1134f206f034408b201dbec37960ed60ec/docs/http/http-spans.md#setting-serveraddress-and-serverport-attributes\n */\nfunction getServerAddress(\n request: IncomingMessage,\n component: 'http' | 'https'\n): { host: string; port?: string } | null {\n const forwardedHeader = request.headers['forwarded'];\n if (forwardedHeader) {\n for (const entry of parseForwardedHeader(forwardedHeader)) {\n if (entry.host) {\n return parseHostHeader(entry.host, entry.proto);\n }\n }\n }\n\n const xForwardedHost = request.headers['x-forwarded-host'];\n if (typeof xForwardedHost === 'string') {\n if (typeof request.headers['x-forwarded-proto'] === 'string') {\n return parseHostHeader(\n xForwardedHost,\n request.headers['x-forwarded-proto']\n );\n }\n\n if (Array.isArray(request.headers['x-forwarded-proto'])) {\n return parseHostHeader(\n xForwardedHost,\n request.headers['x-forwarded-proto'][0]\n );\n }\n\n return parseHostHeader(xForwardedHost);\n } else if (\n Array.isArray(xForwardedHost) &&\n typeof xForwardedHost[0] === 'string' &&\n xForwardedHost[0].length > 0\n ) {\n if (typeof request.headers['x-forwarded-proto'] === 'string') {\n return parseHostHeader(\n xForwardedHost[0],\n request.headers['x-forwarded-proto']\n );\n }\n\n if (Array.isArray(request.headers['x-forwarded-proto'])) {\n return parseHostHeader(\n xForwardedHost[0],\n request.headers['x-forwarded-proto'][0]\n );\n }\n\n return parseHostHeader(xForwardedHost[0]);\n }\n\n const host = request.headers['host'];\n if (typeof host === 'string' && host.length > 0) {\n return parseHostHeader(host, component);\n }\n\n return null;\n}\n\n/**\n * Get server.address and port according to http semconv 1.27\n * https://github.com/open-telemetry/semantic-conventions/blob/bf0a2c1134f206f034408b201dbec37960ed60ec/docs/http/http-spans.md#setting-serveraddress-and-serverport-attributes\n */\nexport function getRemoteClientAddress(\n request: IncomingMessage\n): string | null {\n const forwardedHeader = request.headers['forwarded'];\n if (forwardedHeader) {\n for (const entry of parseForwardedHeader(forwardedHeader)) {\n if (entry.for) {\n return removePortFromAddress(entry.for);\n }\n }\n }\n\n const xForwardedFor = request.headers['x-forwarded-for'];\n if (xForwardedFor) {\n let xForwardedForVal;\n if (typeof xForwardedFor === 'string') {\n xForwardedForVal = xForwardedFor;\n } else if (Array.isArray(xForwardedFor)) {\n xForwardedForVal = xForwardedFor[0];\n }\n\n if (typeof xForwardedForVal === 'string') {\n xForwardedForVal = xForwardedForVal.split(',')[0].trim();\n return removePortFromAddress(xForwardedForVal);\n }\n }\n\n const remote = request.socket.remoteAddress;\n if (remote) {\n return remote;\n }\n\n return null;\n}\n\nfunction removePortFromAddress(input: string): string {\n // This function can be replaced with SocketAddress.parse() once the minimum\n // supported Node.js version allows it.\n try {\n const { hostname: address } = new URL(`http://${input}`);\n\n if (address.startsWith('[') && address.endsWith(']')) {\n return address.slice(1, -1);\n }\n\n return address;\n } catch {\n return input;\n }\n}\n\nfunction getInfoFromIncomingMessage(\n component: 'http' | 'https',\n request: IncomingMessage,\n logger: DiagLogger\n): { pathname?: string; search?: string; toString: () => string } {\n try {\n if (request.headers.host) {\n return new URL(\n request.url ?? '/',\n `${component}://${request.headers.host}`\n );\n } else {\n const unsafeParsedUrl = new URL(\n request.url ?? '/',\n // using localhost as a workaround to still use the URL constructor for parsing\n `${component}://localhost`\n );\n // since we use localhost as a workaround, ensure we hide the rest of the properties to avoid\n // our workaround leaking though.\n return {\n pathname: unsafeParsedUrl.pathname,\n search: unsafeParsedUrl.search,\n toString: function () {\n // we cannot use the result of unsafeParsedUrl.toString as it's potentially wrong.\n return unsafeParsedUrl.pathname + unsafeParsedUrl.search;\n },\n };\n }\n } catch (e) {\n // something is wrong, use undefined - this *should* never happen, logging\n // for troubleshooting in case it does happen.\n logger.verbose('Unable to get URL from request', e);\n return {};\n }\n}\n\n/**\n * Returns incoming request attributes scoped to the request data\n * @param {IncomingMessage} request the request object\n * @param {{ component: string, hookAttributes?: Attributes, enableSyntheticSourceDetection: boolean }} options used to pass data needed to create attributes\n */\nexport const getIncomingRequestAttributes = (\n request: IncomingMessage,\n options: {\n component: 'http' | 'https';\n hookAttributes?: Attributes;\n enableSyntheticSourceDetection: boolean;\n redactedQueryParams?: string[];\n },\n logger: DiagLogger\n): Attributes => {\n const {\n component,\n enableSyntheticSourceDetection,\n hookAttributes,\n redactedQueryParams,\n } = options;\n const { headers, method } = request;\n const { 'user-agent': userAgent } = headers;\n const parsedUrl = getInfoFromIncomingMessage(component, request, logger);\n\n // Stable attributes are used.\n const normalizedMethod = normalizeMethod(method);\n const serverAddress = getServerAddress(request, component);\n const remoteClientAddress = getRemoteClientAddress(request);\n\n const attributes: Attributes = {\n [ATTR_HTTP_REQUEST_METHOD]: normalizedMethod,\n [ATTR_URL_SCHEME]: component,\n [ATTR_SERVER_ADDRESS]: serverAddress?.host,\n [ATTR_NETWORK_PEER_ADDRESS]: request.socket.remoteAddress,\n [ATTR_NETWORK_PEER_PORT]: request.socket.remotePort,\n [ATTR_NETWORK_PROTOCOL_VERSION]: request.httpVersion,\n [ATTR_USER_AGENT_ORIGINAL]: userAgent,\n };\n\n if (parsedUrl.pathname != null) {\n attributes[ATTR_URL_PATH] = parsedUrl.pathname;\n }\n\n if (parsedUrl.search) {\n // Remove leading '?' from URL search (https://developer.mozilla.org/en-US/docs/Web/API/URL/search).\n const paramsToRedact = redactedQueryParams ?? defaultQueryStringsToRedact;\n attributes[ATTR_URL_QUERY] = redactQueryString(\n new URLSearchParams(parsedUrl.search.slice(1)),\n paramsToRedact\n );\n }\n\n if (remoteClientAddress != null) {\n attributes[ATTR_CLIENT_ADDRESS] = remoteClientAddress;\n }\n\n if (serverAddress?.port != null) {\n attributes[ATTR_SERVER_PORT] = Number(serverAddress.port);\n }\n\n // Conditionally required if request method required case normalization.\n if (method !== normalizedMethod) {\n attributes[ATTR_HTTP_REQUEST_METHOD_ORIGINAL] = method;\n }\n\n if (enableSyntheticSourceDetection && userAgent) {\n attributes[ATTR_USER_AGENT_SYNTHETIC_TYPE] = getSyntheticType(userAgent);\n }\n\n return Object.assign(attributes, hookAttributes);\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 response: ServerResponse\n): Attributes => {\n const { statusCode } = response;\n\n const attributes: Attributes = {\n [ATTR_HTTP_RESPONSE_STATUS_CODE]: statusCode,\n };\n\n const rpcMetadata = getRPCMetadata(context.active());\n if (rpcMetadata?.type === RPCType.HTTP && rpcMetadata.route !== undefined) {\n attributes[ATTR_HTTP_ROUTE] = rpcMetadata.route;\n }\n\n return attributes;\n};\n\n/**\n * Returns incoming stable request Metric attributes scoped to the request data\n * @param {Attributes} spanAttributes the span attributes\n */\nexport const getIncomingStableRequestMetricAttributesOnResponse = (\n spanAttributes: Attributes\n): Attributes => {\n const metricAttributes: Attributes = {};\n if (spanAttributes[ATTR_HTTP_ROUTE] !== undefined) {\n metricAttributes[ATTR_HTTP_ROUTE] = spanAttributes[ATTR_HTTP_ROUTE];\n }\n\n // required if and only if one was sent, same as span requirement\n const statusCode = spanAttributes[ATTR_HTTP_RESPONSE_STATUS_CODE];\n if (statusCode) {\n metricAttributes[ATTR_HTTP_RESPONSE_STATUS_CODE] = statusCode;\n const errorType = parseErrorType(SpanKind.SERVER, statusCode);\n if (errorType !== undefined) {\n metricAttributes[ATTR_ERROR_TYPE] ??= errorType;\n }\n }\n\n return metricAttributes;\n};\n\nexport function headerCapture(type: 'request' | 'response', headers: string[]) {\n const normalizedHeaders = new Map<string, string>();\n for (let i = 0, len = headers.length; i < len; i++) {\n const capturedHeader = headers[i].toLowerCase();\n normalizedHeaders.set(capturedHeader, capturedHeader);\n }\n\n return (\n getHeader: (key: string) => undefined | string | string[] | number\n ): Attributes => {\n const attributes: Attributes = {};\n for (const capturedHeader of normalizedHeaders.keys()) {\n const value = getHeader(capturedHeader);\n\n if (value === undefined) {\n continue;\n }\n\n const normalizedHeader = normalizedHeaders.get(capturedHeader);\n const key = `http.${type}.header.${normalizedHeader}`;\n\n if (typeof value === 'string') {\n attributes[key] = [value];\n } else if (Array.isArray(value)) {\n attributes[key] = value;\n } else {\n attributes[key] = [value];\n }\n }\n return attributes;\n };\n}\n\nconst KNOWN_METHODS = new Set([\n // methods from https://www.rfc-editor.org/rfc/rfc9110.html#name-methods\n 'GET',\n 'HEAD',\n 'POST',\n 'PUT',\n 'DELETE',\n 'CONNECT',\n 'OPTIONS',\n 'TRACE',\n\n // PATCH from https://www.rfc-editor.org/rfc/rfc5789.html\n 'PATCH',\n\n // QUERY from https://datatracker.ietf.org/doc/draft-ietf-httpbis-safe-method-w-body/\n 'QUERY',\n]);\n\nfunction normalizeMethod(method?: string | null) {\n if (method == null) {\n return 'GET';\n }\n\n const upper = method.toUpperCase();\n if (KNOWN_METHODS.has(upper)) {\n return upper;\n }\n\n return '_OTHER';\n}\n\nfunction parseForwardedHeader(header: string): Record<string, string>[] {\n try {\n return forwardedParse(header);\n } catch {\n return [];\n }\n}\n"],"mappings":";;;;;;;AAuDO,MAAA,iBAAA,UAAyB,iBAAA;AAEhC,MAAM,8BAA8B,MAAM,KAAK,+BAA+B;;;;;AAM9E,MAAa,qBACX,cACA,mBACW;CACX,MAAM,SAAS,IAAI,gBAAgB,YAAY;CAC/C,KAAK,MAAM,SAAS,gBAClB,IAAI,OAAO,IAAI,KAAK,GAClB,OAAO,IAAI,OAAO,YAAY;CAGlC,OAAO,OAAO,SAAS;AACzB;;;;AAKA,MAAa,kBACX,YACA,SACA,mBAAmB,SACnB,sBAAgC,MAAM,KAAK,+BAA+B,MAC/D;CACX,MAAM,eAAe,cAAc,CAAC;CACpC,MAAM,WAAW,aAAa,YAAY;CAC1C,MAAM,QAAQ,aAAa,QAAQ,GAAA,CAAI,SAAS;CAChD,IAAI,OAAO,aAAa,QAAQ;CAMhC,IAAI,OACD,OAAO,aAAa,SAAS,YAAY,aAAa,QACtD,OAAO,aAAa,aAAa,YAAY,aAAa,YAC1D,OAAO,QAAQ,SAAS,YAAY,QAAQ,QAC7C;CAGF,IAAI,KAAK,QAAQ,GAAG,MAAM,MAAM,QAAQ,SAAS,QAAQ,SAAS,OAChE,QAAQ,IAAI;CAGd,IAAI,OAAO,SAAS,YAAY,KAAK,SAAS,GAAG,GAC/C,IAAI;EACF,MAAM,YAAY,IAAI,IAAI,MAAM,kBAAkB;EAClD,MAAM,WAAW,kBACf,UAAU,cACV,mBACF;EACA,OAAO,GAAG,UAAU,SAAS,GAAG;CAClC,QAAQ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AY;CACjC,IAAI,cAAc,IAAI,KAAK,GACzB,OAAO;CAGT,OAAO;AACT;AAEA,SAAS,qBAAqB,QAA0C;CACtE,IAAI;EACF,OAAO,eAAe,MAAM;CAC9B,QAAQ;EACN,OAAO,CAAC;CACV;AACF"}
|
|
1
|
+
{"version":3,"file":"utils.mjs","names":["forwardedParse"],"sources":["../src/utils.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\nimport type {\n Attributes,\n Span,\n DiagLogger,\n AttributeValue,\n} from '@opentelemetry/api';\nimport { SpanStatusCode, context, SpanKind } from '@opentelemetry/api';\nimport {\n ATTR_CLIENT_ADDRESS,\n ATTR_ERROR_TYPE,\n ATTR_HTTP_REQUEST_METHOD,\n ATTR_HTTP_REQUEST_METHOD_ORIGINAL,\n ATTR_HTTP_RESPONSE_STATUS_CODE,\n ATTR_HTTP_ROUTE,\n ATTR_NETWORK_PEER_ADDRESS,\n ATTR_NETWORK_PEER_PORT,\n ATTR_NETWORK_PROTOCOL_VERSION,\n ATTR_SERVER_ADDRESS,\n ATTR_SERVER_PORT,\n ATTR_URL_FULL,\n ATTR_URL_PATH,\n ATTR_URL_QUERY,\n ATTR_URL_SCHEME,\n ATTR_USER_AGENT_ORIGINAL,\n} from '@opentelemetry/semantic-conventions';\nimport {\n ATTR_USER_AGENT_SYNTHETIC_TYPE,\n USER_AGENT_SYNTHETIC_TYPE_VALUE_BOT,\n USER_AGENT_SYNTHETIC_TYPE_VALUE_TEST,\n} from './semconv';\nimport type {\n IncomingHttpHeaders,\n IncomingMessage,\n OutgoingHttpHeader,\n OutgoingHttpHeaders,\n RequestOptions,\n ServerResponse,\n} from 'http';\nimport { getRPCMetadata, RPCType } from '@opentelemetry/core';\nimport type * as url from 'url';\nimport type {\n Err,\n IgnoreMatcher,\n ParsedRequestOptions,\n} from './internal-types';\nimport { SYNTHETIC_BOT_NAMES, SYNTHETIC_TEST_NAMES } from './internal-types';\nimport {\n DEFAULT_QUERY_STRINGS_TO_REDACT,\n STR_REDACTED,\n} from './internal-types';\nimport { parse as forwardedParse } from 'forwarded-parse';\n\nconst defaultQueryStringsToRedact = Array.from(DEFAULT_QUERY_STRINGS_TO_REDACT);\n\n/**\n * Redacts sensitive query parameters from a query string (without leading '?').\n * Returns the input unchanged if it cannot be parsed.\n */\nexport const redactQueryString = (\n searchParams: URLSearchParams,\n paramsToRedact: string[]\n): string => {\n const params = new URLSearchParams(searchParams);\n for (const param of paramsToRedact) {\n if (params.has(param)) {\n params.set(param, STR_REDACTED);\n }\n }\n return params.toString();\n};\n\n/**\n * Get an absolute url\n */\nexport const getAbsoluteUrl = (\n requestUrl: ParsedRequestOptions | null,\n headers: IncomingHttpHeaders | OutgoingHttpHeaders,\n fallbackProtocol = 'http:',\n redactedQueryParams: string[] = Array.from(DEFAULT_QUERY_STRINGS_TO_REDACT)\n): string => {\n const reqUrlObject = requestUrl || {};\n const protocol = reqUrlObject.protocol || fallbackProtocol;\n const port = (reqUrlObject.port || '').toString();\n let path = reqUrlObject.path || '/';\n // `host`, `hostname` and the `host` header may hold values of unexpected\n // types at runtime. Node.js itself ignores non-string values when it can\n // derive the target from another option (e.g. it uses `hostname` when\n // `host` is not a valid string), so skip non-string candidates instead of\n // crashing on them.\n let host: string =\n (typeof reqUrlObject.host === 'string' && reqUrlObject.host) ||\n (typeof reqUrlObject.hostname === 'string' && reqUrlObject.hostname) ||\n (typeof headers.host === 'string' && headers.host) ||\n 'localhost';\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 (host.indexOf(':') === -1 && port && port !== '80' && port !== '443') {\n host += `:${port}`;\n }\n // Redact sensitive query parameters\n if (typeof path === 'string' && path.includes('?')) {\n try {\n const parsedUrl = new URL(path, 'http://localhost');\n const redacted = redactQueryString(\n parsedUrl.searchParams,\n redactedQueryParams\n );\n path = `${parsedUrl.pathname}?${redacted}`;\n } catch {\n // Ignore error, as the path was not a valid URL.\n }\n }\n const authPart = reqUrlObject.auth ? `${STR_REDACTED}:${STR_REDACTED}@` : '';\n return `${protocol}//${authPart}${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 * Returns the `error.type` value for a response status code, or undefined when\n * the code is not an error for this span kind. Semconv asks for the status code\n * as a string once a response was received.\n */\nexport const parseErrorType = (\n kind: SpanKind,\n statusCode?: unknown\n): string | undefined => {\n const lowerBound = kind === SpanKind.CLIENT ? 400 : 500;\n if (\n typeof statusCode === 'number' &&\n statusCode >= lowerBound &&\n statusCode < 600\n ) {\n return String(statusCode);\n }\n\n return undefined;\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 * 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 span.setAttribute(ATTR_ERROR_TYPE, error.name);\n span.setStatus({ code: SpanStatusCode.ERROR, message });\n span.recordException(error);\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 * Mimics Node.js conversion of URL strings to RequestOptions expected by\n * `http.request` and `https.request` APIs.\n *\n * See https://github.com/nodejs/node/blob/2505e217bba05fc581b572c685c5cf280a16c5a3/lib/internal/url.js#L1415-L1437\n *\n * @param stringUrl\n * @throws TypeError if the URL is not valid.\n */\nfunction stringUrlToHttpOptions(\n stringUrl: string\n): RequestOptions & { pathname: string } {\n // This is heavily inspired by Node.js handling of the same situation, trying\n // to follow it as closely as possible while keeping in mind that we only\n // deal with string URLs, not URL objects.\n const {\n hostname,\n pathname,\n port,\n username,\n password,\n search,\n protocol,\n hash,\n href,\n origin,\n host,\n } = new URL(stringUrl);\n\n const options: RequestOptions & {\n pathname: string;\n hash: string;\n search: string;\n href: string;\n origin: string;\n } = {\n protocol: protocol,\n hostname:\n hostname && hostname[0] === '[' ? hostname.slice(1, -1) : hostname,\n hash: hash,\n search: search,\n pathname: pathname,\n path: `${pathname || ''}${search || ''}`,\n href: href,\n origin: origin,\n host: host,\n };\n if (port !== '') {\n options.port = Number(port);\n }\n if (username || password) {\n options.auth = `${decodeURIComponent(username)}:${decodeURIComponent(\n password\n )}`;\n }\n return options;\n}\n\n/**\n * Mirrors how Node.js detects WHATWG `URL` objects passed to `http.request`\n * and `https.request`: by shape rather than by `instanceof`, so that URL\n * objects from other realms (e.g. `vm` contexts) or WHATWG URL polyfills are\n * handled the same way Node.js handles them.\n *\n * This mirrors Node's `isURL()` predicate exactly. The `auth`/`path` guards\n * matter: they keep options objects and legacy `url.parse()` results (both\n * carry `path`) off the URL code path.\n *\n * See https://github.com/nodejs/node/blob/2505e217bba05fc581b572c685c5cf280a16c5a3/lib/internal/url.js#L756-L773\n */\nexport const isURLLike = (value: unknown): value is url.URL => {\n const candidate = value as\n | (url.URL & { auth?: unknown; path?: unknown })\n | undefined;\n return Boolean(\n candidate?.href &&\n candidate.protocol &&\n candidate.auth === undefined &&\n candidate.path === undefined\n );\n};\n\n/**\n * Makes sure options is an url object\n * return an object with default value and parsed options\n * @param logger component logger\n * @param options original options for the request\n * @param [extraOptions] additional options for the request\n */\nexport const getRequestInfo = (\n logger: DiagLogger,\n options: url.URL | RequestOptions | string,\n extraOptions?: RequestOptions\n): {\n origin: string;\n pathname: string;\n method: string;\n invalidUrl: boolean;\n optionsParsed: RequestOptions;\n} => {\n let pathname: string;\n let origin: string;\n let optionsParsed: RequestOptions;\n let invalidUrl = false;\n if (typeof options === 'string') {\n try {\n const convertedOptions = stringUrlToHttpOptions(options);\n optionsParsed = convertedOptions;\n pathname = convertedOptions.pathname || '/';\n } catch (e) {\n invalidUrl = true;\n logger.verbose(\n 'Unable to parse URL provided to HTTP request, using fallback to determine path. Original error:',\n e\n );\n // for backward compatibility with how url.parse() behaved.\n optionsParsed = {\n path: options,\n };\n pathname = optionsParsed.path || '/';\n }\n\n origin = `${optionsParsed.protocol || 'http:'}//${optionsParsed.host}`;\n if (extraOptions !== undefined) {\n Object.assign(optionsParsed, extraOptions);\n }\n } else if (isURLLike(options)) {\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\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 pathname = (options as url.URL).pathname;\n if (!pathname && optionsParsed.path) {\n try {\n const parsedUrl = new URL(optionsParsed.path, origin);\n pathname = parsedUrl.pathname || '/';\n } catch {\n pathname = '/';\n }\n }\n }\n\n // some packages return method in lowercase..\n // ensure upperCase for consistency\n // Note: a non-string `method` is rejected by Node.js itself; skip it here\n // so the resulting error comes from Node.js and not the instrumentation.\n const method =\n optionsParsed.method && typeof optionsParsed.method === 'string'\n ? optionsParsed.method.toUpperCase()\n : 'GET';\n\n return { origin, pathname, method, optionsParsed, invalidUrl };\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 // `hostname`, `host` and `port` may hold values of unexpected types at\n // runtime. Node.js itself ignores non-string values when it can derive the\n // target from another option (e.g. it uses `hostname` when `host` is not a\n // valid string), so skip non-string candidates instead of crashing on them.\n const optionsHostname =\n typeof requestOptions.hostname === 'string'\n ? requestOptions.hostname\n : undefined;\n const optionsHost =\n typeof requestOptions.host === 'string' ? requestOptions.host : undefined;\n const optionsPort =\n typeof requestOptions.port === 'string' ||\n typeof requestOptions.port === 'number'\n ? requestOptions.port\n : undefined;\n\n if (optionsHostname && optionsPort) {\n return { hostname: optionsHostname, port: optionsPort };\n }\n const matches = optionsHost?.match(/^([^:/ ]+)(:\\d{1,5})?/) || null;\n const hostname =\n optionsHostname || (matches === null ? 'localhost' : matches[1]);\n let port = optionsPort;\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?: Attributes }} 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?: Attributes;\n redactedQueryParams?: string[];\n },\n enableSyntheticSourceDetection: boolean\n): Attributes => {\n const hostname = options.hostname;\n const port = options.port;\n const method = requestOptions.method ?? 'GET';\n const normalizedMethod = normalizeMethod(method);\n const headers = (requestOptions.headers || {}) as OutgoingHttpHeaders;\n const userAgent = headers['user-agent'];\n const urlFull = getAbsoluteUrl(\n requestOptions,\n headers,\n `${options.component}:`,\n options.redactedQueryParams\n );\n\n const attributes: Attributes = {\n // Required attributes\n [ATTR_HTTP_REQUEST_METHOD]: normalizedMethod,\n [ATTR_SERVER_ADDRESS]: hostname,\n [ATTR_SERVER_PORT]: Number(port),\n [ATTR_URL_FULL]: urlFull,\n [ATTR_USER_AGENT_ORIGINAL]: userAgent,\n // leaving out protocol version, it is not yet negotiated\n // leaving out protocol name, it is only required when protocol version is set\n // retries and redirects not supported\n\n // Opt-in attributes left off for now\n };\n\n // conditionally required if request method required case normalization\n if (method !== normalizedMethod) {\n attributes[ATTR_HTTP_REQUEST_METHOD_ORIGINAL] = method;\n }\n\n if (enableSyntheticSourceDetection && userAgent) {\n attributes[ATTR_USER_AGENT_SYNTHETIC_TYPE] = getSyntheticType(userAgent);\n }\n return Object.assign(attributes, options.hookAttributes);\n};\n\n/**\n * Returns the type of synthetic source based on the user agent\n * @param {OutgoingHttpHeader} userAgent the user agent string\n */\nconst getSyntheticType = (\n userAgent: OutgoingHttpHeader\n): AttributeValue | undefined => {\n const userAgentString: string = String(userAgent).toLowerCase();\n for (const name of SYNTHETIC_TEST_NAMES) {\n if (userAgentString.includes(name)) {\n return USER_AGENT_SYNTHETIC_TYPE_VALUE_TEST;\n }\n }\n for (const name of SYNTHETIC_BOT_NAMES) {\n if (userAgentString.includes(name)) {\n return USER_AGENT_SYNTHETIC_TYPE_VALUE_BOT;\n }\n }\n return;\n};\n\n/**\n * Returns outgoing request attributes scoped to the response data\n * @param {IncomingMessage} response the response object\n */\nexport const getOutgoingRequestAttributesOnResponse = (\n response: IncomingMessage\n): Attributes => {\n const { statusCode, socket } = response;\n const attributes: Attributes = {};\n\n if (statusCode != null) {\n attributes[ATTR_HTTP_RESPONSE_STATUS_CODE] = statusCode;\n }\n\n if (socket) {\n const { remoteAddress, remotePort } = socket;\n\n // Recommended\n attributes[ATTR_NETWORK_PEER_ADDRESS] = remoteAddress;\n attributes[ATTR_NETWORK_PEER_PORT] = remotePort;\n attributes[ATTR_NETWORK_PROTOCOL_VERSION] = response.httpVersion;\n }\n return attributes;\n};\n\n/**\n * Returns outgoing request Metric attributes scoped to the response data\n * @param {Attributes} spanAttributes the span attributes\n */\nexport const getOutgoingStableRequestMetricAttributesOnResponse = (\n spanAttributes: Attributes\n): Attributes => {\n const metricAttributes: Attributes = {};\n\n if (spanAttributes[ATTR_NETWORK_PROTOCOL_VERSION]) {\n metricAttributes[ATTR_NETWORK_PROTOCOL_VERSION] =\n spanAttributes[ATTR_NETWORK_PROTOCOL_VERSION];\n }\n\n const statusCode = spanAttributes[ATTR_HTTP_RESPONSE_STATUS_CODE];\n if (statusCode) {\n metricAttributes[ATTR_HTTP_RESPONSE_STATUS_CODE] = statusCode;\n const errorType = parseErrorType(SpanKind.CLIENT, statusCode);\n if (errorType !== undefined) {\n metricAttributes[ATTR_ERROR_TYPE] ??= errorType;\n }\n }\n return metricAttributes;\n};\n\nfunction parseHostHeader(\n hostHeader: string,\n proto?: string\n): { host: string; port?: string } {\n const parts = hostHeader.split(':');\n\n // no semicolon implies ipv4 dotted syntax or host name without port\n // x.x.x.x\n // example.com\n if (parts.length === 1) {\n if (proto === 'http') {\n return { host: parts[0], port: '80' };\n }\n\n if (proto === 'https') {\n return { host: parts[0], port: '443' };\n }\n\n return { host: parts[0] };\n }\n\n // single semicolon implies ipv4 dotted syntax or host name with port\n // x.x.x.x:yyyy\n // example.com:yyyy\n if (parts.length === 2) {\n return {\n host: parts[0],\n port: parts[1],\n };\n }\n\n // more than 2 parts implies ipv6 syntax with multiple colons\n // [x:x:x:x:x:x:x:x]\n // [x:x:x:x:x:x:x:x]:yyyy\n if (parts[0].startsWith('[')) {\n if (parts[parts.length - 1].endsWith(']')) {\n if (proto === 'http') {\n return { host: hostHeader, port: '80' };\n }\n\n if (proto === 'https') {\n return { host: hostHeader, port: '443' };\n }\n } else if (parts[parts.length - 2].endsWith(']')) {\n return {\n host: parts.slice(0, -1).join(':'),\n port: parts[parts.length - 1],\n };\n }\n }\n\n // if nothing above matches just return the host header\n return { host: hostHeader };\n}\n\n/**\n * Get server.address and port according to http semconv 1.27\n * https://github.com/open-telemetry/semantic-conventions/blob/bf0a2c1134f206f034408b201dbec37960ed60ec/docs/http/http-spans.md#setting-serveraddress-and-serverport-attributes\n */\nfunction getServerAddress(\n request: IncomingMessage,\n component: 'http' | 'https'\n): { host: string; port?: string } | null {\n const forwardedHeader = request.headers['forwarded'];\n if (forwardedHeader) {\n for (const entry of parseForwardedHeader(forwardedHeader)) {\n if (entry.host) {\n return parseHostHeader(entry.host, entry.proto);\n }\n }\n }\n\n const xForwardedHost = request.headers['x-forwarded-host'];\n if (typeof xForwardedHost === 'string') {\n if (typeof request.headers['x-forwarded-proto'] === 'string') {\n return parseHostHeader(\n xForwardedHost,\n request.headers['x-forwarded-proto']\n );\n }\n\n if (Array.isArray(request.headers['x-forwarded-proto'])) {\n return parseHostHeader(\n xForwardedHost,\n request.headers['x-forwarded-proto'][0]\n );\n }\n\n return parseHostHeader(xForwardedHost);\n } else if (\n Array.isArray(xForwardedHost) &&\n typeof xForwardedHost[0] === 'string' &&\n xForwardedHost[0].length > 0\n ) {\n if (typeof request.headers['x-forwarded-proto'] === 'string') {\n return parseHostHeader(\n xForwardedHost[0],\n request.headers['x-forwarded-proto']\n );\n }\n\n if (Array.isArray(request.headers['x-forwarded-proto'])) {\n return parseHostHeader(\n xForwardedHost[0],\n request.headers['x-forwarded-proto'][0]\n );\n }\n\n return parseHostHeader(xForwardedHost[0]);\n }\n\n const host = request.headers['host'];\n if (typeof host === 'string' && host.length > 0) {\n return parseHostHeader(host, component);\n }\n\n return null;\n}\n\n/**\n * Get server.address and port according to http semconv 1.27\n * https://github.com/open-telemetry/semantic-conventions/blob/bf0a2c1134f206f034408b201dbec37960ed60ec/docs/http/http-spans.md#setting-serveraddress-and-serverport-attributes\n */\nexport function getRemoteClientAddress(\n request: IncomingMessage\n): string | null {\n const forwardedHeader = request.headers['forwarded'];\n if (forwardedHeader) {\n for (const entry of parseForwardedHeader(forwardedHeader)) {\n if (entry.for) {\n return removePortFromAddress(entry.for);\n }\n }\n }\n\n const xForwardedFor = request.headers['x-forwarded-for'];\n if (xForwardedFor) {\n let xForwardedForVal;\n if (typeof xForwardedFor === 'string') {\n xForwardedForVal = xForwardedFor;\n } else if (Array.isArray(xForwardedFor)) {\n xForwardedForVal = xForwardedFor[0];\n }\n\n if (typeof xForwardedForVal === 'string') {\n xForwardedForVal = xForwardedForVal.split(',')[0].trim();\n return removePortFromAddress(xForwardedForVal);\n }\n }\n\n const remote = request.socket.remoteAddress;\n if (remote) {\n return remote;\n }\n\n return null;\n}\n\nfunction removePortFromAddress(input: string): string {\n // This function can be replaced with SocketAddress.parse() once the minimum\n // supported Node.js version allows it.\n try {\n const { hostname: address } = new URL(`http://${input}`);\n\n if (address.startsWith('[') && address.endsWith(']')) {\n return address.slice(1, -1);\n }\n\n return address;\n } catch {\n return input;\n }\n}\n\nfunction getInfoFromIncomingMessage(\n component: 'http' | 'https',\n request: IncomingMessage,\n logger: DiagLogger\n): { pathname?: string; search?: string; toString: () => string } {\n try {\n if (request.headers.host) {\n return new URL(\n request.url ?? '/',\n `${component}://${request.headers.host}`\n );\n } else {\n const unsafeParsedUrl = new URL(\n request.url ?? '/',\n // using localhost as a workaround to still use the URL constructor for parsing\n `${component}://localhost`\n );\n // since we use localhost as a workaround, ensure we hide the rest of the properties to avoid\n // our workaround leaking though.\n return {\n pathname: unsafeParsedUrl.pathname,\n search: unsafeParsedUrl.search,\n toString: function () {\n // we cannot use the result of unsafeParsedUrl.toString as it's potentially wrong.\n return unsafeParsedUrl.pathname + unsafeParsedUrl.search;\n },\n };\n }\n } catch (e) {\n // something is wrong, use undefined - this *should* never happen, logging\n // for troubleshooting in case it does happen.\n logger.verbose('Unable to get URL from request', e);\n return {};\n }\n}\n\n/**\n * Returns incoming request attributes scoped to the request data\n * @param {IncomingMessage} request the request object\n * @param {{ component: string, hookAttributes?: Attributes, enableSyntheticSourceDetection: boolean }} options used to pass data needed to create attributes\n */\nexport const getIncomingRequestAttributes = (\n request: IncomingMessage,\n options: {\n component: 'http' | 'https';\n hookAttributes?: Attributes;\n enableSyntheticSourceDetection: boolean;\n redactedQueryParams?: string[];\n },\n logger: DiagLogger\n): Attributes => {\n const {\n component,\n enableSyntheticSourceDetection,\n hookAttributes,\n redactedQueryParams,\n } = options;\n const { headers, method } = request;\n const { 'user-agent': userAgent } = headers;\n const parsedUrl = getInfoFromIncomingMessage(component, request, logger);\n\n // Stable attributes are used.\n const normalizedMethod = normalizeMethod(method);\n const serverAddress = getServerAddress(request, component);\n const remoteClientAddress = getRemoteClientAddress(request);\n\n const attributes: Attributes = {\n [ATTR_HTTP_REQUEST_METHOD]: normalizedMethod,\n [ATTR_URL_SCHEME]: component,\n [ATTR_SERVER_ADDRESS]: serverAddress?.host,\n [ATTR_NETWORK_PEER_ADDRESS]: request.socket.remoteAddress,\n [ATTR_NETWORK_PEER_PORT]: request.socket.remotePort,\n [ATTR_NETWORK_PROTOCOL_VERSION]: request.httpVersion,\n [ATTR_USER_AGENT_ORIGINAL]: userAgent,\n };\n\n if (parsedUrl.pathname != null) {\n attributes[ATTR_URL_PATH] = parsedUrl.pathname;\n }\n\n if (parsedUrl.search) {\n // Remove leading '?' from URL search (https://developer.mozilla.org/en-US/docs/Web/API/URL/search).\n const paramsToRedact = redactedQueryParams ?? defaultQueryStringsToRedact;\n attributes[ATTR_URL_QUERY] = redactQueryString(\n new URLSearchParams(parsedUrl.search.slice(1)),\n paramsToRedact\n );\n }\n\n if (remoteClientAddress != null) {\n attributes[ATTR_CLIENT_ADDRESS] = remoteClientAddress;\n }\n\n if (serverAddress?.port != null) {\n attributes[ATTR_SERVER_PORT] = Number(serverAddress.port);\n }\n\n // Conditionally required if request method required case normalization.\n if (method !== normalizedMethod) {\n attributes[ATTR_HTTP_REQUEST_METHOD_ORIGINAL] = method;\n }\n\n if (enableSyntheticSourceDetection && userAgent) {\n attributes[ATTR_USER_AGENT_SYNTHETIC_TYPE] = getSyntheticType(userAgent);\n }\n\n return Object.assign(attributes, hookAttributes);\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 response: ServerResponse\n): Attributes => {\n const { statusCode } = response;\n\n const attributes: Attributes = {\n [ATTR_HTTP_RESPONSE_STATUS_CODE]: statusCode,\n };\n\n const rpcMetadata = getRPCMetadata(context.active());\n if (rpcMetadata?.type === RPCType.HTTP && rpcMetadata.route !== undefined) {\n attributes[ATTR_HTTP_ROUTE] = rpcMetadata.route;\n }\n\n return attributes;\n};\n\n/**\n * Returns incoming stable request Metric attributes scoped to the request data\n * @param {Attributes} spanAttributes the span attributes\n */\nexport const getIncomingStableRequestMetricAttributesOnResponse = (\n spanAttributes: Attributes\n): Attributes => {\n const metricAttributes: Attributes = {};\n if (spanAttributes[ATTR_HTTP_ROUTE] !== undefined) {\n metricAttributes[ATTR_HTTP_ROUTE] = spanAttributes[ATTR_HTTP_ROUTE];\n }\n\n // required if and only if one was sent, same as span requirement\n const statusCode = spanAttributes[ATTR_HTTP_RESPONSE_STATUS_CODE];\n if (statusCode) {\n metricAttributes[ATTR_HTTP_RESPONSE_STATUS_CODE] = statusCode;\n const errorType = parseErrorType(SpanKind.SERVER, statusCode);\n if (errorType !== undefined) {\n metricAttributes[ATTR_ERROR_TYPE] ??= errorType;\n }\n }\n\n return metricAttributes;\n};\n\nexport function headerCapture(type: 'request' | 'response', headers: string[]) {\n const normalizedHeaders = new Map<string, string>();\n for (let i = 0, len = headers.length; i < len; i++) {\n const capturedHeader = headers[i].toLowerCase();\n normalizedHeaders.set(capturedHeader, capturedHeader);\n }\n\n return (\n getHeader: (key: string) => undefined | string | string[] | number\n ): Attributes => {\n const attributes: Attributes = {};\n for (const capturedHeader of normalizedHeaders.keys()) {\n const value = getHeader(capturedHeader);\n\n if (value === undefined) {\n continue;\n }\n\n const normalizedHeader = normalizedHeaders.get(capturedHeader);\n const key = `http.${type}.header.${normalizedHeader}`;\n\n if (typeof value === 'string') {\n attributes[key] = [value];\n } else if (Array.isArray(value)) {\n attributes[key] = value;\n } else {\n attributes[key] = [value];\n }\n }\n return attributes;\n };\n}\n\nconst KNOWN_METHODS = new Set([\n // methods from https://www.rfc-editor.org/rfc/rfc9110.html#name-methods\n 'GET',\n 'HEAD',\n 'POST',\n 'PUT',\n 'DELETE',\n 'CONNECT',\n 'OPTIONS',\n 'TRACE',\n\n // PATCH from https://www.rfc-editor.org/rfc/rfc5789.html\n 'PATCH',\n\n // QUERY from https://datatracker.ietf.org/doc/draft-ietf-httpbis-safe-method-w-body/\n 'QUERY',\n]);\n\nfunction normalizeMethod(method?: string | null) {\n if (method == null) {\n return 'GET';\n }\n\n const upper = method.toUpperCase();\n if (KNOWN_METHODS.has(upper)) {\n return upper;\n }\n\n return '_OTHER';\n}\n\nfunction parseForwardedHeader(header: string): Record<string, string>[] {\n try {\n return forwardedParse(header);\n } catch {\n return [];\n }\n}\n"],"mappings":";;;;;;;AAwDA,MAAM,8BAA8B,MAAM,KAAK,+BAA+B;;;;;AAM9E,MAAa,qBACX,cACA,mBACW;CACX,MAAM,SAAS,IAAI,gBAAgB,YAAY;CAC/C,KAAK,MAAM,SAAS,gBAClB,IAAI,OAAO,IAAI,KAAK,GAClB,OAAO,IAAI,OAAO,YAAY;CAGlC,OAAO,OAAO,SAAS;AACzB;;;;AAKA,MAAa,kBACX,YACA,SACA,mBAAmB,SACnB,sBAAgC,MAAM,KAAK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,gBAAgB,cAAc;CACtD;CAEA,QACE,cACe;EACf,MAAM,aAAyB,CAAC;EAChC,KAAK,MAAM,kBAAkB,kBAAkB,KAAK,GAAG;GACrD,MAAM,QAAQ,UAAU,cAAc;GAEtC,IAAI,UAAU,KAAA,GACZ;GAIF,MAAM,MAAM,QAAQ,KAAK,UADA,kBAAkB,IAAI,cACG;GAElD,IAAI,OAAO,UAAU,UACnB,WAAW,OAAO,CAAC,KAAK;QACnB,IAAI,MAAM,QAAQ,KAAK,GAC5B,WAAW,OAAO;QAElB,WAAW,OAAO,CAAC,KAAK;EAE5B;EACA,OAAO;CACT;AACF;AAEA,MAAM,gCAAgB,IAAI,IAAI;CAE5B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAGA;CAGA;AACF,CAAC;AAED,SAAS,gBAAgB,QAAwB;CAC/C,IAAI,UAAU,MACZ,OAAO;CAGT,MAAM,QAAQ,OAAO,YAAY;CACjC,IAAI,cAAc,IAAI,KAAK,GACzB,OAAO;CAGT,OAAO;AACT;AAEA,SAAS,qBAAqB,QAA0C;CACtE,IAAI;EACF,OAAOA,MAAe,MAAM;CAC9B,QAAQ;EACN,OAAO,CAAC;CACV;AACF"}
|
package/dist/version.cjs
CHANGED
package/dist/version.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.cjs","names":[],"sources":["../src/version.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '0.
|
|
1
|
+
{"version":3,"file":"version.cjs","names":[],"sources":["../src/version.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '0.301.0';\n"],"mappings":";AAMA,MAAa,UAAU"}
|
package/dist/version.mjs
CHANGED
package/dist/version.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.mjs","names":[],"sources":["../src/version.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '0.
|
|
1
|
+
{"version":3,"file":"version.mjs","names":[],"sources":["../src/version.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '0.301.0';\n"],"mappings":";AAMA,MAAa,UAAU"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opentelemetry/instrumentation-http",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.301.0",
|
|
4
4
|
"description": "OpenTelemetry instrumentation for `node:http` and `node:https` http client and server modules",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"types": "./dist/index.d.cts",
|
|
@@ -59,9 +59,9 @@
|
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@opentelemetry/api": "1.10.0",
|
|
62
|
-
"@opentelemetry/context-async-hooks": "3.
|
|
63
|
-
"@opentelemetry/sdk-metrics": "3.
|
|
64
|
-
"@opentelemetry/sdk-trace": "3.
|
|
62
|
+
"@opentelemetry/context-async-hooks": "3.1.0",
|
|
63
|
+
"@opentelemetry/sdk-metrics": "3.1.0",
|
|
64
|
+
"@opentelemetry/sdk-trace": "3.1.0",
|
|
65
65
|
"@types/mocha": "10.0.10",
|
|
66
66
|
"@types/node": "18.19.130",
|
|
67
67
|
"@types/request-promise-native": "1.0.21",
|
|
@@ -76,15 +76,15 @@
|
|
|
76
76
|
"typescript": "5.2.2"
|
|
77
77
|
},
|
|
78
78
|
"peerDependencies": {
|
|
79
|
-
"@opentelemetry/api": "^1.
|
|
79
|
+
"@opentelemetry/api": "^1.10.0"
|
|
80
80
|
},
|
|
81
81
|
"dependencies": {
|
|
82
|
-
"@opentelemetry/core": "3.
|
|
83
|
-
"@opentelemetry/instrumentation": "0.
|
|
82
|
+
"@opentelemetry/core": "3.1.0",
|
|
83
|
+
"@opentelemetry/instrumentation": "0.301.0",
|
|
84
84
|
"@opentelemetry/semantic-conventions": "^1.29.0",
|
|
85
|
-
"forwarded-parse": "2.
|
|
85
|
+
"forwarded-parse": "2.2.0"
|
|
86
86
|
},
|
|
87
87
|
"homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/opentelemetry-instrumentation-http",
|
|
88
88
|
"sideEffects": false,
|
|
89
|
-
"gitHead": "
|
|
89
|
+
"gitHead": "9985264933cc7d93bfa4cbd02f1de562a050e9ce"
|
|
90
90
|
}
|