@opentelemetry/instrumentation-http 0.301.1 → 0.302.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/README.md +52 -0
- package/dist/http.cjs +38 -3
- package/dist/http.cjs.map +1 -1
- package/dist/http.d.cts +8 -4
- package/dist/http.d.cts.map +1 -1
- package/dist/http.d.mts +8 -4
- package/dist/http.d.mts.map +1 -1
- package/dist/http.mjs +39 -4
- package/dist/http.mjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -2
- package/dist/internal-types.cjs +1 -2
- package/dist/internal-types.cjs.map +1 -1
- package/dist/internal-types.mjs +1 -2
- package/dist/internal-types.mjs.map +1 -1
- package/dist/semconv.cjs +1 -2
- package/dist/semconv.mjs +1 -2
- package/dist/types.d.cts +8 -11
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +8 -11
- package/dist/types.d.mts.map +1 -1
- package/dist/utils.cjs +1 -2
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.mjs +1 -2
- package/dist/utils.mjs.map +1 -1
- package/dist/version.cjs +2 -3
- package/dist/version.cjs.map +1 -1
- package/dist/version.mjs +2 -3
- package/dist/version.mjs.map +1 -1
- package/package.json +13 -11
package/dist/http.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.mjs","names":[],"sources":["../src/http.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type {\n HrTime,\n Span,\n SpanOptions,\n SpanStatus,\n Histogram,\n Attributes,\n} from '@opentelemetry/api';\nimport {\n context,\n INVALID_SPAN_CONTEXT,\n propagation,\n ROOT_CONTEXT,\n SpanKind,\n SpanStatusCode,\n trace,\n ValueType,\n} from '@opentelemetry/api';\nimport type { RPCMetadata } from '@opentelemetry/core';\nimport {\n hrTime,\n hrTimeDuration,\n hrTimeToMilliseconds,\n suppressTracing,\n RPCType,\n setRPCMetadata,\n} from '@opentelemetry/core';\nimport type * as http from 'http';\nimport type * as https from 'https';\nimport type { Socket } from 'net';\nimport type * as url from 'url';\nimport type { HttpInstrumentationConfig } from './types';\nimport { VERSION } from './version';\nimport {\n InstrumentationBase,\n InstrumentationNodeModuleDefinition,\n safeExecuteInTheMiddle,\n} from '@opentelemetry/instrumentation';\nimport { errorMonitor } from 'events';\nimport {\n ATTR_ERROR_TYPE,\n ATTR_HTTP_REQUEST_METHOD,\n ATTR_HTTP_RESPONSE_STATUS_CODE,\n ATTR_NETWORK_PROTOCOL_VERSION,\n ATTR_HTTP_ROUTE,\n ATTR_SERVER_ADDRESS,\n ATTR_SERVER_PORT,\n ATTR_URL_SCHEME,\n METRIC_HTTP_CLIENT_REQUEST_DURATION,\n METRIC_HTTP_SERVER_REQUEST_DURATION,\n} from '@opentelemetry/semantic-conventions';\nimport {\n extractHostnameAndPort,\n getIncomingRequestAttributes,\n getIncomingRequestAttributesOnResponse,\n getIncomingStableRequestMetricAttributesOnResponse,\n getOutgoingRequestAttributes,\n getOutgoingRequestAttributesOnResponse,\n getOutgoingStableRequestMetricAttributesOnResponse,\n getRequestInfo,\n isURLLike,\n headerCapture,\n isValidOptionsType,\n parseErrorType,\n parseResponseStatus,\n setSpanWithError,\n} from './utils';\nimport type { Err, Func, Http, HttpRequestArgs, Https } from './internal-types';\nimport { DEFAULT_QUERY_STRINGS_TO_REDACT } from './internal-types';\n\n/**\n * `node:http` and `node:https` instrumentation for OpenTelemetry\n */\nexport class HttpInstrumentation extends InstrumentationBase<HttpInstrumentationConfig> {\n /** keep track on spans not ended */\n private readonly _spanNotEnded: WeakSet<Span> = new WeakSet<Span>();\n private _headerCapture;\n private _httpPatched: boolean = false;\n private _httpsPatched: boolean = false;\n declare private _httpServerDurationHistogram: Histogram;\n declare private _httpClientDurationHistogram: Histogram;\n\n constructor(config: HttpInstrumentationConfig = {}) {\n super('@opentelemetry/instrumentation-http', VERSION, config);\n this._headerCapture = this._createHeaderCapture();\n }\n\n protected override _updateMetricInstruments() {\n this._httpServerDurationHistogram = this.meter.createHistogram(\n METRIC_HTTP_SERVER_REQUEST_DURATION,\n {\n description: 'Duration of HTTP server requests.',\n unit: 's',\n valueType: ValueType.DOUBLE,\n advice: {\n explicitBucketBoundaries: [\n 0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1, 2.5, 5,\n 7.5, 10,\n ],\n },\n }\n );\n this._httpClientDurationHistogram = this.meter.createHistogram(\n METRIC_HTTP_CLIENT_REQUEST_DURATION,\n {\n description: 'Duration of HTTP client requests.',\n unit: 's',\n valueType: ValueType.DOUBLE,\n advice: {\n explicitBucketBoundaries: [\n 0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1, 2.5, 5,\n 7.5, 10,\n ],\n },\n }\n );\n }\n\n private _recordServerDuration(durationMs: number, attributes: Attributes) {\n // stable histogram is counted in S\n this._httpServerDurationHistogram.record(durationMs / 1000, attributes);\n }\n\n private _recordClientDuration(durationMs: number, attributes: Attributes) {\n // stable histogram is counted in S\n this._httpClientDurationHistogram.record(durationMs / 1000, attributes);\n }\n\n override setConfig(config: HttpInstrumentationConfig = {}): void {\n super.setConfig(config);\n this._headerCapture = this._createHeaderCapture();\n }\n\n init(): [\n InstrumentationNodeModuleDefinition,\n InstrumentationNodeModuleDefinition,\n ] {\n return [this._getHttpsInstrumentation(), this._getHttpInstrumentation()];\n }\n\n private _getHttpInstrumentation() {\n return new InstrumentationNodeModuleDefinition(\n 'http',\n ['*'],\n (moduleExports: Http): Http => {\n // Guard against double-instrumentation, if loaded by both `require`\n // and `import`.\n if (this._httpPatched) {\n return moduleExports;\n }\n this._httpPatched = true;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const isESM = (moduleExports as any)[Symbol.toStringTag] === 'Module';\n\n if (!this.getConfig().disableOutgoingRequestInstrumentation) {\n const patchedRequest = this._wrap(\n moduleExports,\n 'request',\n this._getPatchOutgoingRequestFunction('http')\n ) as unknown as Func<http.ClientRequest>;\n const patchedGet = this._wrap(\n moduleExports,\n 'get',\n this._getPatchOutgoingGetFunction(patchedRequest)\n );\n if (isESM) {\n // To handle `import http from 'http'`, which returns the default\n // export, we need to set `module.default.*`.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (moduleExports as any).default.request = patchedRequest;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (moduleExports as any).default.get = patchedGet;\n }\n }\n if (!this.getConfig().disableIncomingRequestInstrumentation) {\n this._wrap(\n moduleExports.Server.prototype,\n 'emit',\n this._getPatchIncomingRequestFunction('http')\n );\n }\n return moduleExports;\n },\n (moduleExports: Http) => {\n this._httpPatched = false;\n if (moduleExports === undefined) return;\n\n if (!this.getConfig().disableOutgoingRequestInstrumentation) {\n this._unwrap(moduleExports, 'request');\n this._unwrap(moduleExports, 'get');\n }\n if (!this.getConfig().disableIncomingRequestInstrumentation) {\n this._unwrap(moduleExports.Server.prototype, 'emit');\n }\n }\n );\n }\n\n private _getHttpsInstrumentation() {\n return new InstrumentationNodeModuleDefinition(\n 'https',\n ['*'],\n (moduleExports: Https): Https => {\n // Guard against double-instrumentation, if loaded by both `require`\n // and `import`.\n if (this._httpsPatched) {\n return moduleExports;\n }\n this._httpsPatched = true;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const isESM = (moduleExports as any)[Symbol.toStringTag] === 'Module';\n\n if (!this.getConfig().disableOutgoingRequestInstrumentation) {\n const patchedRequest = this._wrap(\n moduleExports,\n 'request',\n this._getPatchHttpsOutgoingRequestFunction('https')\n ) as unknown as Func<http.ClientRequest>;\n const patchedGet = this._wrap(\n moduleExports,\n 'get',\n this._getPatchHttpsOutgoingGetFunction(patchedRequest)\n );\n if (isESM) {\n // To handle `import https from 'https'`, which returns the default\n // export, we need to set `module.default.*`.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (moduleExports as any).default.request = patchedRequest;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (moduleExports as any).default.get = patchedGet;\n }\n }\n if (!this.getConfig().disableIncomingRequestInstrumentation) {\n this._wrap(\n moduleExports.Server.prototype,\n 'emit',\n this._getPatchIncomingRequestFunction('https')\n );\n }\n return moduleExports;\n },\n (moduleExports: Https) => {\n this._httpsPatched = false;\n if (moduleExports === undefined) return;\n\n if (!this.getConfig().disableOutgoingRequestInstrumentation) {\n this._unwrap(moduleExports, 'request');\n this._unwrap(moduleExports, 'get');\n }\n if (!this.getConfig().disableIncomingRequestInstrumentation) {\n this._unwrap(moduleExports.Server.prototype, 'emit');\n }\n }\n );\n }\n\n /**\n * Creates spans for incoming requests, restoring spans' context if applied.\n */\n private _getPatchIncomingRequestFunction(component: 'http' | 'https') {\n return (\n original: (event: string, ...args: unknown[]) => boolean\n ): ((this: unknown, event: string, ...args: unknown[]) => boolean) => {\n return this._incomingRequestFunction(component, original);\n };\n }\n\n /**\n * Creates spans for outgoing requests, sending spans' context for distributed\n * tracing.\n */\n private _getPatchOutgoingRequestFunction(component: 'http' | 'https') {\n return (original: Func<http.ClientRequest>): Func<http.ClientRequest> => {\n return this._outgoingRequestFunction(component, original);\n };\n }\n\n private _getPatchOutgoingGetFunction(\n clientRequest: (\n options: http.RequestOptions | string | url.URL,\n ...args: HttpRequestArgs\n ) => http.ClientRequest\n ) {\n return (_original: Func<http.ClientRequest>): Func<http.ClientRequest> => {\n // Re-implement http.get. This needs to be done (instead of using\n // getPatchOutgoingRequestFunction to patch it) because we need to\n // set the trace context header before the returned http.ClientRequest is\n // ended. The Node.js docs state that the only differences between\n // request and get are that (1) get defaults to the HTTP GET method and\n // (2) the returned request object is ended immediately. The former is\n // already true (at least in supported Node versions up to v10), so we\n // simply follow the latter. Ref:\n // https://nodejs.org/dist/latest/docs/api/http.html#http_http_get_options_callback\n // https://github.com/googleapis/cloud-trace-nodejs/blob/master/src/instrumentations/instrumentation-http.ts#L198\n return function outgoingGetRequest<\n T extends http.RequestOptions | string | url.URL,\n >(options: T, ...args: HttpRequestArgs): http.ClientRequest {\n const req = clientRequest(options, ...args);\n req.end();\n return req;\n };\n };\n }\n\n /** Patches HTTPS outgoing requests */\n private _getPatchHttpsOutgoingRequestFunction(component: 'http' | 'https') {\n return (original: Func<http.ClientRequest>): Func<http.ClientRequest> => {\n const instrumentation = this;\n return function httpsOutgoingRequest(\n options: https.RequestOptions | string | URL,\n ...args: HttpRequestArgs\n ): http.ClientRequest {\n // Makes sure options will have default HTTPS parameters\n if (\n component === 'https' &&\n typeof options === 'object' &&\n options?.constructor?.name !== 'URL'\n ) {\n options = Object.assign({}, options);\n instrumentation._setDefaultOptions(options);\n }\n return instrumentation._getPatchOutgoingRequestFunction(component)(\n original\n )(options, ...args);\n };\n };\n }\n\n private _setDefaultOptions(options: https.RequestOptions) {\n options.protocol = options.protocol || 'https:';\n options.port = options.port || 443;\n }\n\n /** Patches HTTPS outgoing get requests */\n private _getPatchHttpsOutgoingGetFunction(\n clientRequest: (\n options: http.RequestOptions | string | URL,\n ...args: HttpRequestArgs\n ) => http.ClientRequest\n ) {\n return (original: Func<http.ClientRequest>): Func<http.ClientRequest> => {\n const instrumentation = this;\n return function httpsOutgoingRequest(\n options: https.RequestOptions | string | URL,\n ...args: HttpRequestArgs\n ): http.ClientRequest {\n return instrumentation._getPatchOutgoingGetFunction(clientRequest)(\n original\n )(options, ...args);\n };\n };\n }\n\n /**\n * Attach event listeners to a client request to end span and add span attributes.\n *\n * @param request The original request object.\n * @param span representing the current operation\n * @param startTime representing the start time of the request to calculate duration in Metric\n * @param metricAttributes metric attributes for the request duration metric\n */\n private _traceClientRequest(\n request: http.ClientRequest,\n span: Span,\n startTime: HrTime,\n metricAttributes: Attributes\n ): http.ClientRequest {\n if (this.getConfig().requestHook) {\n this._callRequestHook(span, request);\n }\n\n /**\n * Determines if the request has errored or the response has ended/errored.\n */\n let responseFinished = false;\n\n /*\n * User 'response' event listeners can be added before our listener,\n * force our listener to be the first, so response emitter is bound\n * before any user listeners are added to it.\n */\n request.prependListener(\n 'response',\n (response: http.IncomingMessage & { aborted?: boolean }) => {\n this._diag.debug('outgoingRequest on response()');\n if (request.listenerCount('response') <= 1) {\n response.resume();\n }\n const responseAttributes =\n getOutgoingRequestAttributesOnResponse(response);\n span.setAttributes(responseAttributes);\n metricAttributes = Object.assign(\n metricAttributes,\n getOutgoingStableRequestMetricAttributesOnResponse(responseAttributes)\n );\n\n if (this.getConfig().responseHook) {\n this._callResponseHook(span, response);\n }\n\n span.setAttributes(\n this._headerCapture.client.captureRequestHeaders(header =>\n request.getHeader(header)\n )\n );\n span.setAttributes(\n this._headerCapture.client.captureResponseHeaders(\n header => response.headers[header]\n )\n );\n\n context.bind(context.active(), response);\n\n const endHandler = () => {\n this._diag.debug('outgoingRequest on end()');\n if (responseFinished) {\n return;\n }\n responseFinished = true;\n let status: SpanStatus;\n\n if (response.aborted && !response.complete) {\n status = { code: SpanStatusCode.ERROR };\n } else {\n // behaves same for new and old semconv\n status = {\n code: parseResponseStatus(SpanKind.CLIENT, response.statusCode),\n };\n const errorType = parseErrorType(\n SpanKind.CLIENT,\n response.statusCode\n );\n if (errorType !== undefined) {\n span.setAttribute(ATTR_ERROR_TYPE, errorType);\n }\n }\n\n span.setStatus(status);\n\n if (this.getConfig().applyCustomAttributesOnSpan) {\n safeExecuteInTheMiddle(\n () =>\n this.getConfig().applyCustomAttributesOnSpan!(\n span,\n request,\n response\n ),\n () => {},\n true\n );\n }\n\n this._closeHttpSpan(\n span,\n SpanKind.CLIENT,\n startTime,\n metricAttributes\n );\n };\n\n response.on('end', endHandler);\n response.on(errorMonitor, (error: Err) => {\n this._diag.debug('outgoingRequest on error()', error);\n if (responseFinished) {\n return;\n }\n responseFinished = true;\n this._onOutgoingRequestError(\n span,\n metricAttributes,\n startTime,\n error\n );\n });\n }\n );\n request.on('close', () => {\n this._diag.debug('outgoingRequest on request close()');\n if (request.aborted || responseFinished) {\n return;\n }\n responseFinished = true;\n this._closeHttpSpan(span, SpanKind.CLIENT, startTime, metricAttributes);\n });\n request.on(errorMonitor, (error: Err) => {\n this._diag.debug('outgoingRequest on request error()', error);\n if (responseFinished) {\n return;\n }\n responseFinished = true;\n this._onOutgoingRequestError(span, metricAttributes, startTime, error);\n });\n\n this._diag.debug('http.ClientRequest return request');\n return request;\n }\n\n private _incomingRequestFunction(\n component: 'http' | 'https',\n original: (event: string, ...args: unknown[]) => boolean\n ) {\n const instrumentation = this;\n return function incomingRequest(\n this: unknown,\n event: string,\n ...args: unknown[]\n ): boolean {\n // Only traces request events\n if (event !== 'request') {\n return original.apply(this, [event, ...args]);\n }\n\n const request = args[0] as http.IncomingMessage;\n const response = args[1] as http.ServerResponse & { socket: Socket };\n const method = request.method || 'GET';\n\n instrumentation._diag.debug(\n `${component} instrumentation incomingRequest`\n );\n\n if (\n safeExecuteInTheMiddle(\n () =>\n instrumentation.getConfig().ignoreIncomingRequestHook?.(request),\n (e: unknown) => {\n if (e != null) {\n instrumentation._diag.error(\n 'caught ignoreIncomingRequestHook error: ',\n e\n );\n }\n },\n true\n )\n ) {\n return context.with(suppressTracing(context.active()), () => {\n context.bind(context.active(), request);\n context.bind(context.active(), response);\n return original.apply(this, [event, ...args]);\n });\n }\n\n const headers = request.headers;\n\n const spanAttributes = getIncomingRequestAttributes(\n request,\n {\n component: component,\n hookAttributes: instrumentation._callStartSpanHook(\n request,\n instrumentation.getConfig().startIncomingSpanHook\n ),\n enableSyntheticSourceDetection:\n instrumentation.getConfig().enableSyntheticSourceDetection || false,\n redactedQueryParams:\n instrumentation.getConfig().redactedQueryParamsServer ??\n Array.from(DEFAULT_QUERY_STRINGS_TO_REDACT),\n },\n instrumentation._diag\n );\n\n Object.assign(\n spanAttributes,\n instrumentation._headerCapture.server.captureRequestHeaders(\n header => request.headers[header]\n )\n );\n\n const spanOptions: SpanOptions = {\n kind: SpanKind.SERVER,\n attributes: spanAttributes,\n };\n\n const startTime = hrTime();\n\n // request method and url.scheme are both required span attributes\n const metricAttributes: Attributes = {\n [ATTR_HTTP_REQUEST_METHOD]: spanAttributes[ATTR_HTTP_REQUEST_METHOD],\n [ATTR_URL_SCHEME]: spanAttributes[ATTR_URL_SCHEME],\n };\n\n // recommended if and only if one was sent, same as span recommendation\n if (spanAttributes[ATTR_NETWORK_PROTOCOL_VERSION]) {\n metricAttributes[ATTR_NETWORK_PROTOCOL_VERSION] =\n spanAttributes[ATTR_NETWORK_PROTOCOL_VERSION];\n }\n\n const ctx = propagation.extract(ROOT_CONTEXT, headers);\n const span = instrumentation._startHttpSpan(method, spanOptions, ctx);\n const rpcMetadata: RPCMetadata = {\n type: RPCType.HTTP,\n span,\n };\n\n return context.with(\n setRPCMetadata(trace.setSpan(ctx, span), rpcMetadata),\n () => {\n context.bind(context.active(), request);\n context.bind(context.active(), response);\n\n if (instrumentation.getConfig().requestHook) {\n instrumentation._callRequestHook(span, request);\n }\n if (instrumentation.getConfig().responseHook) {\n instrumentation._callResponseHook(span, response);\n }\n\n // After 'error', no further events other than 'close' should be emitted.\n let hasError = false;\n response.on('close', () => {\n if (hasError) {\n return;\n }\n instrumentation._onServerResponseFinish(\n request,\n response,\n span,\n metricAttributes,\n startTime\n );\n });\n response.on(errorMonitor, (err: Err) => {\n hasError = true;\n instrumentation._onServerResponseError(\n span,\n metricAttributes,\n startTime,\n err\n );\n });\n\n return safeExecuteInTheMiddle(\n () => original.apply(this, [event, ...args]),\n error => {\n if (error) {\n instrumentation._onServerResponseError(\n span,\n metricAttributes,\n startTime,\n error\n );\n throw error;\n }\n }\n );\n }\n );\n };\n }\n\n private _outgoingRequestFunction(\n component: 'http' | 'https',\n original: Func<http.ClientRequest>\n ): Func<http.ClientRequest> {\n const instrumentation = this;\n return function outgoingRequest(\n this: unknown,\n options: url.URL | http.RequestOptions | string,\n ...args: unknown[]\n ): http.ClientRequest {\n if (!isValidOptionsType(options)) {\n return original.apply(this, [options, ...args]);\n }\n const extraOptions =\n typeof args[0] === 'object' &&\n (typeof options === 'string' || isURLLike(options))\n ? (args.shift() as http.RequestOptions)\n : undefined;\n const { method, invalidUrl, optionsParsed } = getRequestInfo(\n instrumentation._diag,\n options,\n extraOptions\n );\n\n if (\n safeExecuteInTheMiddle(\n () =>\n instrumentation\n .getConfig()\n .ignoreOutgoingRequestHook?.(optionsParsed),\n (e: unknown) => {\n if (e != null) {\n instrumentation._diag.error(\n 'caught ignoreOutgoingRequestHook error: ',\n e\n );\n }\n },\n true\n )\n ) {\n return original.apply(this, [optionsParsed, ...args]);\n }\n\n const { hostname, port } = extractHostnameAndPort(optionsParsed);\n const attributes = getOutgoingRequestAttributes(\n optionsParsed,\n {\n component,\n port,\n hostname,\n hookAttributes: instrumentation._callStartSpanHook(\n optionsParsed,\n instrumentation.getConfig().startOutgoingSpanHook\n ),\n redactedQueryParams: instrumentation.getConfig().redactedQueryParams, // Added config for adding custom query strings\n },\n instrumentation.getConfig().enableSyntheticSourceDetection || false\n );\n\n const startTime = hrTime();\n\n // request method, server address, and server port are both required span attributes\n const metricAttributes: Attributes = {\n [ATTR_HTTP_REQUEST_METHOD]: attributes[ATTR_HTTP_REQUEST_METHOD],\n [ATTR_SERVER_ADDRESS]: attributes[ATTR_SERVER_ADDRESS],\n [ATTR_SERVER_PORT]: attributes[ATTR_SERVER_PORT],\n };\n\n // required if and only if one was sent, same as span requirement\n if (attributes[ATTR_HTTP_RESPONSE_STATUS_CODE]) {\n metricAttributes[ATTR_HTTP_RESPONSE_STATUS_CODE] =\n attributes[ATTR_HTTP_RESPONSE_STATUS_CODE];\n }\n\n // recommended if and only if one was sent, same as span recommendation\n if (attributes[ATTR_NETWORK_PROTOCOL_VERSION]) {\n metricAttributes[ATTR_NETWORK_PROTOCOL_VERSION] =\n attributes[ATTR_NETWORK_PROTOCOL_VERSION];\n }\n\n const spanOptions: SpanOptions = {\n kind: SpanKind.CLIENT,\n attributes,\n };\n const span = instrumentation._startHttpSpan(method, spanOptions);\n\n const parentContext = context.active();\n const requestContext = trace.setSpan(parentContext, span);\n\n if (!optionsParsed.headers) {\n optionsParsed.headers = {};\n } else {\n // Make a copy of the headers object to avoid mutating an object the\n // caller might have a reference to.\n optionsParsed.headers = Object.assign({}, optionsParsed.headers);\n }\n propagation.inject(requestContext, optionsParsed.headers);\n\n return context.with(requestContext, () => {\n /*\n * The response callback is registered before ClientRequest is bound,\n * thus it is needed to bind it before the function call.\n */\n const cb = args[args.length - 1];\n if (typeof cb === 'function') {\n args[args.length - 1] = context.bind(parentContext, cb);\n }\n\n const request: http.ClientRequest = safeExecuteInTheMiddle(\n () => {\n if (invalidUrl) {\n // we know that the url is invalid, there's no point in injecting context as it will fail validation.\n // Passing in what the user provided will give the user an error that matches what they'd see without\n // the instrumentation.\n return original.apply(this, [options, ...args]);\n } else {\n return original.apply(this, [optionsParsed, ...args]);\n }\n },\n error => {\n if (error) {\n instrumentation._onOutgoingRequestError(\n span,\n metricAttributes,\n startTime,\n error\n );\n throw error;\n }\n }\n );\n\n instrumentation._diag.debug(\n `${component} instrumentation outgoingRequest`\n );\n context.bind(parentContext, request);\n return instrumentation._traceClientRequest(\n request,\n span,\n startTime,\n metricAttributes\n );\n });\n };\n }\n\n private _onServerResponseFinish(\n request: http.IncomingMessage,\n response: http.ServerResponse,\n span: Span,\n metricAttributes: Attributes,\n startTime: HrTime\n ) {\n const attributes = getIncomingRequestAttributesOnResponse(response);\n metricAttributes = Object.assign(\n metricAttributes,\n getIncomingStableRequestMetricAttributesOnResponse(attributes)\n );\n\n span.setAttributes(\n this._headerCapture.server.captureResponseHeaders(header =>\n response.getHeader(header)\n )\n );\n\n span.setAttributes(attributes).setStatus({\n code: parseResponseStatus(SpanKind.SERVER, response.statusCode),\n });\n\n const errorType = parseErrorType(SpanKind.SERVER, response.statusCode);\n if (errorType !== undefined) {\n span.setAttribute(ATTR_ERROR_TYPE, errorType);\n }\n\n const route = attributes[ATTR_HTTP_ROUTE];\n if (route) {\n span.updateName(`${request.method || 'GET'} ${route}`);\n }\n\n if (this.getConfig().applyCustomAttributesOnSpan) {\n safeExecuteInTheMiddle(\n () =>\n this.getConfig().applyCustomAttributesOnSpan!(\n span,\n request,\n response\n ),\n () => {},\n true\n );\n }\n\n this._closeHttpSpan(span, SpanKind.SERVER, startTime, metricAttributes);\n }\n\n private _onOutgoingRequestError(\n span: Span,\n metricAttributes: Attributes,\n startTime: HrTime,\n error: Err\n ) {\n setSpanWithError(span, error);\n metricAttributes[ATTR_ERROR_TYPE] = error.name;\n\n this._closeHttpSpan(span, SpanKind.CLIENT, startTime, metricAttributes);\n }\n\n private _onServerResponseError(\n span: Span,\n metricAttributes: Attributes,\n startTime: HrTime,\n error: Err\n ) {\n setSpanWithError(span, error);\n metricAttributes[ATTR_ERROR_TYPE] = error.name;\n\n this._closeHttpSpan(span, SpanKind.SERVER, startTime, metricAttributes);\n }\n\n private _startHttpSpan(\n name: string,\n options: SpanOptions,\n ctx = context.active()\n ) {\n /*\n * If a parent is required but not present, we use a `NoopSpan` to still\n * propagate context without recording it.\n */\n const requireParent =\n options.kind === SpanKind.CLIENT\n ? this.getConfig().requireParentforOutgoingSpans\n : this.getConfig().requireParentforIncomingSpans;\n\n let span: Span;\n const currentSpan = trace.getSpan(ctx);\n\n if (\n requireParent === true &&\n (!currentSpan || !trace.isSpanContextValid(currentSpan.spanContext()))\n ) {\n span = trace.wrapSpanContext(INVALID_SPAN_CONTEXT);\n } else if (requireParent === true && currentSpan?.spanContext().isRemote) {\n span = currentSpan;\n } else {\n span = this.tracer.startSpan(name, options, ctx);\n }\n this._spanNotEnded.add(span);\n return span;\n }\n\n private _closeHttpSpan(\n span: Span,\n spanKind: SpanKind,\n startTime: HrTime,\n metricAttributes: Attributes\n ) {\n if (!this._spanNotEnded.has(span)) {\n return;\n }\n\n span.end();\n this._spanNotEnded.delete(span);\n\n // Record metrics\n const duration = hrTimeToMilliseconds(hrTimeDuration(startTime, hrTime()));\n if (spanKind === SpanKind.SERVER) {\n this._recordServerDuration(duration, metricAttributes);\n } else if (spanKind === SpanKind.CLIENT) {\n this._recordClientDuration(duration, metricAttributes);\n }\n }\n\n private _callResponseHook(\n span: Span,\n response: http.IncomingMessage | http.ServerResponse\n ) {\n safeExecuteInTheMiddle(\n () => this.getConfig().responseHook!(span, response),\n () => {},\n true\n );\n }\n\n private _callRequestHook(\n span: Span,\n request: http.ClientRequest | http.IncomingMessage\n ) {\n safeExecuteInTheMiddle(\n () => this.getConfig().requestHook!(span, request),\n () => {},\n true\n );\n }\n\n private _callStartSpanHook(\n request: http.IncomingMessage | http.RequestOptions,\n hookFunc: Function | undefined\n ) {\n if (typeof hookFunc === 'function') {\n return safeExecuteInTheMiddle(\n () => hookFunc(request),\n () => {},\n true\n );\n }\n }\n\n private _createHeaderCapture() {\n const config = this.getConfig();\n\n return {\n client: {\n captureRequestHeaders: headerCapture(\n 'request',\n config.headersToSpanAttributes?.client?.requestHeaders ?? []\n ),\n captureResponseHeaders: headerCapture(\n 'response',\n config.headersToSpanAttributes?.client?.responseHeaders ?? []\n ),\n },\n server: {\n captureRequestHeaders: headerCapture(\n 'request',\n config.headersToSpanAttributes?.server?.requestHeaders ?? []\n ),\n captureResponseHeaders: headerCapture(\n 'response',\n config.headersToSpanAttributes?.server?.responseHeaders ?? []\n ),\n },\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;AA8EA,IAAa,sBAAb,cAAyC,oBAA+C;;CAEtF,gCAAgD,IAAI,QAAc;CAClE;CACA,eAAgC;CAChC,gBAAiC;CAIjC,YAAY,SAAoC,CAAC,GAAG;EAClD,MAAM,uCAAuC,SAAS,MAAM;EAC5D,KAAK,iBAAiB,KAAK,qBAAqB;CAClD;CAEA,2BAA8C;EAC5C,KAAK,+BAA+B,KAAK,MAAM,gBAC7C,qCACA;GACE,aAAa;GACb,MAAM;GACN,WAAW,UAAU;GACrB,QAAQ,EACN,0BAA0B;IACxB;IAAO;IAAM;IAAO;IAAM;IAAO;IAAK;IAAM;IAAK;IAAM;IAAG;IAAK;IAC/D;IAAK;GACP,EACF;EACF,CACF;EACA,KAAK,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AAkB,CAAC,CAC7D;IACA,wBAAwB,cACtB,YACA,OAAO,yBAAyB,QAAQ,mBAAmB,CAAC,CAC9D;GACF;GACA,QAAQ;IACN,uBAAuB,cACrB,WACA,OAAO,yBAAyB,QAAQ,kBAAkB,CAAC,CAC7D;IACA,wBAAwB,cACtB,YACA,OAAO,yBAAyB,QAAQ,mBAAmB,CAAC,CAC9D;GACF;EACF;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"http.mjs","names":[],"sources":["../src/http.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type {\n HrTime,\n Span,\n SpanOptions,\n SpanStatus,\n Histogram,\n Attributes,\n} from '@opentelemetry/api';\nimport {\n context,\n INVALID_SPAN_CONTEXT,\n propagation,\n ROOT_CONTEXT,\n SpanKind,\n SpanStatusCode,\n trace,\n ValueType,\n} from '@opentelemetry/api';\nimport type { ConfigProvider } from '@opentelemetry/api-config';\nimport type { RPCMetadata } from '@opentelemetry/core';\nimport {\n hrTime,\n hrTimeDuration,\n hrTimeToMilliseconds,\n suppressTracing,\n RPCType,\n setRPCMetadata,\n} from '@opentelemetry/core';\nimport type * as http from 'http';\nimport type * as https from 'https';\nimport type { Socket } from 'net';\nimport type * as url from 'url';\nimport type { HttpInstrumentationConfig } from './types';\nimport { VERSION } from './version';\nimport {\n InstrumentationBase,\n InstrumentationNodeModuleDefinition,\n safeExecuteInTheMiddle,\n readDeclarativeConfig,\n} from '@opentelemetry/instrumentation';\nimport { errorMonitor } from 'events';\nimport {\n ATTR_ERROR_TYPE,\n ATTR_HTTP_REQUEST_METHOD,\n ATTR_HTTP_RESPONSE_STATUS_CODE,\n ATTR_NETWORK_PROTOCOL_VERSION,\n ATTR_HTTP_ROUTE,\n ATTR_SERVER_ADDRESS,\n ATTR_SERVER_PORT,\n ATTR_URL_SCHEME,\n METRIC_HTTP_CLIENT_REQUEST_DURATION,\n METRIC_HTTP_SERVER_REQUEST_DURATION,\n} from '@opentelemetry/semantic-conventions';\nimport {\n extractHostnameAndPort,\n getIncomingRequestAttributes,\n getIncomingRequestAttributesOnResponse,\n getIncomingStableRequestMetricAttributesOnResponse,\n getOutgoingRequestAttributes,\n getOutgoingRequestAttributesOnResponse,\n getOutgoingStableRequestMetricAttributesOnResponse,\n getRequestInfo,\n isURLLike,\n headerCapture,\n isValidOptionsType,\n parseErrorType,\n parseResponseStatus,\n setSpanWithError,\n} from './utils';\nimport type { Err, Func, Http, HttpRequestArgs, Https } from './internal-types';\nimport { DEFAULT_QUERY_STRINGS_TO_REDACT } from './internal-types';\n\n/**\n * `node:http` and `node:https` instrumentation for OpenTelemetry\n */\nexport class HttpInstrumentation extends InstrumentationBase<HttpInstrumentationConfig> {\n /** keep track on spans not ended */\n private readonly _spanNotEnded: WeakSet<Span> = new WeakSet<Span>();\n private _headerCapture;\n private _httpPatched: boolean = false;\n private _httpsPatched: boolean = false;\n declare private _httpServerDurationHistogram: Histogram;\n declare private _httpClientDurationHistogram: Histogram;\n\n constructor(config: HttpInstrumentationConfig = {}) {\n super('@opentelemetry/instrumentation-http', VERSION, config);\n\n this._headerCapture = this._createHeaderCapture();\n }\n\n protected override _updateMetricInstruments() {\n this._httpServerDurationHistogram = this.meter.createHistogram(\n METRIC_HTTP_SERVER_REQUEST_DURATION,\n {\n description: 'Duration of HTTP server requests.',\n unit: 's',\n valueType: ValueType.DOUBLE,\n advice: {\n explicitBucketBoundaries: [\n 0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1, 2.5, 5,\n 7.5, 10,\n ],\n },\n }\n );\n this._httpClientDurationHistogram = this.meter.createHistogram(\n METRIC_HTTP_CLIENT_REQUEST_DURATION,\n {\n description: 'Duration of HTTP client requests.',\n unit: 's',\n valueType: ValueType.DOUBLE,\n advice: {\n explicitBucketBoundaries: [\n 0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1, 2.5, 5,\n 7.5, 10,\n ],\n },\n }\n );\n }\n\n private _recordServerDuration(durationMs: number, attributes: Attributes) {\n // stable histogram is counted in S\n this._httpServerDurationHistogram.record(durationMs / 1000, attributes);\n }\n\n private _recordClientDuration(durationMs: number, attributes: Attributes) {\n // stable histogram is counted in S\n this._httpClientDurationHistogram.record(durationMs / 1000, attributes);\n }\n\n override setConfig(config: HttpInstrumentationConfig = {}): void {\n super.setConfig(config);\n this._headerCapture = this._createHeaderCapture();\n }\n\n /**\n * Update the current config (rather than fully *replace* it), with any\n * settings from declarative config. See the \"Declarative Configuration\"\n * section of the README for the properties this instrumentation supports.\n */\n setConfigProvider(configProvider: ConfigProvider): void {\n const config = readDeclarativeConfig({\n configProvider,\n instrumentationName: this.instrumentationName,\n // instrumentation-http owns the `general.http` domain.\n generalDomains: ['http'],\n currentConfig: this.getConfig() as Record<string, unknown>,\n diag: this._diag,\n reader: (own, general): Partial<HttpInstrumentationConfig> => ({\n disableIncomingRequestInstrumentation: own.getBoolean(\n 'disable_incoming_request_instrumentation'\n ),\n disableOutgoingRequestInstrumentation: own.getBoolean(\n 'disable_outgoing_request_instrumentation'\n ),\n requireParentforIncomingSpans: own.getBoolean(\n 'require_parent_for_incoming_spans'\n ),\n requireParentforOutgoingSpans: own.getBoolean(\n 'require_parent_for_outgoing_spans'\n ),\n redactedQueryParams: own.getStringArray('redacted_query_params'),\n enableSyntheticSourceDetection: own.getBoolean(\n 'enable_synthetic_source_detection'\n ),\n headersToSpanAttributes: {\n client: {\n requestHeaders: general.getStringArray(\n 'http.client.request_captured_headers'\n ),\n responseHeaders: general.getStringArray(\n 'http.client.response_captured_headers'\n ),\n },\n server: {\n requestHeaders: general.getStringArray(\n 'http.server.request_captured_headers'\n ),\n responseHeaders: general.getStringArray(\n 'http.server.response_captured_headers'\n ),\n },\n },\n }),\n });\n\n if (Object.keys(config).length > 0) {\n this.setConfig({ ...this.getConfig(), ...config });\n }\n }\n\n init(): [\n InstrumentationNodeModuleDefinition,\n InstrumentationNodeModuleDefinition,\n ] {\n return [this._getHttpsInstrumentation(), this._getHttpInstrumentation()];\n }\n\n private _getHttpInstrumentation() {\n return new InstrumentationNodeModuleDefinition(\n 'http',\n ['*'],\n (moduleExports: Http): Http => {\n // Guard against double-instrumentation, if loaded by both `require`\n // and `import`.\n if (this._httpPatched) {\n return moduleExports;\n }\n this._httpPatched = true;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const isESM = (moduleExports as any)[Symbol.toStringTag] === 'Module';\n\n if (!this.getConfig().disableOutgoingRequestInstrumentation) {\n const patchedRequest = this._wrap(\n moduleExports,\n 'request',\n this._getPatchOutgoingRequestFunction('http')\n ) as unknown as Func<http.ClientRequest>;\n const patchedGet = this._wrap(\n moduleExports,\n 'get',\n this._getPatchOutgoingGetFunction(patchedRequest)\n );\n if (isESM) {\n // To handle `import http from 'http'`, which returns the default\n // export, we need to set `module.default.*`.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (moduleExports as any).default.request = patchedRequest;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (moduleExports as any).default.get = patchedGet;\n }\n }\n if (!this.getConfig().disableIncomingRequestInstrumentation) {\n this._wrap(\n moduleExports.Server.prototype,\n 'emit',\n this._getPatchIncomingRequestFunction('http')\n );\n }\n return moduleExports;\n },\n (moduleExports: Http) => {\n this._httpPatched = false;\n if (moduleExports === undefined) return;\n\n if (!this.getConfig().disableOutgoingRequestInstrumentation) {\n this._unwrap(moduleExports, 'request');\n this._unwrap(moduleExports, 'get');\n }\n if (!this.getConfig().disableIncomingRequestInstrumentation) {\n this._unwrap(moduleExports.Server.prototype, 'emit');\n }\n }\n );\n }\n\n private _getHttpsInstrumentation() {\n return new InstrumentationNodeModuleDefinition(\n 'https',\n ['*'],\n (moduleExports: Https): Https => {\n // Guard against double-instrumentation, if loaded by both `require`\n // and `import`.\n if (this._httpsPatched) {\n return moduleExports;\n }\n this._httpsPatched = true;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const isESM = (moduleExports as any)[Symbol.toStringTag] === 'Module';\n\n if (!this.getConfig().disableOutgoingRequestInstrumentation) {\n const patchedRequest = this._wrap(\n moduleExports,\n 'request',\n this._getPatchHttpsOutgoingRequestFunction('https')\n ) as unknown as Func<http.ClientRequest>;\n const patchedGet = this._wrap(\n moduleExports,\n 'get',\n this._getPatchHttpsOutgoingGetFunction(patchedRequest)\n );\n if (isESM) {\n // To handle `import https from 'https'`, which returns the default\n // export, we need to set `module.default.*`.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (moduleExports as any).default.request = patchedRequest;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (moduleExports as any).default.get = patchedGet;\n }\n }\n if (!this.getConfig().disableIncomingRequestInstrumentation) {\n this._wrap(\n moduleExports.Server.prototype,\n 'emit',\n this._getPatchIncomingRequestFunction('https')\n );\n }\n return moduleExports;\n },\n (moduleExports: Https) => {\n this._httpsPatched = false;\n if (moduleExports === undefined) return;\n\n if (!this.getConfig().disableOutgoingRequestInstrumentation) {\n this._unwrap(moduleExports, 'request');\n this._unwrap(moduleExports, 'get');\n }\n if (!this.getConfig().disableIncomingRequestInstrumentation) {\n this._unwrap(moduleExports.Server.prototype, 'emit');\n }\n }\n );\n }\n\n /**\n * Creates spans for incoming requests, restoring spans' context if applied.\n */\n private _getPatchIncomingRequestFunction(component: 'http' | 'https') {\n return (\n original: (event: string, ...args: unknown[]) => boolean\n ): ((this: unknown, event: string, ...args: unknown[]) => boolean) => {\n return this._incomingRequestFunction(component, original);\n };\n }\n\n /**\n * Creates spans for outgoing requests, sending spans' context for distributed\n * tracing.\n */\n private _getPatchOutgoingRequestFunction(component: 'http' | 'https') {\n return (original: Func<http.ClientRequest>): Func<http.ClientRequest> => {\n return this._outgoingRequestFunction(component, original);\n };\n }\n\n private _getPatchOutgoingGetFunction(\n clientRequest: (\n options: http.RequestOptions | string | url.URL,\n ...args: HttpRequestArgs\n ) => http.ClientRequest\n ) {\n return (_original: Func<http.ClientRequest>): Func<http.ClientRequest> => {\n // Re-implement http.get. This needs to be done (instead of using\n // getPatchOutgoingRequestFunction to patch it) because we need to\n // set the trace context header before the returned http.ClientRequest is\n // ended. The Node.js docs state that the only differences between\n // request and get are that (1) get defaults to the HTTP GET method and\n // (2) the returned request object is ended immediately. The former is\n // already true (at least in supported Node versions up to v10), so we\n // simply follow the latter. Ref:\n // https://nodejs.org/dist/latest/docs/api/http.html#http_http_get_options_callback\n // https://github.com/googleapis/cloud-trace-nodejs/blob/master/src/instrumentations/instrumentation-http.ts#L198\n return function outgoingGetRequest<\n T extends http.RequestOptions | string | url.URL,\n >(options: T, ...args: HttpRequestArgs): http.ClientRequest {\n const req = clientRequest(options, ...args);\n req.end();\n return req;\n };\n };\n }\n\n /** Patches HTTPS outgoing requests */\n private _getPatchHttpsOutgoingRequestFunction(component: 'http' | 'https') {\n return (original: Func<http.ClientRequest>): Func<http.ClientRequest> => {\n const instrumentation = this;\n return function httpsOutgoingRequest(\n options: https.RequestOptions | string | URL,\n ...args: HttpRequestArgs\n ): http.ClientRequest {\n // Makes sure options will have default HTTPS parameters\n if (\n component === 'https' &&\n typeof options === 'object' &&\n options?.constructor?.name !== 'URL'\n ) {\n options = Object.assign({}, options);\n instrumentation._setDefaultOptions(options);\n }\n return instrumentation._getPatchOutgoingRequestFunction(component)(\n original\n )(options, ...args);\n };\n };\n }\n\n private _setDefaultOptions(options: https.RequestOptions) {\n options.protocol = options.protocol || 'https:';\n options.port = options.port || 443;\n }\n\n /** Patches HTTPS outgoing get requests */\n private _getPatchHttpsOutgoingGetFunction(\n clientRequest: (\n options: http.RequestOptions | string | URL,\n ...args: HttpRequestArgs\n ) => http.ClientRequest\n ) {\n return (original: Func<http.ClientRequest>): Func<http.ClientRequest> => {\n const instrumentation = this;\n return function httpsOutgoingRequest(\n options: https.RequestOptions | string | URL,\n ...args: HttpRequestArgs\n ): http.ClientRequest {\n return instrumentation._getPatchOutgoingGetFunction(clientRequest)(\n original\n )(options, ...args);\n };\n };\n }\n\n /**\n * Attach event listeners to a client request to end span and add span attributes.\n *\n * @param request The original request object.\n * @param span representing the current operation\n * @param startTime representing the start time of the request to calculate duration in Metric\n * @param metricAttributes metric attributes for the request duration metric\n */\n private _traceClientRequest(\n request: http.ClientRequest,\n span: Span,\n startTime: HrTime,\n metricAttributes: Attributes\n ): http.ClientRequest {\n if (this.getConfig().requestHook) {\n this._callRequestHook(span, request);\n }\n\n /**\n * Determines if the request has errored or the response has ended/errored.\n */\n let responseFinished = false;\n\n /*\n * User 'response' event listeners can be added before our listener,\n * force our listener to be the first, so response emitter is bound\n * before any user listeners are added to it.\n */\n request.prependListener(\n 'response',\n (response: http.IncomingMessage & { aborted?: boolean }) => {\n this._diag.debug('outgoingRequest on response()');\n if (request.listenerCount('response') <= 1) {\n response.resume();\n }\n const responseAttributes =\n getOutgoingRequestAttributesOnResponse(response);\n span.setAttributes(responseAttributes);\n metricAttributes = Object.assign(\n metricAttributes,\n getOutgoingStableRequestMetricAttributesOnResponse(responseAttributes)\n );\n\n if (this.getConfig().responseHook) {\n this._callResponseHook(span, response);\n }\n\n span.setAttributes(\n this._headerCapture.client.captureRequestHeaders(header =>\n request.getHeader(header)\n )\n );\n span.setAttributes(\n this._headerCapture.client.captureResponseHeaders(\n header => response.headers[header]\n )\n );\n\n context.bind(context.active(), response);\n\n const endHandler = () => {\n this._diag.debug('outgoingRequest on end()');\n if (responseFinished) {\n return;\n }\n responseFinished = true;\n let status: SpanStatus;\n\n if (response.aborted && !response.complete) {\n status = { code: SpanStatusCode.ERROR };\n } else {\n // behaves same for new and old semconv\n status = {\n code: parseResponseStatus(SpanKind.CLIENT, response.statusCode),\n };\n const errorType = parseErrorType(\n SpanKind.CLIENT,\n response.statusCode\n );\n if (errorType !== undefined) {\n span.setAttribute(ATTR_ERROR_TYPE, errorType);\n }\n }\n\n span.setStatus(status);\n\n if (this.getConfig().applyCustomAttributesOnSpan) {\n safeExecuteInTheMiddle(\n () =>\n this.getConfig().applyCustomAttributesOnSpan!(\n span,\n request,\n response\n ),\n () => {},\n true\n );\n }\n\n this._closeHttpSpan(\n span,\n SpanKind.CLIENT,\n startTime,\n metricAttributes\n );\n };\n\n response.on('end', endHandler);\n response.on(errorMonitor, (error: Err) => {\n this._diag.debug('outgoingRequest on error()', error);\n if (responseFinished) {\n return;\n }\n responseFinished = true;\n this._onOutgoingRequestError(\n span,\n metricAttributes,\n startTime,\n error\n );\n });\n }\n );\n request.on('close', () => {\n this._diag.debug('outgoingRequest on request close()');\n if (request.aborted || responseFinished) {\n return;\n }\n responseFinished = true;\n this._closeHttpSpan(span, SpanKind.CLIENT, startTime, metricAttributes);\n });\n request.on(errorMonitor, (error: Err) => {\n this._diag.debug('outgoingRequest on request error()', error);\n if (responseFinished) {\n return;\n }\n responseFinished = true;\n this._onOutgoingRequestError(span, metricAttributes, startTime, error);\n });\n\n this._diag.debug('http.ClientRequest return request');\n return request;\n }\n\n private _incomingRequestFunction(\n component: 'http' | 'https',\n original: (event: string, ...args: unknown[]) => boolean\n ) {\n const instrumentation = this;\n return function incomingRequest(\n this: unknown,\n event: string,\n ...args: unknown[]\n ): boolean {\n // Only traces request events\n if (event !== 'request') {\n return original.apply(this, [event, ...args]);\n }\n\n const request = args[0] as http.IncomingMessage;\n const response = args[1] as http.ServerResponse & { socket: Socket };\n const method = request.method || 'GET';\n\n instrumentation._diag.debug(\n `${component} instrumentation incomingRequest`\n );\n\n if (\n safeExecuteInTheMiddle(\n () =>\n instrumentation.getConfig().ignoreIncomingRequestHook?.(request),\n (e: unknown) => {\n if (e != null) {\n instrumentation._diag.error(\n 'caught ignoreIncomingRequestHook error: ',\n e\n );\n }\n },\n true\n )\n ) {\n return context.with(suppressTracing(context.active()), () => {\n context.bind(context.active(), request);\n context.bind(context.active(), response);\n return original.apply(this, [event, ...args]);\n });\n }\n\n const headers = request.headers;\n\n const spanAttributes = getIncomingRequestAttributes(\n request,\n {\n component: component,\n hookAttributes: instrumentation._callStartSpanHook(\n request,\n instrumentation.getConfig().startIncomingSpanHook\n ),\n enableSyntheticSourceDetection:\n instrumentation.getConfig().enableSyntheticSourceDetection || false,\n redactedQueryParams:\n instrumentation.getConfig().redactedQueryParamsServer ??\n Array.from(DEFAULT_QUERY_STRINGS_TO_REDACT),\n },\n instrumentation._diag\n );\n\n Object.assign(\n spanAttributes,\n instrumentation._headerCapture.server.captureRequestHeaders(\n header => request.headers[header]\n )\n );\n\n const spanOptions: SpanOptions = {\n kind: SpanKind.SERVER,\n attributes: spanAttributes,\n };\n\n const startTime = hrTime();\n\n // request method and url.scheme are both required span attributes\n const metricAttributes: Attributes = {\n [ATTR_HTTP_REQUEST_METHOD]: spanAttributes[ATTR_HTTP_REQUEST_METHOD],\n [ATTR_URL_SCHEME]: spanAttributes[ATTR_URL_SCHEME],\n };\n\n // recommended if and only if one was sent, same as span recommendation\n if (spanAttributes[ATTR_NETWORK_PROTOCOL_VERSION]) {\n metricAttributes[ATTR_NETWORK_PROTOCOL_VERSION] =\n spanAttributes[ATTR_NETWORK_PROTOCOL_VERSION];\n }\n\n const ctx = propagation.extract(ROOT_CONTEXT, headers);\n const span = instrumentation._startHttpSpan(method, spanOptions, ctx);\n const rpcMetadata: RPCMetadata = {\n type: RPCType.HTTP,\n span,\n };\n\n return context.with(\n setRPCMetadata(trace.setSpan(ctx, span), rpcMetadata),\n () => {\n context.bind(context.active(), request);\n context.bind(context.active(), response);\n\n if (instrumentation.getConfig().requestHook) {\n instrumentation._callRequestHook(span, request);\n }\n if (instrumentation.getConfig().responseHook) {\n instrumentation._callResponseHook(span, response);\n }\n\n // After 'error', no further events other than 'close' should be emitted.\n let hasError = false;\n response.on('close', () => {\n if (hasError) {\n return;\n }\n instrumentation._onServerResponseFinish(\n request,\n response,\n span,\n metricAttributes,\n startTime\n );\n });\n response.on(errorMonitor, (err: Err) => {\n hasError = true;\n instrumentation._onServerResponseError(\n span,\n metricAttributes,\n startTime,\n err\n );\n });\n\n return safeExecuteInTheMiddle(\n () => original.apply(this, [event, ...args]),\n error => {\n if (error) {\n instrumentation._onServerResponseError(\n span,\n metricAttributes,\n startTime,\n error\n );\n throw error;\n }\n }\n );\n }\n );\n };\n }\n\n private _outgoingRequestFunction(\n component: 'http' | 'https',\n original: Func<http.ClientRequest>\n ): Func<http.ClientRequest> {\n const instrumentation = this;\n return function outgoingRequest(\n this: unknown,\n options: url.URL | http.RequestOptions | string,\n ...args: unknown[]\n ): http.ClientRequest {\n if (!isValidOptionsType(options)) {\n return original.apply(this, [options, ...args]);\n }\n const extraOptions =\n typeof args[0] === 'object' &&\n (typeof options === 'string' || isURLLike(options))\n ? (args.shift() as http.RequestOptions)\n : undefined;\n const { method, invalidUrl, optionsParsed } = getRequestInfo(\n instrumentation._diag,\n options,\n extraOptions\n );\n\n if (\n safeExecuteInTheMiddle(\n () =>\n instrumentation\n .getConfig()\n .ignoreOutgoingRequestHook?.(optionsParsed),\n (e: unknown) => {\n if (e != null) {\n instrumentation._diag.error(\n 'caught ignoreOutgoingRequestHook error: ',\n e\n );\n }\n },\n true\n )\n ) {\n return original.apply(this, [optionsParsed, ...args]);\n }\n\n const { hostname, port } = extractHostnameAndPort(optionsParsed);\n const attributes = getOutgoingRequestAttributes(\n optionsParsed,\n {\n component,\n port,\n hostname,\n hookAttributes: instrumentation._callStartSpanHook(\n optionsParsed,\n instrumentation.getConfig().startOutgoingSpanHook\n ),\n redactedQueryParams: instrumentation.getConfig().redactedQueryParams, // Added config for adding custom query strings\n },\n instrumentation.getConfig().enableSyntheticSourceDetection || false\n );\n\n const startTime = hrTime();\n\n // request method, server address, and server port are both required span attributes\n const metricAttributes: Attributes = {\n [ATTR_HTTP_REQUEST_METHOD]: attributes[ATTR_HTTP_REQUEST_METHOD],\n [ATTR_SERVER_ADDRESS]: attributes[ATTR_SERVER_ADDRESS],\n [ATTR_SERVER_PORT]: attributes[ATTR_SERVER_PORT],\n };\n\n // required if and only if one was sent, same as span requirement\n if (attributes[ATTR_HTTP_RESPONSE_STATUS_CODE]) {\n metricAttributes[ATTR_HTTP_RESPONSE_STATUS_CODE] =\n attributes[ATTR_HTTP_RESPONSE_STATUS_CODE];\n }\n\n // recommended if and only if one was sent, same as span recommendation\n if (attributes[ATTR_NETWORK_PROTOCOL_VERSION]) {\n metricAttributes[ATTR_NETWORK_PROTOCOL_VERSION] =\n attributes[ATTR_NETWORK_PROTOCOL_VERSION];\n }\n\n const spanOptions: SpanOptions = {\n kind: SpanKind.CLIENT,\n attributes,\n };\n const span = instrumentation._startHttpSpan(method, spanOptions);\n\n const parentContext = context.active();\n const requestContext = trace.setSpan(parentContext, span);\n\n if (!optionsParsed.headers) {\n optionsParsed.headers = {};\n } else {\n // Make a copy of the headers object to avoid mutating an object the\n // caller might have a reference to.\n optionsParsed.headers = Object.assign({}, optionsParsed.headers);\n }\n propagation.inject(requestContext, optionsParsed.headers);\n\n return context.with(requestContext, () => {\n /*\n * The response callback is registered before ClientRequest is bound,\n * thus it is needed to bind it before the function call.\n */\n const cb = args[args.length - 1];\n if (typeof cb === 'function') {\n args[args.length - 1] = context.bind(parentContext, cb);\n }\n\n const request: http.ClientRequest = safeExecuteInTheMiddle(\n () => {\n if (invalidUrl) {\n // we know that the url is invalid, there's no point in injecting context as it will fail validation.\n // Passing in what the user provided will give the user an error that matches what they'd see without\n // the instrumentation.\n return original.apply(this, [options, ...args]);\n } else {\n return original.apply(this, [optionsParsed, ...args]);\n }\n },\n error => {\n if (error) {\n instrumentation._onOutgoingRequestError(\n span,\n metricAttributes,\n startTime,\n error\n );\n throw error;\n }\n }\n );\n\n instrumentation._diag.debug(\n `${component} instrumentation outgoingRequest`\n );\n context.bind(parentContext, request);\n return instrumentation._traceClientRequest(\n request,\n span,\n startTime,\n metricAttributes\n );\n });\n };\n }\n\n private _onServerResponseFinish(\n request: http.IncomingMessage,\n response: http.ServerResponse,\n span: Span,\n metricAttributes: Attributes,\n startTime: HrTime\n ) {\n const attributes = getIncomingRequestAttributesOnResponse(response);\n metricAttributes = Object.assign(\n metricAttributes,\n getIncomingStableRequestMetricAttributesOnResponse(attributes)\n );\n\n span.setAttributes(\n this._headerCapture.server.captureResponseHeaders(header =>\n response.getHeader(header)\n )\n );\n\n span.setAttributes(attributes).setStatus({\n code: parseResponseStatus(SpanKind.SERVER, response.statusCode),\n });\n\n const errorType = parseErrorType(SpanKind.SERVER, response.statusCode);\n if (errorType !== undefined) {\n span.setAttribute(ATTR_ERROR_TYPE, errorType);\n }\n\n const route = attributes[ATTR_HTTP_ROUTE];\n if (route) {\n span.updateName(`${request.method || 'GET'} ${route}`);\n }\n\n if (this.getConfig().applyCustomAttributesOnSpan) {\n safeExecuteInTheMiddle(\n () =>\n this.getConfig().applyCustomAttributesOnSpan!(\n span,\n request,\n response\n ),\n () => {},\n true\n );\n }\n\n this._closeHttpSpan(span, SpanKind.SERVER, startTime, metricAttributes);\n }\n\n private _onOutgoingRequestError(\n span: Span,\n metricAttributes: Attributes,\n startTime: HrTime,\n error: Err\n ) {\n setSpanWithError(span, error);\n metricAttributes[ATTR_ERROR_TYPE] = error.name;\n\n this._closeHttpSpan(span, SpanKind.CLIENT, startTime, metricAttributes);\n }\n\n private _onServerResponseError(\n span: Span,\n metricAttributes: Attributes,\n startTime: HrTime,\n error: Err\n ) {\n setSpanWithError(span, error);\n metricAttributes[ATTR_ERROR_TYPE] = error.name;\n\n this._closeHttpSpan(span, SpanKind.SERVER, startTime, metricAttributes);\n }\n\n private _startHttpSpan(\n name: string,\n options: SpanOptions,\n ctx = context.active()\n ) {\n /*\n * If a parent is required but not present, we use a `NoopSpan` to still\n * propagate context without recording it.\n */\n const requireParent =\n options.kind === SpanKind.CLIENT\n ? this.getConfig().requireParentforOutgoingSpans\n : this.getConfig().requireParentforIncomingSpans;\n\n let span: Span;\n const currentSpan = trace.getSpan(ctx);\n\n if (\n requireParent === true &&\n (!currentSpan || !trace.isSpanContextValid(currentSpan.spanContext()))\n ) {\n span = trace.wrapSpanContext(INVALID_SPAN_CONTEXT);\n } else if (requireParent === true && currentSpan?.spanContext().isRemote) {\n span = currentSpan;\n } else {\n span = this.tracer.startSpan(name, options, ctx);\n }\n this._spanNotEnded.add(span);\n return span;\n }\n\n private _closeHttpSpan(\n span: Span,\n spanKind: SpanKind,\n startTime: HrTime,\n metricAttributes: Attributes\n ) {\n if (!this._spanNotEnded.has(span)) {\n return;\n }\n\n span.end();\n this._spanNotEnded.delete(span);\n\n // Record metrics\n const duration = hrTimeToMilliseconds(hrTimeDuration(startTime, hrTime()));\n if (spanKind === SpanKind.SERVER) {\n this._recordServerDuration(duration, metricAttributes);\n } else if (spanKind === SpanKind.CLIENT) {\n this._recordClientDuration(duration, metricAttributes);\n }\n }\n\n private _callResponseHook(\n span: Span,\n response: http.IncomingMessage | http.ServerResponse\n ) {\n safeExecuteInTheMiddle(\n () => this.getConfig().responseHook!(span, response),\n () => {},\n true\n );\n }\n\n private _callRequestHook(\n span: Span,\n request: http.ClientRequest | http.IncomingMessage\n ) {\n safeExecuteInTheMiddle(\n () => this.getConfig().requestHook!(span, request),\n () => {},\n true\n );\n }\n\n private _callStartSpanHook(\n request: http.IncomingMessage | http.RequestOptions,\n hookFunc: Function | undefined\n ) {\n if (typeof hookFunc === 'function') {\n return safeExecuteInTheMiddle(\n () => hookFunc(request),\n () => {},\n true\n );\n }\n }\n\n private _createHeaderCapture() {\n const config = this.getConfig();\n\n return {\n client: {\n captureRequestHeaders: headerCapture(\n 'request',\n config.headersToSpanAttributes?.client?.requestHeaders ?? []\n ),\n captureResponseHeaders: headerCapture(\n 'response',\n config.headersToSpanAttributes?.client?.responseHeaders ?? []\n ),\n },\n server: {\n captureRequestHeaders: headerCapture(\n 'request',\n config.headersToSpanAttributes?.server?.requestHeaders ?? []\n ),\n captureResponseHeaders: headerCapture(\n 'response',\n config.headersToSpanAttributes?.server?.responseHeaders ?? []\n ),\n },\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;AAgFA,IAAa,sBAAb,cAAyC,oBAA+C;;CAErE,gCAA+B,IAAI,QAAc;CAC1D;CACA,eAAwB;CACxB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AC,CAC7D;IACA,wBAAwB,cACtB,YACA,OAAO,yBAAyB,QAAQ,mBAAmB,CAAC,CAC9D;GACF;EACF;CACF;AACF"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { HttpCustomAttributeFunction, HttpInstrumentationConfig, HttpRequestCustomAttributeFunction, HttpResponseCustomAttributeFunction, IgnoreIncomingRequestFunction, IgnoreOutgoingRequestFunction, StartIncomingSpanCustomAttributeFunction, StartOutgoingSpanCustomAttributeFunction } from "./types.cjs";
|
|
2
1
|
import { HttpInstrumentation } from "./http.cjs";
|
|
2
|
+
import { HttpCustomAttributeFunction, HttpInstrumentationConfig, HttpRequestCustomAttributeFunction, HttpResponseCustomAttributeFunction, IgnoreIncomingRequestFunction, IgnoreOutgoingRequestFunction, StartIncomingSpanCustomAttributeFunction, StartOutgoingSpanCustomAttributeFunction } from "./types.cjs";
|
|
3
3
|
export { type HttpCustomAttributeFunction, HttpInstrumentation, type HttpInstrumentationConfig, type HttpRequestCustomAttributeFunction, type HttpResponseCustomAttributeFunction, type IgnoreIncomingRequestFunction, type IgnoreOutgoingRequestFunction, type StartIncomingSpanCustomAttributeFunction, type StartOutgoingSpanCustomAttributeFunction };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { HttpCustomAttributeFunction, HttpInstrumentationConfig, HttpRequestCustomAttributeFunction, HttpResponseCustomAttributeFunction, IgnoreIncomingRequestFunction, IgnoreOutgoingRequestFunction, StartIncomingSpanCustomAttributeFunction, StartOutgoingSpanCustomAttributeFunction } from "./types.mjs";
|
|
2
1
|
import { HttpInstrumentation } from "./http.mjs";
|
|
2
|
+
import { HttpCustomAttributeFunction, HttpInstrumentationConfig, HttpRequestCustomAttributeFunction, HttpResponseCustomAttributeFunction, IgnoreIncomingRequestFunction, IgnoreOutgoingRequestFunction, StartIncomingSpanCustomAttributeFunction, StartOutgoingSpanCustomAttributeFunction } from "./types.mjs";
|
|
3
3
|
export { type HttpCustomAttributeFunction, HttpInstrumentation, type HttpInstrumentationConfig, type HttpRequestCustomAttributeFunction, type HttpResponseCustomAttributeFunction, type IgnoreIncomingRequestFunction, type IgnoreOutgoingRequestFunction, type StartIncomingSpanCustomAttributeFunction, type StartOutgoingSpanCustomAttributeFunction };
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { HttpInstrumentation };
|
|
1
|
+
export { HttpInstrumentation } from "./http.mjs";
|
package/dist/internal-types.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/internal-types.ts
|
|
2
2
|
/**
|
|
3
3
|
* Names of possible synthetic test sources.
|
|
4
4
|
*/
|
|
@@ -23,7 +23,6 @@ const DEFAULT_QUERY_STRINGS_TO_REDACT = [
|
|
|
23
23
|
"X-Amz-Credential",
|
|
24
24
|
"X-Amz-Security-Token"
|
|
25
25
|
];
|
|
26
|
-
//#endregion
|
|
27
26
|
exports.DEFAULT_QUERY_STRINGS_TO_REDACT = DEFAULT_QUERY_STRINGS_TO_REDACT;
|
|
28
27
|
exports.STR_REDACTED = STR_REDACTED;
|
|
29
28
|
exports.SYNTHETIC_BOT_NAMES = SYNTHETIC_BOT_NAMES;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal-types.cjs","names":[],"sources":["../src/internal-types.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type * as http from 'http';\nimport type * as https from 'https';\nimport type { get, IncomingMessage, request } from 'http';\nimport type * as url from 'url';\n\nexport type IgnoreMatcher = string | RegExp | ((url: string) => boolean);\nexport type HttpCallback = (res: IncomingMessage) => void;\nexport type RequestFunction = typeof request;\nexport type GetFunction = typeof get;\n\nexport type HttpCallbackOptional = HttpCallback | undefined;\n\n// from node 10+\nexport type RequestSignature = [http.RequestOptions, HttpCallbackOptional] &\n HttpCallback;\n\nexport type HttpRequestArgs = Array<HttpCallbackOptional | RequestSignature>;\n\nexport type ParsedRequestOptions =\n
|
|
1
|
+
{"version":3,"file":"internal-types.cjs","names":[],"sources":["../src/internal-types.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type * as http from 'http';\nimport type * as https from 'https';\nimport type { get, IncomingMessage, request } from 'http';\nimport type * as url from 'url';\n\nexport type IgnoreMatcher = string | RegExp | ((url: string) => boolean);\nexport type HttpCallback = (res: IncomingMessage) => void;\nexport type RequestFunction = typeof request;\nexport type GetFunction = typeof get;\n\nexport type HttpCallbackOptional = HttpCallback | undefined;\n\n// from node 10+\nexport type RequestSignature = [http.RequestOptions, HttpCallbackOptional] &\n HttpCallback;\n\nexport type HttpRequestArgs = Array<HttpCallbackOptional | RequestSignature>;\n\nexport type ParsedRequestOptions =\n (http.RequestOptions & Partial<url.UrlWithParsedQuery>) | http.RequestOptions;\nexport type Http = typeof http;\nexport type Https = typeof https;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type Func<T> = (...args: any[]) => T;\n\nexport interface Err extends Error {\n errno?: number;\n code?: string;\n path?: string;\n syscall?: string;\n stack?: string;\n}\n\n/**\n * Names of possible synthetic test sources.\n */\nexport const SYNTHETIC_TEST_NAMES = ['alwayson'];\n\n/**\n * Names of possible synthetic bot sources.\n */\nexport const SYNTHETIC_BOT_NAMES = ['googlebot', 'bingbot'];\n\n/**\n * REDACTED string used to replace sensitive information in URLs.\n */\nexport const STR_REDACTED = 'REDACTED';\n\n/**\n * List of URL query keys that are considered sensitive and whose value should be redacted.\n */\nexport const DEFAULT_QUERY_STRINGS_TO_REDACT = [\n 'sig',\n 'Signature',\n 'AWSAccessKeyId',\n 'X-Goog-Signature',\n 'X-Amz-Signature',\n 'X-Amz-Credential',\n 'X-Amz-Security-Token',\n] as const;\n"],"mappings":";;;;AAyCA,MAAa,uBAAuB,CAAC,UAAU;;;;AAK/C,MAAa,sBAAsB,CAAC,aAAa,SAAS;;;;AAK1D,MAAa,eAAe;;;;AAK5B,MAAa,kCAAkC;CAC7C;CACA;CACA;CACA;CACA;CACA;CACA;AACF"}
|
package/dist/internal-types.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/internal-types.ts
|
|
2
2
|
/**
|
|
3
3
|
* Names of possible synthetic test sources.
|
|
4
4
|
*/
|
|
@@ -23,7 +23,6 @@ const DEFAULT_QUERY_STRINGS_TO_REDACT = [
|
|
|
23
23
|
"X-Amz-Credential",
|
|
24
24
|
"X-Amz-Security-Token"
|
|
25
25
|
];
|
|
26
|
-
//#endregion
|
|
27
26
|
export { DEFAULT_QUERY_STRINGS_TO_REDACT, STR_REDACTED, SYNTHETIC_BOT_NAMES, SYNTHETIC_TEST_NAMES };
|
|
28
27
|
|
|
29
28
|
//# sourceMappingURL=internal-types.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal-types.mjs","names":[],"sources":["../src/internal-types.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type * as http from 'http';\nimport type * as https from 'https';\nimport type { get, IncomingMessage, request } from 'http';\nimport type * as url from 'url';\n\nexport type IgnoreMatcher = string | RegExp | ((url: string) => boolean);\nexport type HttpCallback = (res: IncomingMessage) => void;\nexport type RequestFunction = typeof request;\nexport type GetFunction = typeof get;\n\nexport type HttpCallbackOptional = HttpCallback | undefined;\n\n// from node 10+\nexport type RequestSignature = [http.RequestOptions, HttpCallbackOptional] &\n HttpCallback;\n\nexport type HttpRequestArgs = Array<HttpCallbackOptional | RequestSignature>;\n\nexport type ParsedRequestOptions =\n
|
|
1
|
+
{"version":3,"file":"internal-types.mjs","names":[],"sources":["../src/internal-types.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type * as http from 'http';\nimport type * as https from 'https';\nimport type { get, IncomingMessage, request } from 'http';\nimport type * as url from 'url';\n\nexport type IgnoreMatcher = string | RegExp | ((url: string) => boolean);\nexport type HttpCallback = (res: IncomingMessage) => void;\nexport type RequestFunction = typeof request;\nexport type GetFunction = typeof get;\n\nexport type HttpCallbackOptional = HttpCallback | undefined;\n\n// from node 10+\nexport type RequestSignature = [http.RequestOptions, HttpCallbackOptional] &\n HttpCallback;\n\nexport type HttpRequestArgs = Array<HttpCallbackOptional | RequestSignature>;\n\nexport type ParsedRequestOptions =\n (http.RequestOptions & Partial<url.UrlWithParsedQuery>) | http.RequestOptions;\nexport type Http = typeof http;\nexport type Https = typeof https;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type Func<T> = (...args: any[]) => T;\n\nexport interface Err extends Error {\n errno?: number;\n code?: string;\n path?: string;\n syscall?: string;\n stack?: string;\n}\n\n/**\n * Names of possible synthetic test sources.\n */\nexport const SYNTHETIC_TEST_NAMES = ['alwayson'];\n\n/**\n * Names of possible synthetic bot sources.\n */\nexport const SYNTHETIC_BOT_NAMES = ['googlebot', 'bingbot'];\n\n/**\n * REDACTED string used to replace sensitive information in URLs.\n */\nexport const STR_REDACTED = 'REDACTED';\n\n/**\n * List of URL query keys that are considered sensitive and whose value should be redacted.\n */\nexport const DEFAULT_QUERY_STRINGS_TO_REDACT = [\n 'sig',\n 'Signature',\n 'AWSAccessKeyId',\n 'X-Goog-Signature',\n 'X-Amz-Signature',\n 'X-Amz-Credential',\n 'X-Amz-Security-Token',\n] as const;\n"],"mappings":";;;;AAyCA,MAAa,uBAAuB,CAAC,UAAU;;;;AAK/C,MAAa,sBAAsB,CAAC,aAAa,SAAS;;;;AAK1D,MAAa,eAAe;;;;AAK5B,MAAa,kCAAkC;CAC7C;CACA;CACA;CACA;CACA;CACA;CACA;AACF"}
|
package/dist/semconv.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/semconv.ts
|
|
2
2
|
/**
|
|
3
3
|
* Specifies the category of synthetic traffic, such as tests or bots.
|
|
4
4
|
*
|
|
@@ -11,7 +11,6 @@ const ATTR_USER_AGENT_SYNTHETIC_TYPE = "user_agent.synthetic.type";
|
|
|
11
11
|
* Enum value "test" for attribute {@link ATTR_USER_AGENT_SYNTHETIC_TYPE}.
|
|
12
12
|
*/
|
|
13
13
|
const USER_AGENT_SYNTHETIC_TYPE_VALUE_TEST = "test";
|
|
14
|
-
//#endregion
|
|
15
14
|
exports.ATTR_USER_AGENT_SYNTHETIC_TYPE = ATTR_USER_AGENT_SYNTHETIC_TYPE;
|
|
16
15
|
exports.USER_AGENT_SYNTHETIC_TYPE_VALUE_TEST = USER_AGENT_SYNTHETIC_TYPE_VALUE_TEST;
|
|
17
16
|
|
package/dist/semconv.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/semconv.ts
|
|
2
2
|
/**
|
|
3
3
|
* Specifies the category of synthetic traffic, such as tests or bots.
|
|
4
4
|
*
|
|
@@ -11,7 +11,6 @@ const ATTR_USER_AGENT_SYNTHETIC_TYPE = "user_agent.synthetic.type";
|
|
|
11
11
|
* Enum value "test" for attribute {@link ATTR_USER_AGENT_SYNTHETIC_TYPE}.
|
|
12
12
|
*/
|
|
13
13
|
const USER_AGENT_SYNTHETIC_TYPE_VALUE_TEST = "test";
|
|
14
|
-
//#endregion
|
|
15
14
|
export { ATTR_USER_AGENT_SYNTHETIC_TYPE, USER_AGENT_SYNTHETIC_TYPE_VALUE_TEST };
|
|
16
15
|
|
|
17
16
|
//# sourceMappingURL=semconv.mjs.map
|
package/dist/types.d.cts
CHANGED
|
@@ -2,54 +2,53 @@
|
|
|
2
2
|
import { Attributes, Span } from "@opentelemetry/api";
|
|
3
3
|
import { ClientRequest, IncomingMessage, RequestOptions, ServerResponse } from "http";
|
|
4
4
|
import { InstrumentationConfig } from "@opentelemetry/instrumentation";
|
|
5
|
-
|
|
6
|
-
interface HttpCustomAttributeFunction {
|
|
5
|
+
export interface HttpCustomAttributeFunction {
|
|
7
6
|
(span: Span, request: ClientRequest | IncomingMessage, response: IncomingMessage | ServerResponse): void;
|
|
8
7
|
}
|
|
9
8
|
/**
|
|
10
9
|
* Called with each incoming request. Return `true` to skip creating a server
|
|
11
10
|
* span for that request.
|
|
12
11
|
*/
|
|
13
|
-
interface IgnoreIncomingRequestFunction {
|
|
12
|
+
export interface IgnoreIncomingRequestFunction {
|
|
14
13
|
(request: IncomingMessage): boolean;
|
|
15
14
|
}
|
|
16
15
|
/**
|
|
17
16
|
* Called with each outgoing request's parsed options. Return `true` to skip
|
|
18
17
|
* creating a client span for that request.
|
|
19
18
|
*/
|
|
20
|
-
interface IgnoreOutgoingRequestFunction {
|
|
19
|
+
export interface IgnoreOutgoingRequestFunction {
|
|
21
20
|
(request: RequestOptions): boolean;
|
|
22
21
|
}
|
|
23
22
|
/**
|
|
24
23
|
* Called with the active span and request before the request is handled.
|
|
25
24
|
*/
|
|
26
|
-
interface HttpRequestCustomAttributeFunction {
|
|
25
|
+
export interface HttpRequestCustomAttributeFunction {
|
|
27
26
|
(span: Span, request: ClientRequest | IncomingMessage): void;
|
|
28
27
|
}
|
|
29
28
|
/**
|
|
30
29
|
* Called with the active span and response before the response is handled.
|
|
31
30
|
*/
|
|
32
|
-
interface HttpResponseCustomAttributeFunction {
|
|
31
|
+
export interface HttpResponseCustomAttributeFunction {
|
|
33
32
|
(span: Span, response: IncomingMessage | ServerResponse): void;
|
|
34
33
|
}
|
|
35
34
|
/**
|
|
36
35
|
* Called before an incoming request span is started. Returned attributes are
|
|
37
36
|
* added to the new server span.
|
|
38
37
|
*/
|
|
39
|
-
interface StartIncomingSpanCustomAttributeFunction {
|
|
38
|
+
export interface StartIncomingSpanCustomAttributeFunction {
|
|
40
39
|
(request: IncomingMessage): Attributes;
|
|
41
40
|
}
|
|
42
41
|
/**
|
|
43
42
|
* Called with an outgoing request's parsed options before the span is started.
|
|
44
43
|
* Returned attributes are added to the new client span.
|
|
45
44
|
*/
|
|
46
|
-
interface StartOutgoingSpanCustomAttributeFunction {
|
|
45
|
+
export interface StartOutgoingSpanCustomAttributeFunction {
|
|
47
46
|
(request: RequestOptions): Attributes;
|
|
48
47
|
}
|
|
49
48
|
/**
|
|
50
49
|
* Options available for the HTTP instrumentation (see [documentation](https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/opentelemetry-instrumentation-http#http-instrumentation-options))
|
|
51
50
|
*/
|
|
52
|
-
interface HttpInstrumentationConfig extends InstrumentationConfig {
|
|
51
|
+
export interface HttpInstrumentationConfig extends InstrumentationConfig {
|
|
53
52
|
/** Do not trace incoming requests for which this function returns `true`. */
|
|
54
53
|
ignoreIncomingRequestHook?: IgnoreIncomingRequestFunction;
|
|
55
54
|
/** Do not trace outgoing requests for which this function returns `true`. */
|
|
@@ -107,6 +106,4 @@ interface HttpInstrumentationConfig extends InstrumentationConfig {
|
|
|
107
106
|
*/
|
|
108
107
|
redactedQueryParamsServer?: string[];
|
|
109
108
|
}
|
|
110
|
-
//#endregion
|
|
111
|
-
export { HttpCustomAttributeFunction, HttpInstrumentationConfig, HttpRequestCustomAttributeFunction, HttpResponseCustomAttributeFunction, IgnoreIncomingRequestFunction, IgnoreOutgoingRequestFunction, StartIncomingSpanCustomAttributeFunction, StartOutgoingSpanCustomAttributeFunction };
|
|
112
109
|
//# sourceMappingURL=types.d.cts.map
|
package/dist/types.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.cts","names":[],"sources":["../src/types.d.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.d.cts","names":[],"sources":["../src/types.d.ts"],"mappings":";;;;iBAIiB;GACZ,MAAM,MAAM,SAAS,gBAAgB,iBAAiB,UAAU,kBAAkB;;;;;;iBAMtE;GACZ,SAAS;;;;;;iBAMG;GACZ,SAAS;;;;;iBAKG;GACZ,MAAM,MAAM,SAAS,gBAAgB;;;;;iBAKzB;GACZ,MAAM,MAAM,UAAU,kBAAkB;;;;;;iBAM5B;GACZ,SAAS,kBAAkB;;;;;;iBAMf;GACZ,SAAS,iBAAiB;;;;;iBAKd,kCAAkC;;EAE/C,4BAA4B;;EAE5B,4BAA4B;;EAE5B;;EAEA;;EAEA,8BAA8B;;EAE9B,cAAc;;EAEd,eAAe;;EAEf,wBAAwB;;EAExB,wBAAwB;;EAExB;;EAEA;;EAEA;IACI;MACI;MACA;;IAEJ;MACI;MACA;;;;;;;EAOR;;;;;;;;;;EAUA;;;;;;;;EAQA"}
|
package/dist/types.d.mts
CHANGED
|
@@ -2,54 +2,53 @@
|
|
|
2
2
|
import { Attributes, Span } from "@opentelemetry/api";
|
|
3
3
|
import { InstrumentationConfig } from "@opentelemetry/instrumentation";
|
|
4
4
|
import { ClientRequest, IncomingMessage, RequestOptions, ServerResponse } from "http";
|
|
5
|
-
|
|
6
|
-
interface HttpCustomAttributeFunction {
|
|
5
|
+
export interface HttpCustomAttributeFunction {
|
|
7
6
|
(span: Span, request: ClientRequest | IncomingMessage, response: IncomingMessage | ServerResponse): void;
|
|
8
7
|
}
|
|
9
8
|
/**
|
|
10
9
|
* Called with each incoming request. Return `true` to skip creating a server
|
|
11
10
|
* span for that request.
|
|
12
11
|
*/
|
|
13
|
-
interface IgnoreIncomingRequestFunction {
|
|
12
|
+
export interface IgnoreIncomingRequestFunction {
|
|
14
13
|
(request: IncomingMessage): boolean;
|
|
15
14
|
}
|
|
16
15
|
/**
|
|
17
16
|
* Called with each outgoing request's parsed options. Return `true` to skip
|
|
18
17
|
* creating a client span for that request.
|
|
19
18
|
*/
|
|
20
|
-
interface IgnoreOutgoingRequestFunction {
|
|
19
|
+
export interface IgnoreOutgoingRequestFunction {
|
|
21
20
|
(request: RequestOptions): boolean;
|
|
22
21
|
}
|
|
23
22
|
/**
|
|
24
23
|
* Called with the active span and request before the request is handled.
|
|
25
24
|
*/
|
|
26
|
-
interface HttpRequestCustomAttributeFunction {
|
|
25
|
+
export interface HttpRequestCustomAttributeFunction {
|
|
27
26
|
(span: Span, request: ClientRequest | IncomingMessage): void;
|
|
28
27
|
}
|
|
29
28
|
/**
|
|
30
29
|
* Called with the active span and response before the response is handled.
|
|
31
30
|
*/
|
|
32
|
-
interface HttpResponseCustomAttributeFunction {
|
|
31
|
+
export interface HttpResponseCustomAttributeFunction {
|
|
33
32
|
(span: Span, response: IncomingMessage | ServerResponse): void;
|
|
34
33
|
}
|
|
35
34
|
/**
|
|
36
35
|
* Called before an incoming request span is started. Returned attributes are
|
|
37
36
|
* added to the new server span.
|
|
38
37
|
*/
|
|
39
|
-
interface StartIncomingSpanCustomAttributeFunction {
|
|
38
|
+
export interface StartIncomingSpanCustomAttributeFunction {
|
|
40
39
|
(request: IncomingMessage): Attributes;
|
|
41
40
|
}
|
|
42
41
|
/**
|
|
43
42
|
* Called with an outgoing request's parsed options before the span is started.
|
|
44
43
|
* Returned attributes are added to the new client span.
|
|
45
44
|
*/
|
|
46
|
-
interface StartOutgoingSpanCustomAttributeFunction {
|
|
45
|
+
export interface StartOutgoingSpanCustomAttributeFunction {
|
|
47
46
|
(request: RequestOptions): Attributes;
|
|
48
47
|
}
|
|
49
48
|
/**
|
|
50
49
|
* Options available for the HTTP instrumentation (see [documentation](https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/opentelemetry-instrumentation-http#http-instrumentation-options))
|
|
51
50
|
*/
|
|
52
|
-
interface HttpInstrumentationConfig extends InstrumentationConfig {
|
|
51
|
+
export interface HttpInstrumentationConfig extends InstrumentationConfig {
|
|
53
52
|
/** Do not trace incoming requests for which this function returns `true`. */
|
|
54
53
|
ignoreIncomingRequestHook?: IgnoreIncomingRequestFunction;
|
|
55
54
|
/** Do not trace outgoing requests for which this function returns `true`. */
|
|
@@ -107,6 +106,4 @@ interface HttpInstrumentationConfig extends InstrumentationConfig {
|
|
|
107
106
|
*/
|
|
108
107
|
redactedQueryParamsServer?: string[];
|
|
109
108
|
}
|
|
110
|
-
//#endregion
|
|
111
|
-
export { HttpCustomAttributeFunction, HttpInstrumentationConfig, HttpRequestCustomAttributeFunction, HttpResponseCustomAttributeFunction, IgnoreIncomingRequestFunction, IgnoreOutgoingRequestFunction, StartIncomingSpanCustomAttributeFunction, StartOutgoingSpanCustomAttributeFunction };
|
|
112
109
|
//# sourceMappingURL=types.d.mts.map
|
package/dist/types.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","names":[],"sources":["../src/types.d.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.d.mts","names":[],"sources":["../src/types.d.ts"],"mappings":";;;;iBAIiB;GACZ,MAAM,MAAM,SAAS,gBAAgB,iBAAiB,UAAU,kBAAkB;;;;;;iBAMtE;GACZ,SAAS;;;;;;iBAMG;GACZ,SAAS;;;;;iBAKG;GACZ,MAAM,MAAM,SAAS,gBAAgB;;;;;iBAKzB;GACZ,MAAM,MAAM,UAAU,kBAAkB;;;;;;iBAM5B;GACZ,SAAS,kBAAkB;;;;;;iBAMf;GACZ,SAAS,iBAAiB;;;;;iBAKd,kCAAkC;;EAE/C,4BAA4B;;EAE5B,4BAA4B;;EAE5B;;EAEA;;EAEA,8BAA8B;;EAE9B,cAAc;;EAEd,eAAe;;EAEf,wBAAwB;;EAExB,wBAAwB;;EAExB;;EAEA;;EAEA;IACI;MACI;MACA;;IAEJ;MACI;MACA;;;;;;;EAOR;;;;;;;;;;EAUA;;;;;;;;EAQA"}
|
package/dist/utils.cjs
CHANGED
|
@@ -4,7 +4,7 @@ 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
6
|
let forwarded_parse = require("forwarded-parse");
|
|
7
|
-
|
|
7
|
+
// src/utils.ts
|
|
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 '?').
|
|
@@ -464,7 +464,6 @@ function parseForwardedHeader(header) {
|
|
|
464
464
|
return [];
|
|
465
465
|
}
|
|
466
466
|
}
|
|
467
|
-
//#endregion
|
|
468
467
|
exports.extractHostnameAndPort = extractHostnameAndPort;
|
|
469
468
|
exports.getAbsoluteUrl = getAbsoluteUrl;
|
|
470
469
|
exports.getIncomingRequestAttributes = getIncomingRequestAttributes;
|