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EAAE;YAC1C,OAAO,QAAQ,CAAC,WAAW,EAAE,CAAC;SAC/B;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF;AA/aD,sDA+aC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport * as diagch from 'diagnostics_channel';\nimport { URL } from 'url';\n\nimport {\n InstrumentationBase,\n safeExecuteInTheMiddle,\n} from '@opentelemetry/instrumentation';\nimport {\n Attributes,\n context,\n Histogram,\n HrTime,\n INVALID_SPAN_CONTEXT,\n propagation,\n Span,\n SpanKind,\n SpanStatusCode,\n trace,\n ValueType,\n} from '@opentelemetry/api';\n\nimport { PACKAGE_NAME, PACKAGE_VERSION } from './version';\n\nimport {\n ListenerRecord,\n RequestHeadersMessage,\n RequestMessage,\n RequestTrailersMessage,\n ResponseHeadersMessage,\n} from './internal-types';\nimport { UndiciInstrumentationConfig, UndiciRequest } from './types';\nimport { SemanticAttributes } from './enums/SemanticAttributes';\nimport {\n hrTime,\n hrTimeDuration,\n hrTimeToMilliseconds,\n} from '@opentelemetry/core';\n\ninterface InstrumentationRecord {\n span: Span;\n attributes: Attributes;\n startTime: HrTime;\n}\n\n// A combination of https://github.com/elastic/apm-agent-nodejs and\n// https://github.com/gadget-inc/opentelemetry-instrumentations/blob/main/packages/opentelemetry-instrumentation-undici/src/index.ts\nexport class UndiciInstrumentation extends InstrumentationBase {\n // Keep ref to avoid https://github.com/nodejs/node/issues/42170 bug and for\n // unsubscribing.\n private _channelSubs!: Array;\n private _recordFromReq = new WeakMap();\n\n private _httpClientDurationHistogram!: Histogram;\n constructor(config: UndiciInstrumentationConfig = {}) {\n super(PACKAGE_NAME, PACKAGE_VERSION, config);\n }\n\n // No need to instrument files/modules\n protected override init() {\n return undefined;\n }\n\n override disable(): void {\n super.disable();\n this._channelSubs.forEach(sub => sub.channel.unsubscribe(sub.onMessage));\n this._channelSubs.length = 0;\n }\n\n override enable(): void {\n // \"enabled\" handling is currently a bit messy with InstrumentationBase.\n // If constructed with `{enabled: false}`, this `.enable()` is still called,\n // and `this.getConfig().enabled !== this.isEnabled()`, creating confusion.\n //\n // For now, this class will setup for instrumenting if `.enable()` is\n // called, but use `this.getConfig().enabled` to determine if\n // instrumentation should be generated. This covers the more likely common\n // case of config being given a construction time, rather than later via\n // `instance.enable()`, `.disable()`, or `.setConfig()` calls.\n super.enable();\n\n // This method is called by the super-class constructor before ours is\n // called. So we need to ensure the property is initalized.\n this._channelSubs = this._channelSubs || [];\n\n // Avoid to duplicate subscriptions\n if (this._channelSubs.length > 0) {\n return;\n }\n\n this.subscribeToChannel(\n 'undici:request:create',\n this.onRequestCreated.bind(this)\n );\n this.subscribeToChannel(\n 'undici:client:sendHeaders',\n this.onRequestHeaders.bind(this)\n );\n this.subscribeToChannel(\n 'undici:request:headers',\n this.onResponseHeaders.bind(this)\n );\n this.subscribeToChannel('undici:request:trailers', this.onDone.bind(this));\n this.subscribeToChannel('undici:request:error', this.onError.bind(this));\n }\n\n protected override _updateMetricInstruments() {\n this._httpClientDurationHistogram = this.meter.createHistogram(\n 'http.client.request.duration',\n {\n description: 'Measures the duration of outbound HTTP 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 subscribeToChannel(\n diagnosticChannel: string,\n onMessage: ListenerRecord['onMessage']\n ) {\n const channel = diagch.channel(diagnosticChannel);\n channel.subscribe(onMessage);\n this._channelSubs.push({\n name: diagnosticChannel,\n channel,\n onMessage,\n });\n }\n\n // This is the 1st message we receive for each request (fired after request creation). Here we will\n // create the span and populate some atttributes, then link the span to the request for further\n // span processing\n private onRequestCreated({ request }: RequestMessage): void {\n // Ignore if:\n // - instrumentation is disabled\n // - ignored by config\n // - method is 'CONNECT'\n const config = this.getConfig();\n const enabled = config.enabled !== false;\n const shouldIgnoreReq = safeExecuteInTheMiddle(\n () =>\n !enabled ||\n request.method === 'CONNECT' ||\n config.ignoreRequestHook?.(request),\n e => e && this._diag.error('caught ignoreRequestHook error: ', e),\n true\n );\n\n if (shouldIgnoreReq) {\n return;\n }\n\n const startTime = hrTime();\n const requestUrl = new URL(request.origin + request.path);\n const urlScheme = requestUrl.protocol.replace(':', '');\n const requestMethod = this.getRequestMethod(request.method);\n const attributes: Attributes = {\n [SemanticAttributes.HTTP_REQUEST_METHOD]: requestMethod,\n [SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL]: request.method,\n [SemanticAttributes.URL_FULL]: requestUrl.toString(),\n [SemanticAttributes.URL_PATH]: requestUrl.pathname,\n [SemanticAttributes.URL_QUERY]: requestUrl.search,\n [SemanticAttributes.URL_SCHEME]: urlScheme,\n };\n\n const schemePorts: Record = { https: '443', http: '80' };\n const serverAddress = requestUrl.hostname;\n const serverPort = requestUrl.port || schemePorts[urlScheme];\n\n attributes[SemanticAttributes.SERVER_ADDRESS] = serverAddress;\n if (serverPort && !isNaN(Number(serverPort))) {\n attributes[SemanticAttributes.SERVER_PORT] = Number(serverPort);\n }\n\n // Get user agent from headers\n let userAgent;\n if (Array.isArray(request.headers)) {\n const idx = request.headers.findIndex(\n h => h.toLowerCase() === 'user-agent'\n );\n if (idx >= 0) {\n userAgent = request.headers[idx + 1];\n }\n } else if (typeof request.headers === 'string') {\n const headers = request.headers.split('\\r\\n');\n const uaHeader = headers.find(h =>\n h.toLowerCase().startsWith('user-agent')\n );\n userAgent =\n uaHeader && uaHeader.substring(uaHeader.indexOf(':') + 1).trim();\n }\n\n if (userAgent) {\n attributes[SemanticAttributes.USER_AGENT_ORIGINAL] = userAgent;\n }\n\n // Get attributes from the hook if present\n const hookAttributes = safeExecuteInTheMiddle(\n () => config.startSpanHook?.(request),\n e => e && this._diag.error('caught startSpanHook error: ', e),\n true\n );\n if (hookAttributes) {\n Object.entries(hookAttributes).forEach(([key, val]) => {\n attributes[key] = val;\n });\n }\n\n // Check if parent span is required via config and:\n // - if a parent is required but not present, we use a `NoopSpan` to still\n // propagate context without recording it.\n // - create a span otherwise\n const activeCtx = context.active();\n const currentSpan = trace.getSpan(activeCtx);\n let span: Span;\n\n if (\n config.requireParentforSpans &&\n (!currentSpan || !trace.isSpanContextValid(currentSpan.spanContext()))\n ) {\n span = trace.wrapSpanContext(INVALID_SPAN_CONTEXT);\n } else {\n span = this.tracer.startSpan(\n requestMethod === '_OTHER' ? 'HTTP' : requestMethod,\n {\n kind: SpanKind.CLIENT,\n attributes: attributes,\n },\n activeCtx\n );\n }\n\n // Execute the request hook if defined\n safeExecuteInTheMiddle(\n () => config.requestHook?.(span, request),\n e => e && this._diag.error('caught requestHook error: ', e),\n true\n );\n\n // Context propagation goes last so no hook can tamper\n // the propagation headers\n const requestContext = trace.setSpan(context.active(), span);\n const addedHeaders: Record = {};\n propagation.inject(requestContext, addedHeaders);\n\n const headerEntries = Object.entries(addedHeaders);\n\n for (let i = 0; i < headerEntries.length; i++) {\n const [k, v] = headerEntries[i];\n\n if (typeof request.addHeader === 'function') {\n request.addHeader(k, v);\n } else if (typeof request.headers === 'string') {\n request.headers += `${k}: ${v}\\r\\n`;\n } else if (Array.isArray(request.headers)) {\n // undici@6.11.0 accidentally, briefly removed `request.addHeader()`.\n request.headers.push(k, v);\n }\n }\n this._recordFromReq.set(request, { span, attributes, startTime });\n }\n\n // This is the 2nd message we receive for each request. It is fired when connection with\n // the remote is established and about to send the first byte. Here we do have info about the\n // remote address and port so we can populate some `network.*` attributes into the span\n private onRequestHeaders({ request, socket }: RequestHeadersMessage): void {\n const record = this._recordFromReq.get(request as UndiciRequest);\n\n if (!record) {\n return;\n }\n\n const config = this.getConfig();\n const { span } = record;\n const { remoteAddress, remotePort } = socket;\n const spanAttributes: Attributes = {\n [SemanticAttributes.NETWORK_PEER_ADDRESS]: remoteAddress,\n [SemanticAttributes.NETWORK_PEER_PORT]: remotePort,\n };\n\n // After hooks have been processed (which may modify request headers)\n // we can collect the headers based on the configuration\n if (config.headersToSpanAttributes?.requestHeaders) {\n const headersToAttribs = new Set(\n config.headersToSpanAttributes.requestHeaders.map(n => n.toLowerCase())\n );\n\n // headers could be in form\n // ['name: value', ...] for v5\n // ['name', 'value', ...] for v6\n const rawHeaders = Array.isArray(request.headers)\n ? request.headers\n : request.headers.split('\\r\\n');\n rawHeaders.forEach((h, idx) => {\n const sepIndex = h.indexOf(':');\n const hasSeparator = sepIndex !== -1;\n const name = (\n hasSeparator ? h.substring(0, sepIndex) : h\n ).toLowerCase();\n const value = hasSeparator\n ? h.substring(sepIndex + 1)\n : rawHeaders[idx + 1];\n\n if (headersToAttribs.has(name)) {\n spanAttributes[`http.request.header.${name}`] = value.trim();\n }\n });\n }\n\n span.setAttributes(spanAttributes);\n }\n\n // This is the 3rd message we get for each request and it's fired when the server\n // headers are received, body may not be accessible yet.\n // From the response headers we can set the status and content length\n private onResponseHeaders({\n request,\n response,\n }: ResponseHeadersMessage): void {\n const record = this._recordFromReq.get(request);\n\n if (!record) {\n return;\n }\n\n const { span, attributes } = record;\n const spanAttributes: Attributes = {\n [SemanticAttributes.HTTP_RESPONSE_STATUS_CODE]: response.statusCode,\n };\n\n const config = this.getConfig();\n\n // Execute the response hook if defined\n safeExecuteInTheMiddle(\n () => config.responseHook?.(span, { request, response }),\n e => e && this._diag.error('caught responseHook error: ', e),\n true\n );\n\n const headersToAttribs = new Set();\n\n if (config.headersToSpanAttributes?.responseHeaders) {\n config.headersToSpanAttributes?.responseHeaders.forEach(name =>\n headersToAttribs.add(name.toLowerCase())\n );\n }\n\n for (let idx = 0; idx < response.headers.length; idx = idx + 2) {\n const name = response.headers[idx].toString().toLowerCase();\n const value = response.headers[idx + 1];\n\n if (headersToAttribs.has(name)) {\n spanAttributes[`http.response.header.${name}`] = value.toString();\n }\n\n if (name === 'content-length') {\n const contentLength = Number(value.toString());\n if (!isNaN(contentLength)) {\n spanAttributes['http.response.header.content-length'] = contentLength;\n }\n }\n }\n\n span.setAttributes(spanAttributes);\n span.setStatus({\n code:\n response.statusCode >= 400\n ? SpanStatusCode.ERROR\n : SpanStatusCode.UNSET,\n });\n record.attributes = Object.assign(attributes, spanAttributes);\n }\n\n // This is the last event we receive if the request went without any errors\n private onDone({ request }: RequestTrailersMessage): void {\n const record = this._recordFromReq.get(request);\n\n if (!record) {\n return;\n }\n\n const { span, attributes, startTime } = record;\n\n // End the span\n span.end();\n this._recordFromReq.delete(request);\n\n // Record metrics\n this.recordRequestDuration(attributes, startTime);\n }\n\n // This is the event we get when something is wrong in the request like\n // - invalid options when calling `fetch` global API or any undici method for request\n // - connectivity errors such as unreachable host\n // - requests aborted through an `AbortController.signal`\n // NOTE: server errors are considered valid responses and it's the lib consumer\n // who should deal with that.\n private onError({ request, error }: any): void {\n const record = this._recordFromReq.get(request);\n\n if (!record) {\n return;\n }\n\n const { span, attributes, startTime } = record;\n\n // NOTE: in `undici@6.3.0` when request aborted the error type changes from\n // a custom error (`RequestAbortedError`) to a built-in `DOMException` carrying\n // some differences:\n // - `code` is from DOMEXception (ABORT_ERR: 20)\n // - `message` changes\n // - stacktrace is smaller and contains node internal frames\n span.recordException(error);\n span.setStatus({\n code: SpanStatusCode.ERROR,\n message: error.message,\n });\n span.end();\n this._recordFromReq.delete(request);\n\n // Record metrics (with the error)\n attributes[SemanticAttributes.ERROR_TYPE] = error.message;\n this.recordRequestDuration(attributes, startTime);\n }\n\n private recordRequestDuration(attributes: Attributes, startTime: HrTime) {\n // Time to record metrics\n const metricsAttributes: Attributes = {};\n // Get the attribs already in span attributes\n const keysToCopy = [\n SemanticAttributes.HTTP_RESPONSE_STATUS_CODE,\n SemanticAttributes.HTTP_REQUEST_METHOD,\n SemanticAttributes.SERVER_ADDRESS,\n SemanticAttributes.SERVER_PORT,\n SemanticAttributes.URL_SCHEME,\n SemanticAttributes.ERROR_TYPE,\n ];\n keysToCopy.forEach(key => {\n if (key in attributes) {\n metricsAttributes[key] = attributes[key];\n }\n });\n\n // Take the duration and record it\n const durationSeconds =\n hrTimeToMilliseconds(hrTimeDuration(startTime, hrTime())) / 1000;\n this._httpClientDurationHistogram.record(\n durationSeconds,\n metricsAttributes\n );\n }\n\n private getRequestMethod(original: string): string {\n const knownMethods = {\n CONNECT: true,\n OPTIONS: true,\n HEAD: true,\n GET: true,\n POST: true,\n PUT: true,\n PATCH: true,\n DELETE: true,\n TRACE: true,\n };\n\n if (original.toUpperCase() in knownMethods) {\n return original.toUpperCase();\n }\n\n return '_OTHER';\n }\n}\n"]}