@opentelemetry/instrumentation-http 0.49.1 → 0.51.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 CHANGED
@@ -67,7 +67,39 @@ The following options are deprecated:
67
67
  | Options | Type | Description |
68
68
  | ------- | ---- | ----------- |
69
69
  | `ignoreIncomingPaths` | `IgnoreMatcher[]` | Http instrumentation will not trace all incoming requests that match paths |
70
- | `ignoreOutgoingUrls` | `IgnoreMatcher[]` | Http instrumentation will not trace all outgoing requests that match urls |
70
+
71
+ ## Semantic Conventions
72
+
73
+ This package uses `@opentelemetry/semantic-conventions` version `1.22+`, which implements Semantic Convention [Version 1.7.0](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.7.0/semantic_conventions/README.md)
74
+
75
+ Attributes collected:
76
+
77
+ | Attribute | Short Description | Notes |
78
+ | ------------------------------------------- | ------------------------------------------------------------------------------ | --------------------------------------------------------- |
79
+ | `ip_tcp` | Transport protocol used | Key: `NETTRANSPORTVALUES_IP_TCP` |
80
+ | `ip_udp` | Transport protocol used | Key: `NETTRANSPORTVALUES_IP_UDP` |
81
+ | `http.client_ip` | The IP address of the original client behind all proxies, if known | Key: `SEMATTRS_HTTP_CLIENT_IP` |
82
+ | `http.flavor` | Kind of HTTP protocol used | Key: `SEMATTRS_HTTP_FLAVOR` |
83
+ | `http.host` | The value of the HTTP host header | Key: `SEMATTRS_HTTP_HOST` |
84
+ | `http.method` | HTTP request method | Key: `SEMATTRS_HTTP_METHOD` |
85
+ | `http.request_content_length` | The size of the request payload body in bytes | Key: `SEMATTRS_HTTP_REQUEST_CONTENT_LENGTH` |
86
+ | `http.request_content_length_uncompressed` | The size of the uncompressed request payload body after transport decoding | Key: `SEMATTRS_HTTP_REQUEST_CONTENT_LENGTH_UNCOMPRESSED` |
87
+ | `http.response_content_length` | The size of the response payload body in bytes | Key: `SEMATTRS_HTTP_RESPONSE_CONTENT_LENGTH` |
88
+ | `http.response_content_length_uncompressed` | The size of the uncompressed response payload body after transport decoding | Key: `SEMATTRS_HTTP_RESPONSE_CONTENT_LENGTH_UNCOMPRESSED` |
89
+ | `http.route` | The matched route (path template). | Key: `SEMATTRS_HTTP_ROUTE` |
90
+ | `http.scheme` | The URI scheme identifying the used protocol | Key: `SEMATTRS_HTTP_SCHEME` |
91
+ | `http.server_name` | The primary server name of the matched virtual host | Key: `SEMATTRS_HTTP_SERVER_NAME` |
92
+ | `http.status_code` | HTTP response status code | Key: `SEMATTRS_HTTP_STATUS_CODE` |
93
+ | `http.target` | The full request target as passed in a HTTP request line or equivalent | Key: `SEMATTRS_HTTP_TARGET` |
94
+ | `http.url` | Full HTTP request URL in the form `scheme://host[:port]/path?query[#fragment]` | Key: `SEMATTRS_HTTP_URL` |
95
+ | `http.user_agent` | Value of the HTTP User-Agent header sent by the client | Key: `SEMATTRS_HTTP_USER_AGENT` |
96
+ | `net.host.ip` | Like net.peer.ip but for the host IP. Useful in case of a multi-IP host | Key: `SEMATTRS_NET_HOST_IP` |
97
+ | `net.host.name` | Local hostname or similar | Key: `SEMATTRS_NET_HOST_NAME` |
98
+ | `net.host.port` | Like net.peer.port but for the host port | Key: `SEMATTRS_NET_HOST_PORT` |
99
+ | `net.peer.ip.` | Remote address of the peer (dotted decimal for IPv4 or RFC5952 for IPv6) | Key: `SEMATTRS_NET_PEER_IP` |
100
+ | `net.peer.name` | Remote hostname or similar | Key: `SEMATTRS_NET_PEER_NAME` |
101
+ | `net.peer.port` | Remote port number | Key: `SEMATTRS_NET_PEER_PORT` |
102
+ | `net.transport` | Transport protocol used | Key: `SEMATTRS_NET_TRANSPORT` |
71
103
 
72
104
  ## Useful links
73
105
 
@@ -1,12 +1,12 @@
1
1
  /// <reference types="node" />
2
2
  import type * as http from 'http';
3
3
  import * as url from 'url';
4
- import { Func, Http, HttpInstrumentationConfig, HttpRequestArgs, Https } from './types';
4
+ import { Func, HttpInstrumentationConfig, HttpRequestArgs } from './types';
5
5
  import { InstrumentationBase, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation';
6
6
  /**
7
7
  * Http instrumentation instrumentation for Opentelemetry
8
8
  */
9
- export declare class HttpInstrumentation extends InstrumentationBase<Http> {
9
+ export declare class HttpInstrumentation extends InstrumentationBase {
10
10
  /** keep track on spans not ended */
11
11
  private readonly _spanNotEnded;
12
12
  private _headerCapture;
@@ -17,8 +17,8 @@ export declare class HttpInstrumentation extends InstrumentationBase<Http> {
17
17
  private _getConfig;
18
18
  setConfig(config?: HttpInstrumentationConfig): void;
19
19
  init(): [
20
- InstrumentationNodeModuleDefinition<Https>,
21
- InstrumentationNodeModuleDefinition<Http>
20
+ InstrumentationNodeModuleDefinition,
21
+ InstrumentationNodeModuleDefinition
22
22
  ];
23
23
  private _getHttpInstrumentation;
24
24
  private _getHttpsInstrumentation;
package/build/src/http.js CHANGED
@@ -59,9 +59,7 @@ class HttpInstrumentation extends instrumentation_1.InstrumentationBase {
59
59
  return [this._getHttpsInstrumentation(), this._getHttpInstrumentation()];
60
60
  }
61
61
  _getHttpInstrumentation() {
62
- const version = process.versions.node;
63
- return new instrumentation_1.InstrumentationNodeModuleDefinition('http', ['*'], moduleExports => {
64
- this._diag.debug(`Applying patch for http@${version}`);
62
+ return new instrumentation_1.InstrumentationNodeModuleDefinition('http', ['*'], (moduleExports) => {
65
63
  if ((0, instrumentation_1.isWrapped)(moduleExports.request)) {
66
64
  this._unwrap(moduleExports, 'request');
67
65
  }
@@ -75,19 +73,16 @@ class HttpInstrumentation extends instrumentation_1.InstrumentationBase {
75
73
  }
76
74
  this._wrap(moduleExports.Server.prototype, 'emit', this._getPatchIncomingRequestFunction('http'));
77
75
  return moduleExports;
78
- }, moduleExports => {
76
+ }, (moduleExports) => {
79
77
  if (moduleExports === undefined)
80
78
  return;
81
- this._diag.debug(`Removing patch for http@${version}`);
82
79
  this._unwrap(moduleExports, 'request');
83
80
  this._unwrap(moduleExports, 'get');
84
81
  this._unwrap(moduleExports.Server.prototype, 'emit');
85
82
  });
86
83
  }
87
84
  _getHttpsInstrumentation() {
88
- const version = process.versions.node;
89
- return new instrumentation_1.InstrumentationNodeModuleDefinition('https', ['*'], moduleExports => {
90
- this._diag.debug(`Applying patch for https@${version}`);
85
+ return new instrumentation_1.InstrumentationNodeModuleDefinition('https', ['*'], (moduleExports) => {
91
86
  if ((0, instrumentation_1.isWrapped)(moduleExports.request)) {
92
87
  this._unwrap(moduleExports, 'request');
93
88
  }
@@ -101,10 +96,9 @@ class HttpInstrumentation extends instrumentation_1.InstrumentationBase {
101
96
  }
102
97
  this._wrap(moduleExports.Server.prototype, 'emit', this._getPatchIncomingRequestFunction('https'));
103
98
  return moduleExports;
104
- }, moduleExports => {
99
+ }, (moduleExports) => {
105
100
  if (moduleExports === undefined)
106
101
  return;
107
- this._diag.debug(`Removing patch for https@${version}`);
108
102
  this._unwrap(moduleExports, 'request');
109
103
  this._unwrap(moduleExports, 'get');
110
104
  this._unwrap(moduleExports.Server.prototype, 'emit');
@@ -438,7 +432,7 @@ class HttpInstrumentation extends instrumentation_1.InstrumentationBase {
438
432
  span.setAttributes(attributes).setStatus({
439
433
  code: utils.parseResponseStatus(api_1.SpanKind.SERVER, response.statusCode),
440
434
  });
441
- const route = attributes[semantic_conventions_1.SemanticAttributes.HTTP_ROUTE];
435
+ const route = attributes[semantic_conventions_1.SEMATTRS_HTTP_ROUTE];
442
436
  if (route) {
443
437
  span.updateName(`${request.method || 'GET'} ${route}`);
444
438
  }
@@ -1 +1 @@
1
- {"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/http.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,4CAe4B;AAC5B,8CAK6B;AAI7B,iCAAiC;AACjC,2BAA2B;AAS3B,iCAAiC;AACjC,uCAAoC;AACpC,oEAKwC;AACxC,8CAA2E;AAC3E,mCAAsC;AACtC,8EAAyE;AAEzE;;GAEG;AACH,MAAa,mBAAoB,SAAQ,qCAAyB;IAOhE,YAAY,MAAkC;QAC5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KAAK,CAAC,aAAa,CACzC,UAAU,EACV,MAAA,MAAA,MAAA,MAAM,CAAC,uBAAuB,0CAAE,MAAM,0CAAE,eAAe,mCAAI,EAAE,CAC9D;aACF;YACD,MAAM,EAAE;gBACN,qBAAqB,EAAE,KAAK,CAAC,aAAa,CACxC,SAAS,EACT,MAAA,MAAA,MAAA,MAAM,CAAC,uBAAuB,0CAAE,MAAM,0CAAE,cAAc,mCAAI,EAAE,CAC7D;gBACD,sBAAsB,EAAE,KAAK,CAAC,aAAa,CACzC,UAAU,EACV,MAAA,MAAA,MAAA,MAAM,CAAC,uBAAuB,0CAAE,MAAM,0CAAE,eAAe,mCAAI,EAAE,CAC9D;aACF;SACF,CAAC;IACJ,CAAC;CACF;AAzzBD,kDAyzBC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n context,\n HrTime,\n INVALID_SPAN_CONTEXT,\n propagation,\n ROOT_CONTEXT,\n Span,\n SpanKind,\n SpanOptions,\n SpanStatus,\n SpanStatusCode,\n trace,\n Histogram,\n MetricAttributes,\n ValueType,\n} from '@opentelemetry/api';\nimport {\n hrTime,\n hrTimeDuration,\n hrTimeToMilliseconds,\n suppressTracing,\n} from '@opentelemetry/core';\nimport type * as http from 'http';\nimport type * as https from 'https';\nimport { Socket } from 'net';\nimport * as semver from 'semver';\nimport * as url from 'url';\nimport {\n Err,\n Func,\n Http,\n HttpInstrumentationConfig,\n HttpRequestArgs,\n Https,\n} from './types';\nimport * as utils from './utils';\nimport { VERSION } from './version';\nimport {\n InstrumentationBase,\n InstrumentationNodeModuleDefinition,\n isWrapped,\n safeExecuteInTheMiddle,\n} from '@opentelemetry/instrumentation';\nimport { RPCMetadata, RPCType, setRPCMetadata } from '@opentelemetry/core';\nimport { errorMonitor } from 'events';\nimport { SemanticAttributes } from '@opentelemetry/semantic-conventions';\n\n/**\n * Http instrumentation instrumentation for Opentelemetry\n */\nexport class HttpInstrumentation extends InstrumentationBase<Http> {\n /** keep track on spans not ended */\n private readonly _spanNotEnded: WeakSet<Span> = new WeakSet<Span>();\n private _headerCapture;\n private _httpServerDurationHistogram!: Histogram;\n 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 'http.server.duration',\n {\n description: 'Measures the duration of inbound HTTP requests.',\n unit: 'ms',\n valueType: ValueType.DOUBLE,\n }\n );\n this._httpClientDurationHistogram = this.meter.createHistogram(\n 'http.client.duration',\n {\n description: 'Measures the duration of outbound HTTP requests.',\n unit: 'ms',\n valueType: ValueType.DOUBLE,\n }\n );\n }\n\n private _getConfig(): HttpInstrumentationConfig {\n return this._config;\n }\n\n override setConfig(config?: HttpInstrumentationConfig): void {\n super.setConfig(config);\n this._headerCapture = this._createHeaderCapture();\n }\n\n init(): [\n InstrumentationNodeModuleDefinition<Https>,\n InstrumentationNodeModuleDefinition<Http>,\n ] {\n return [this._getHttpsInstrumentation(), this._getHttpInstrumentation()];\n }\n\n private _getHttpInstrumentation() {\n const version = process.versions.node;\n return new InstrumentationNodeModuleDefinition<Http>(\n 'http',\n ['*'],\n moduleExports => {\n this._diag.debug(`Applying patch for http@${version}`);\n if (isWrapped(moduleExports.request)) {\n this._unwrap(moduleExports, 'request');\n }\n this._wrap(\n moduleExports,\n 'request',\n this._getPatchOutgoingRequestFunction('http')\n );\n if (isWrapped(moduleExports.get)) {\n this._unwrap(moduleExports, 'get');\n }\n this._wrap(\n moduleExports,\n 'get',\n this._getPatchOutgoingGetFunction(moduleExports.request)\n );\n if (isWrapped(moduleExports.Server.prototype.emit)) {\n this._unwrap(moduleExports.Server.prototype, 'emit');\n }\n this._wrap(\n moduleExports.Server.prototype,\n 'emit',\n this._getPatchIncomingRequestFunction('http')\n );\n return moduleExports;\n },\n moduleExports => {\n if (moduleExports === undefined) return;\n this._diag.debug(`Removing patch for http@${version}`);\n\n this._unwrap(moduleExports, 'request');\n this._unwrap(moduleExports, 'get');\n this._unwrap(moduleExports.Server.prototype, 'emit');\n }\n );\n }\n\n private _getHttpsInstrumentation() {\n const version = process.versions.node;\n return new InstrumentationNodeModuleDefinition<Https>(\n 'https',\n ['*'],\n moduleExports => {\n this._diag.debug(`Applying patch for https@${version}`);\n if (isWrapped(moduleExports.request)) {\n this._unwrap(moduleExports, 'request');\n }\n this._wrap(\n moduleExports,\n 'request',\n this._getPatchHttpsOutgoingRequestFunction('https')\n );\n if (isWrapped(moduleExports.get)) {\n this._unwrap(moduleExports, 'get');\n }\n this._wrap(\n moduleExports,\n 'get',\n this._getPatchHttpsOutgoingGetFunction(moduleExports.request)\n );\n if (isWrapped(moduleExports.Server.prototype.emit)) {\n this._unwrap(moduleExports.Server.prototype, 'emit');\n }\n this._wrap(\n moduleExports.Server.prototype,\n 'emit',\n this._getPatchIncomingRequestFunction('https')\n );\n return moduleExports;\n },\n moduleExports => {\n if (moduleExports === undefined) return;\n this._diag.debug(`Removing patch for https@${version}`);\n\n this._unwrap(moduleExports, 'request');\n this._unwrap(moduleExports, 'get');\n this._unwrap(moduleExports.Server.prototype, 'emit');\n }\n );\n }\n\n /**\n * Creates spans for incoming requests, restoring spans' context if applied.\n */\n protected _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 protected _getPatchOutgoingRequestFunction(component: 'http' | 'https') {\n return (original: Func<http.ClientRequest>): Func<http.ClientRequest> => {\n return this._outgoingRequestFunction(component, original);\n };\n }\n\n protected _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 // eslint-disable-next-line node/no-unsupported-features/node-builtins\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 // eslint-disable-next-line node/no-unsupported-features/node-builtins\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 // eslint-disable-next-line node/no-unsupported-features/node-builtins\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\n */\n private _traceClientRequest(\n request: http.ClientRequest,\n span: Span,\n startTime: HrTime,\n metricAttributes: MetricAttributes\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 utils.getOutgoingRequestAttributesOnResponse(response);\n span.setAttributes(responseAttributes);\n metricAttributes = Object.assign(\n metricAttributes,\n utils.getOutgoingRequestMetricAttributesOnResponse(responseAttributes)\n );\n\n if (this._getConfig().responseHook) {\n this._callResponseHook(span, response);\n }\n\n this._headerCapture.client.captureRequestHeaders(span, header =>\n request.getHeader(header)\n );\n this._headerCapture.client.captureResponseHeaders(\n span,\n header => response.headers[header]\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 status = {\n code: utils.parseResponseStatus(\n SpanKind.CLIENT,\n response.statusCode\n ),\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 // See https://github.com/open-telemetry/opentelemetry-js/pull/3625#issuecomment-1475673533\n if (semver.lt(process.version, '16.0.0')) {\n response.on('close', endHandler);\n }\n response.on(errorMonitor, (error: Err) => {\n this._diag.debug('outgoingRequest on error()', error);\n if (responseFinished) {\n return;\n }\n responseFinished = true;\n utils.setSpanWithError(span, error);\n span.setStatus({\n code: SpanStatusCode.ERROR,\n message: error.message,\n });\n this._closeHttpSpan(\n span,\n SpanKind.CLIENT,\n startTime,\n metricAttributes\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 utils.setSpanWithError(span, error);\n this._closeHttpSpan(span, SpanKind.CLIENT, startTime, metricAttributes);\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 pathname = request.url\n ? url.parse(request.url).pathname || '/'\n : '/';\n const method = request.method || 'GET';\n\n instrumentation._diag.debug(\n `${component} instrumentation incomingRequest`\n );\n\n if (\n utils.isIgnored(\n pathname,\n instrumentation._getConfig().ignoreIncomingPaths,\n (e: unknown) =>\n instrumentation._diag.error('caught ignoreIncomingPaths error: ', e)\n ) ||\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 = utils.getIncomingRequestAttributes(request, {\n component: component,\n serverName: instrumentation._getConfig().serverName,\n hookAttributes: instrumentation._callStartSpanHook(\n request,\n instrumentation._getConfig().startIncomingSpanHook\n ),\n });\n\n const spanOptions: SpanOptions = {\n kind: SpanKind.SERVER,\n attributes: spanAttributes,\n };\n\n const startTime = hrTime();\n const metricAttributes =\n utils.getIncomingRequestMetricAttributes(spanAttributes);\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 instrumentation._headerCapture.server.captureRequestHeaders(\n span,\n header => request.headers[header]\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 utils.setSpanWithError(span, error);\n instrumentation._closeHttpSpan(\n span,\n SpanKind.SERVER,\n startTime,\n metricAttributes\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 (!utils.isValidOptionsType(options)) {\n return original.apply(this, [options, ...args]);\n }\n const extraOptions =\n typeof args[0] === 'object' &&\n (typeof options === 'string' || options instanceof url.URL)\n ? (args.shift() as http.RequestOptions)\n : undefined;\n const { origin, pathname, method, optionsParsed } = utils.getRequestInfo(\n options,\n extraOptions\n );\n /**\n * Node 8's https module directly call the http one so to avoid creating\n * 2 span for the same request we need to check that the protocol is correct\n * See: https://github.com/nodejs/node/blob/v8.17.0/lib/https.js#L245\n */\n if (\n component === 'http' &&\n semver.lt(process.version, '9.0.0') &&\n optionsParsed.protocol === 'https:'\n ) {\n return original.apply(this, [optionsParsed, ...args]);\n }\n\n if (\n utils.isIgnored(\n origin + pathname,\n instrumentation._getConfig().ignoreOutgoingUrls,\n (e: unknown) =>\n instrumentation._diag.error('caught ignoreOutgoingUrls error: ', e)\n ) ||\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 } = utils.extractHostnameAndPort(optionsParsed);\n\n const attributes = utils.getOutgoingRequestAttributes(optionsParsed, {\n component,\n port,\n hostname,\n hookAttributes: instrumentation._callStartSpanHook(\n optionsParsed,\n instrumentation._getConfig().startOutgoingSpanHook\n ),\n });\n\n const startTime = hrTime();\n const metricAttributes: MetricAttributes =\n utils.getOutgoingRequestMetricAttributes(attributes);\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 () => original.apply(this, [optionsParsed, ...args]),\n error => {\n if (error) {\n utils.setSpanWithError(span, error);\n instrumentation._closeHttpSpan(\n span,\n SpanKind.CLIENT,\n startTime,\n metricAttributes\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: MetricAttributes,\n startTime: HrTime\n ) {\n const attributes = utils.getIncomingRequestAttributesOnResponse(\n request,\n response\n );\n metricAttributes = Object.assign(\n metricAttributes,\n utils.getIncomingRequestMetricAttributesOnResponse(attributes)\n );\n\n this._headerCapture.server.captureResponseHeaders(span, header =>\n response.getHeader(header)\n );\n\n span.setAttributes(attributes).setStatus({\n code: utils.parseResponseStatus(SpanKind.SERVER, response.statusCode),\n });\n\n const route = attributes[SemanticAttributes.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 _onServerResponseError(\n span: Span,\n metricAttributes: MetricAttributes,\n startTime: HrTime,\n error: Err\n ) {\n utils.setSpanWithError(span, error);\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 (requireParent === true && currentSpan === undefined) {\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: MetricAttributes\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._httpServerDurationHistogram.record(duration, metricAttributes);\n } else if (spanKind === SpanKind.CLIENT) {\n this._httpClientDurationHistogram.record(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: utils.headerCapture(\n 'request',\n config.headersToSpanAttributes?.client?.requestHeaders ?? []\n ),\n captureResponseHeaders: utils.headerCapture(\n 'response',\n config.headersToSpanAttributes?.client?.responseHeaders ?? []\n ),\n },\n server: {\n captureRequestHeaders: utils.headerCapture(\n 'request',\n config.headersToSpanAttributes?.server?.requestHeaders ?? []\n ),\n captureResponseHeaders: utils.headerCapture(\n 'response',\n config.headersToSpanAttributes?.server?.responseHeaders ?? []\n ),\n },\n };\n }\n}\n"]}
1
+ {"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/http.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,4CAe4B;AAC5B,8CAK6B;AAI7B,iCAAiC;AACjC,2BAA2B;AAS3B,iCAAiC;AACjC,uCAAoC;AACpC,oEAKwC;AACxC,8CAA2E;AAC3E,mCAAsC;AACtC,8EAA0E;AAE1E;;GAEG;AACH,MAAa,mBAAoB,SAAQ,qCAAmB;IAO1D,YAAY,MAAkC;QAC5C,KAAK,CAAC,qCAAqC,EAAE,iBAAO,EAAE,MAAM,CAAC,CAAC;QAPhE,oCAAoC;QACnB,kBAAa,GAAkB,IAAI,OAAO,EAAQ,CAAC;QAOlE,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,oBAAoB,EAAE,CAAC;IACpD,CAAC;IAEkB,wBAAwB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C,IAAI,CAAC,UAAU,EAAE,CAAC,WAAY,CAAC,IAAI,EAAE,OAAO,CAAC,EACnD,GAAG,EAAE,GAAE,CAAC,EACR,IAAI,CACL,CAAC;IACJ,CAAC;IAEO,kBAAkB,CACxB,OAAmD,EACnD,QAA8B;QAE9B,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE;YAClC,OAAO,IAAA,wCAAsB,EAC3B,GAAG,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,EACvB,GAAG,EAAE,GAAE,CAAC,EACR,IAAI,CACL,CAAC;SACH;IACH,CAAC;IAEO,oBAAoB;;QAC1B,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;QAEjC,OAAO;YACL,MAAM,EAAE;gBACN,qBAAqB,EAAE,KAAK,CAAC,aAAa,CACxC,SAAS,EACT,MAAA,MAAA,MAAA,MAAM,CAAC,uBAAuB,0CAAE,MAAM,0CAAE,cAAc,mCAAI,EAAE,CAC7D;gBACD,sBAAsB,EAAE,KAAK,CAAC,aAAa,CACzC,UAAU,EACV,MAAA,MAAA,MAAA,MAAM,CAAC,uBAAuB,0CAAE,MAAM,0CAAE,eAAe,mCAAI,EAAE,CAC9D;aACF;YACD,MAAM,EAAE;gBACN,qBAAqB,EAAE,KAAK,CAAC,aAAa,CACxC,SAAS,EACT,MAAA,MAAA,MAAA,MAAM,CAAC,uBAAuB,0CAAE,MAAM,0CAAE,cAAc,mCAAI,EAAE,CAC7D;gBACD,sBAAsB,EAAE,KAAK,CAAC,aAAa,CACzC,UAAU,EACV,MAAA,MAAA,MAAA,MAAM,CAAC,uBAAuB,0CAAE,MAAM,0CAAE,eAAe,mCAAI,EAAE,CAC9D;aACF;SACF,CAAC;IACJ,CAAC;CACF;AAnzBD,kDAmzBC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n context,\n HrTime,\n INVALID_SPAN_CONTEXT,\n propagation,\n ROOT_CONTEXT,\n Span,\n SpanKind,\n SpanOptions,\n SpanStatus,\n SpanStatusCode,\n trace,\n Histogram,\n MetricAttributes,\n ValueType,\n} from '@opentelemetry/api';\nimport {\n hrTime,\n hrTimeDuration,\n hrTimeToMilliseconds,\n suppressTracing,\n} from '@opentelemetry/core';\nimport type * as http from 'http';\nimport type * as https from 'https';\nimport { Socket } from 'net';\nimport * as semver from 'semver';\nimport * as url from 'url';\nimport {\n Err,\n Func,\n Http,\n HttpInstrumentationConfig,\n HttpRequestArgs,\n Https,\n} from './types';\nimport * as utils from './utils';\nimport { VERSION } from './version';\nimport {\n InstrumentationBase,\n InstrumentationNodeModuleDefinition,\n isWrapped,\n safeExecuteInTheMiddle,\n} from '@opentelemetry/instrumentation';\nimport { RPCMetadata, RPCType, setRPCMetadata } from '@opentelemetry/core';\nimport { errorMonitor } from 'events';\nimport { SEMATTRS_HTTP_ROUTE } from '@opentelemetry/semantic-conventions';\n\n/**\n * Http instrumentation instrumentation for Opentelemetry\n */\nexport class HttpInstrumentation extends InstrumentationBase {\n /** keep track on spans not ended */\n private readonly _spanNotEnded: WeakSet<Span> = new WeakSet<Span>();\n private _headerCapture;\n private _httpServerDurationHistogram!: Histogram;\n 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 'http.server.duration',\n {\n description: 'Measures the duration of inbound HTTP requests.',\n unit: 'ms',\n valueType: ValueType.DOUBLE,\n }\n );\n this._httpClientDurationHistogram = this.meter.createHistogram(\n 'http.client.duration',\n {\n description: 'Measures the duration of outbound HTTP requests.',\n unit: 'ms',\n valueType: ValueType.DOUBLE,\n }\n );\n }\n\n private _getConfig(): HttpInstrumentationConfig {\n return this._config;\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 if (isWrapped(moduleExports.request)) {\n this._unwrap(moduleExports, 'request');\n }\n this._wrap(\n moduleExports,\n 'request',\n this._getPatchOutgoingRequestFunction('http')\n );\n if (isWrapped(moduleExports.get)) {\n this._unwrap(moduleExports, 'get');\n }\n this._wrap(\n moduleExports,\n 'get',\n this._getPatchOutgoingGetFunction(moduleExports.request)\n );\n if (isWrapped(moduleExports.Server.prototype.emit)) {\n this._unwrap(moduleExports.Server.prototype, 'emit');\n }\n this._wrap(\n moduleExports.Server.prototype,\n 'emit',\n this._getPatchIncomingRequestFunction('http')\n );\n return moduleExports;\n },\n (moduleExports: Http) => {\n if (moduleExports === undefined) return;\n\n this._unwrap(moduleExports, 'request');\n this._unwrap(moduleExports, 'get');\n this._unwrap(moduleExports.Server.prototype, 'emit');\n }\n );\n }\n\n private _getHttpsInstrumentation() {\n return new InstrumentationNodeModuleDefinition(\n 'https',\n ['*'],\n (moduleExports: Https): Https => {\n if (isWrapped(moduleExports.request)) {\n this._unwrap(moduleExports, 'request');\n }\n this._wrap(\n moduleExports,\n 'request',\n this._getPatchHttpsOutgoingRequestFunction('https')\n );\n if (isWrapped(moduleExports.get)) {\n this._unwrap(moduleExports, 'get');\n }\n this._wrap(\n moduleExports,\n 'get',\n this._getPatchHttpsOutgoingGetFunction(moduleExports.request)\n );\n if (isWrapped(moduleExports.Server.prototype.emit)) {\n this._unwrap(moduleExports.Server.prototype, 'emit');\n }\n this._wrap(\n moduleExports.Server.prototype,\n 'emit',\n this._getPatchIncomingRequestFunction('https')\n );\n return moduleExports;\n },\n (moduleExports: Https) => {\n if (moduleExports === undefined) return;\n\n this._unwrap(moduleExports, 'request');\n this._unwrap(moduleExports, 'get');\n this._unwrap(moduleExports.Server.prototype, 'emit');\n }\n );\n }\n\n /**\n * Creates spans for incoming requests, restoring spans' context if applied.\n */\n protected _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 protected _getPatchOutgoingRequestFunction(component: 'http' | 'https') {\n return (original: Func<http.ClientRequest>): Func<http.ClientRequest> => {\n return this._outgoingRequestFunction(component, original);\n };\n }\n\n protected _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 // eslint-disable-next-line node/no-unsupported-features/node-builtins\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 // eslint-disable-next-line node/no-unsupported-features/node-builtins\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 // eslint-disable-next-line node/no-unsupported-features/node-builtins\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\n */\n private _traceClientRequest(\n request: http.ClientRequest,\n span: Span,\n startTime: HrTime,\n metricAttributes: MetricAttributes\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 utils.getOutgoingRequestAttributesOnResponse(response);\n span.setAttributes(responseAttributes);\n metricAttributes = Object.assign(\n metricAttributes,\n utils.getOutgoingRequestMetricAttributesOnResponse(responseAttributes)\n );\n\n if (this._getConfig().responseHook) {\n this._callResponseHook(span, response);\n }\n\n this._headerCapture.client.captureRequestHeaders(span, header =>\n request.getHeader(header)\n );\n this._headerCapture.client.captureResponseHeaders(\n span,\n header => response.headers[header]\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 status = {\n code: utils.parseResponseStatus(\n SpanKind.CLIENT,\n response.statusCode\n ),\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 // See https://github.com/open-telemetry/opentelemetry-js/pull/3625#issuecomment-1475673533\n if (semver.lt(process.version, '16.0.0')) {\n response.on('close', endHandler);\n }\n response.on(errorMonitor, (error: Err) => {\n this._diag.debug('outgoingRequest on error()', error);\n if (responseFinished) {\n return;\n }\n responseFinished = true;\n utils.setSpanWithError(span, error);\n span.setStatus({\n code: SpanStatusCode.ERROR,\n message: error.message,\n });\n this._closeHttpSpan(\n span,\n SpanKind.CLIENT,\n startTime,\n metricAttributes\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 utils.setSpanWithError(span, error);\n this._closeHttpSpan(span, SpanKind.CLIENT, startTime, metricAttributes);\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 pathname = request.url\n ? url.parse(request.url).pathname || '/'\n : '/';\n const method = request.method || 'GET';\n\n instrumentation._diag.debug(\n `${component} instrumentation incomingRequest`\n );\n\n if (\n utils.isIgnored(\n pathname,\n instrumentation._getConfig().ignoreIncomingPaths,\n (e: unknown) =>\n instrumentation._diag.error('caught ignoreIncomingPaths error: ', e)\n ) ||\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 = utils.getIncomingRequestAttributes(request, {\n component: component,\n serverName: instrumentation._getConfig().serverName,\n hookAttributes: instrumentation._callStartSpanHook(\n request,\n instrumentation._getConfig().startIncomingSpanHook\n ),\n });\n\n const spanOptions: SpanOptions = {\n kind: SpanKind.SERVER,\n attributes: spanAttributes,\n };\n\n const startTime = hrTime();\n const metricAttributes =\n utils.getIncomingRequestMetricAttributes(spanAttributes);\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 instrumentation._headerCapture.server.captureRequestHeaders(\n span,\n header => request.headers[header]\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 utils.setSpanWithError(span, error);\n instrumentation._closeHttpSpan(\n span,\n SpanKind.SERVER,\n startTime,\n metricAttributes\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 (!utils.isValidOptionsType(options)) {\n return original.apply(this, [options, ...args]);\n }\n const extraOptions =\n typeof args[0] === 'object' &&\n (typeof options === 'string' || options instanceof url.URL)\n ? (args.shift() as http.RequestOptions)\n : undefined;\n const { origin, pathname, method, optionsParsed } = utils.getRequestInfo(\n options,\n extraOptions\n );\n /**\n * Node 8's https module directly call the http one so to avoid creating\n * 2 span for the same request we need to check that the protocol is correct\n * See: https://github.com/nodejs/node/blob/v8.17.0/lib/https.js#L245\n */\n if (\n component === 'http' &&\n semver.lt(process.version, '9.0.0') &&\n optionsParsed.protocol === 'https:'\n ) {\n return original.apply(this, [optionsParsed, ...args]);\n }\n\n if (\n utils.isIgnored(\n origin + pathname,\n instrumentation._getConfig().ignoreOutgoingUrls,\n (e: unknown) =>\n instrumentation._diag.error('caught ignoreOutgoingUrls error: ', e)\n ) ||\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 } = utils.extractHostnameAndPort(optionsParsed);\n\n const attributes = utils.getOutgoingRequestAttributes(optionsParsed, {\n component,\n port,\n hostname,\n hookAttributes: instrumentation._callStartSpanHook(\n optionsParsed,\n instrumentation._getConfig().startOutgoingSpanHook\n ),\n });\n\n const startTime = hrTime();\n const metricAttributes: MetricAttributes =\n utils.getOutgoingRequestMetricAttributes(attributes);\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 () => original.apply(this, [optionsParsed, ...args]),\n error => {\n if (error) {\n utils.setSpanWithError(span, error);\n instrumentation._closeHttpSpan(\n span,\n SpanKind.CLIENT,\n startTime,\n metricAttributes\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: MetricAttributes,\n startTime: HrTime\n ) {\n const attributes = utils.getIncomingRequestAttributesOnResponse(\n request,\n response\n );\n metricAttributes = Object.assign(\n metricAttributes,\n utils.getIncomingRequestMetricAttributesOnResponse(attributes)\n );\n\n this._headerCapture.server.captureResponseHeaders(span, header =>\n response.getHeader(header)\n );\n\n span.setAttributes(attributes).setStatus({\n code: utils.parseResponseStatus(SpanKind.SERVER, response.statusCode),\n });\n\n const route = attributes[SEMATTRS_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 _onServerResponseError(\n span: Span,\n metricAttributes: MetricAttributes,\n startTime: HrTime,\n error: Err\n ) {\n utils.setSpanWithError(span, error);\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 (requireParent === true && currentSpan === undefined) {\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: MetricAttributes\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._httpServerDurationHistogram.record(duration, metricAttributes);\n } else if (spanKind === SpanKind.CLIENT) {\n this._httpClientDurationHistogram.record(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: utils.headerCapture(\n 'request',\n config.headersToSpanAttributes?.client?.requestHeaders ?? []\n ),\n captureResponseHeaders: utils.headerCapture(\n 'response',\n config.headersToSpanAttributes?.client?.responseHeaders ?? []\n ),\n },\n server: {\n captureRequestHeaders: utils.headerCapture(\n 'request',\n config.headersToSpanAttributes?.server?.requestHeaders ?? []\n ),\n captureResponseHeaders: utils.headerCapture(\n 'response',\n config.headersToSpanAttributes?.server?.responseHeaders ?? []\n ),\n },\n };\n }\n}\n"]}
@@ -85,7 +85,7 @@ export declare const getOutgoingRequestMetricAttributes: (spanAttributes: SpanAt
85
85
  * Returns attributes related to the kind of HTTP protocol used
86
86
  * @param {string} [kind] Kind of HTTP protocol used: "1.0", "1.1", "2", "SPDY" or "QUIC".
87
87
  */
88
- export declare const getAttributesFromHttpKind: (kind?: string | undefined) => SpanAttributes;
88
+ export declare const setAttributesFromHttpKind: (kind: string | undefined, attributes: SpanAttributes) => void;
89
89
  /**
90
90
  * Returns outgoing request attributes scoped to the response data
91
91
  * @param {IncomingMessage} response the response object
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.headerCapture = exports.getIncomingRequestMetricAttributesOnResponse = exports.getIncomingRequestAttributesOnResponse = exports.getIncomingRequestMetricAttributes = exports.getIncomingRequestAttributes = exports.getOutgoingRequestMetricAttributesOnResponse = exports.getOutgoingRequestAttributesOnResponse = exports.getAttributesFromHttpKind = exports.getOutgoingRequestMetricAttributes = exports.getOutgoingRequestAttributes = exports.extractHostnameAndPort = exports.isValidOptionsType = exports.getRequestInfo = exports.isCompressed = exports.setResponseContentLengthAttribute = exports.setRequestContentLengthAttribute = exports.setSpanWithError = exports.isIgnored = exports.satisfiesPattern = exports.parseResponseStatus = exports.getAbsoluteUrl = void 0;
3
+ exports.headerCapture = exports.getIncomingRequestMetricAttributesOnResponse = exports.getIncomingRequestAttributesOnResponse = exports.getIncomingRequestMetricAttributes = exports.getIncomingRequestAttributes = exports.getOutgoingRequestMetricAttributesOnResponse = exports.getOutgoingRequestAttributesOnResponse = exports.setAttributesFromHttpKind = exports.getOutgoingRequestMetricAttributes = exports.getOutgoingRequestAttributes = exports.extractHostnameAndPort = exports.isValidOptionsType = exports.getRequestInfo = exports.isCompressed = exports.setResponseContentLengthAttribute = exports.setRequestContentLengthAttribute = exports.setSpanWithError = exports.isIgnored = exports.satisfiesPattern = exports.parseResponseStatus = exports.getAbsoluteUrl = void 0;
4
4
  /*
5
5
  * Copyright The OpenTelemetry Authors
6
6
  *
@@ -111,10 +111,8 @@ exports.isIgnored = isIgnored;
111
111
  */
112
112
  const setSpanWithError = (span, error) => {
113
113
  const message = error.message;
114
- span.setAttributes({
115
- [AttributeNames_1.AttributeNames.HTTP_ERROR_NAME]: error.name,
116
- [AttributeNames_1.AttributeNames.HTTP_ERROR_MESSAGE]: message,
117
- });
114
+ span.setAttribute(AttributeNames_1.AttributeNames.HTTP_ERROR_NAME, error.name);
115
+ span.setAttribute(AttributeNames_1.AttributeNames.HTTP_ERROR_MESSAGE, message);
118
116
  span.setStatus({ code: api_1.SpanStatusCode.ERROR, message });
119
117
  span.recordException(error);
120
118
  };
@@ -129,11 +127,10 @@ const setRequestContentLengthAttribute = (request, attributes) => {
129
127
  if (length === null)
130
128
  return;
131
129
  if ((0, exports.isCompressed)(request.headers)) {
132
- attributes[semantic_conventions_1.SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH] = length;
130
+ attributes[semantic_conventions_1.SEMATTRS_HTTP_REQUEST_CONTENT_LENGTH] = length;
133
131
  }
134
132
  else {
135
- attributes[semantic_conventions_1.SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH_UNCOMPRESSED] =
136
- length;
133
+ attributes[semantic_conventions_1.SEMATTRS_HTTP_REQUEST_CONTENT_LENGTH_UNCOMPRESSED] = length;
137
134
  }
138
135
  };
139
136
  exports.setRequestContentLengthAttribute = setRequestContentLengthAttribute;
@@ -147,11 +144,10 @@ const setResponseContentLengthAttribute = (response, attributes) => {
147
144
  if (length === null)
148
145
  return;
149
146
  if ((0, exports.isCompressed)(response.headers)) {
150
- attributes[semantic_conventions_1.SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH] = length;
147
+ attributes[semantic_conventions_1.SEMATTRS_HTTP_RESPONSE_CONTENT_LENGTH] = length;
151
148
  }
152
149
  else {
153
- attributes[semantic_conventions_1.SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH_UNCOMPRESSED] =
154
- length;
150
+ attributes[semantic_conventions_1.SEMATTRS_HTTP_RESPONSE_CONTENT_LENGTH_UNCOMPRESSED] = length;
155
151
  }
156
152
  };
157
153
  exports.setResponseContentLengthAttribute = setResponseContentLengthAttribute;
@@ -265,7 +261,7 @@ exports.extractHostnameAndPort = extractHostnameAndPort;
265
261
  * @param {{ component: string, hostname: string, hookAttributes?: SpanAttributes }} options used to pass data needed to create attributes
266
262
  */
267
263
  const getOutgoingRequestAttributes = (requestOptions, options) => {
268
- var _a, _b;
264
+ var _a;
269
265
  const hostname = options.hostname;
270
266
  const port = options.port;
271
267
  const requestMethod = requestOptions.method;
@@ -273,14 +269,14 @@ const getOutgoingRequestAttributes = (requestOptions, options) => {
273
269
  const headers = requestOptions.headers || {};
274
270
  const userAgent = headers['user-agent'];
275
271
  const attributes = {
276
- [semantic_conventions_1.SemanticAttributes.HTTP_URL]: (0, exports.getAbsoluteUrl)(requestOptions, headers, `${options.component}:`),
277
- [semantic_conventions_1.SemanticAttributes.HTTP_METHOD]: method,
278
- [semantic_conventions_1.SemanticAttributes.HTTP_TARGET]: requestOptions.path || '/',
279
- [semantic_conventions_1.SemanticAttributes.NET_PEER_NAME]: hostname,
280
- [semantic_conventions_1.SemanticAttributes.HTTP_HOST]: (_b = (_a = requestOptions.headers) === null || _a === void 0 ? void 0 : _a.host) !== null && _b !== void 0 ? _b : `${hostname}:${port}`,
272
+ [semantic_conventions_1.SEMATTRS_HTTP_URL]: (0, exports.getAbsoluteUrl)(requestOptions, headers, `${options.component}:`),
273
+ [semantic_conventions_1.SEMATTRS_HTTP_METHOD]: method,
274
+ [semantic_conventions_1.SEMATTRS_HTTP_TARGET]: requestOptions.path || '/',
275
+ [semantic_conventions_1.SEMATTRS_NET_PEER_NAME]: hostname,
276
+ [semantic_conventions_1.SEMATTRS_HTTP_HOST]: (_a = headers.host) !== null && _a !== void 0 ? _a : `${hostname}:${port}`,
281
277
  };
282
278
  if (userAgent !== undefined) {
283
- attributes[semantic_conventions_1.SemanticAttributes.HTTP_USER_AGENT] = userAgent;
279
+ attributes[semantic_conventions_1.SEMATTRS_HTTP_USER_AGENT] = userAgent;
284
280
  }
285
281
  return Object.assign(attributes, options.hookAttributes);
286
282
  };
@@ -291,11 +287,10 @@ exports.getOutgoingRequestAttributes = getOutgoingRequestAttributes;
291
287
  */
292
288
  const getOutgoingRequestMetricAttributes = (spanAttributes) => {
293
289
  const metricAttributes = {};
294
- metricAttributes[semantic_conventions_1.SemanticAttributes.HTTP_METHOD] =
295
- spanAttributes[semantic_conventions_1.SemanticAttributes.HTTP_METHOD];
296
- metricAttributes[semantic_conventions_1.SemanticAttributes.NET_PEER_NAME] =
297
- spanAttributes[semantic_conventions_1.SemanticAttributes.NET_PEER_NAME];
298
- //TODO: http.url attribute, it should susbtitute any parameters to avoid high cardinality.
290
+ metricAttributes[semantic_conventions_1.SEMATTRS_HTTP_METHOD] = spanAttributes[semantic_conventions_1.SEMATTRS_HTTP_METHOD];
291
+ metricAttributes[semantic_conventions_1.SEMATTRS_NET_PEER_NAME] =
292
+ spanAttributes[semantic_conventions_1.SEMATTRS_NET_PEER_NAME];
293
+ //TODO: http.url attribute, it should substitute any parameters to avoid high cardinality.
299
294
  return metricAttributes;
300
295
  };
301
296
  exports.getOutgoingRequestMetricAttributes = getOutgoingRequestMetricAttributes;
@@ -303,20 +298,18 @@ exports.getOutgoingRequestMetricAttributes = getOutgoingRequestMetricAttributes;
303
298
  * Returns attributes related to the kind of HTTP protocol used
304
299
  * @param {string} [kind] Kind of HTTP protocol used: "1.0", "1.1", "2", "SPDY" or "QUIC".
305
300
  */
306
- const getAttributesFromHttpKind = (kind) => {
307
- const attributes = {};
301
+ const setAttributesFromHttpKind = (kind, attributes) => {
308
302
  if (kind) {
309
- attributes[semantic_conventions_1.SemanticAttributes.HTTP_FLAVOR] = kind;
303
+ attributes[semantic_conventions_1.SEMATTRS_HTTP_FLAVOR] = kind;
310
304
  if (kind.toUpperCase() !== 'QUIC') {
311
- attributes[semantic_conventions_1.SemanticAttributes.NET_TRANSPORT] = semantic_conventions_1.NetTransportValues.IP_TCP;
305
+ attributes[semantic_conventions_1.SEMATTRS_NET_TRANSPORT] = semantic_conventions_1.NETTRANSPORTVALUES_IP_TCP;
312
306
  }
313
307
  else {
314
- attributes[semantic_conventions_1.SemanticAttributes.NET_TRANSPORT] = semantic_conventions_1.NetTransportValues.IP_UDP;
308
+ attributes[semantic_conventions_1.SEMATTRS_NET_TRANSPORT] = semantic_conventions_1.NETTRANSPORTVALUES_IP_UDP;
315
309
  }
316
310
  }
317
- return attributes;
318
311
  };
319
- exports.getAttributesFromHttpKind = getAttributesFromHttpKind;
312
+ exports.setAttributesFromHttpKind = setAttributesFromHttpKind;
320
313
  /**
321
314
  * Returns outgoing request attributes scoped to the response data
322
315
  * @param {IncomingMessage} response the response object
@@ -327,16 +320,16 @@ const getOutgoingRequestAttributesOnResponse = (response) => {
327
320
  const attributes = {};
328
321
  if (socket) {
329
322
  const { remoteAddress, remotePort } = socket;
330
- attributes[semantic_conventions_1.SemanticAttributes.NET_PEER_IP] = remoteAddress;
331
- attributes[semantic_conventions_1.SemanticAttributes.NET_PEER_PORT] = remotePort;
323
+ attributes[semantic_conventions_1.SEMATTRS_NET_PEER_IP] = remoteAddress;
324
+ attributes[semantic_conventions_1.SEMATTRS_NET_PEER_PORT] = remotePort;
332
325
  }
333
326
  (0, exports.setResponseContentLengthAttribute)(response, attributes);
334
327
  if (statusCode) {
335
- attributes[semantic_conventions_1.SemanticAttributes.HTTP_STATUS_CODE] = statusCode;
328
+ attributes[semantic_conventions_1.SEMATTRS_HTTP_STATUS_CODE] = statusCode;
336
329
  attributes[AttributeNames_1.AttributeNames.HTTP_STATUS_TEXT] = (statusMessage || '').toUpperCase();
337
330
  }
338
- const httpKindAttributes = (0, exports.getAttributesFromHttpKind)(httpVersion);
339
- return Object.assign(attributes, httpKindAttributes);
331
+ (0, exports.setAttributesFromHttpKind)(httpVersion, attributes);
332
+ return attributes;
340
333
  };
341
334
  exports.getOutgoingRequestAttributesOnResponse = getOutgoingRequestAttributesOnResponse;
342
335
  /**
@@ -345,12 +338,11 @@ exports.getOutgoingRequestAttributesOnResponse = getOutgoingRequestAttributesOnR
345
338
  */
346
339
  const getOutgoingRequestMetricAttributesOnResponse = (spanAttributes) => {
347
340
  const metricAttributes = {};
348
- metricAttributes[semantic_conventions_1.SemanticAttributes.NET_PEER_PORT] =
349
- spanAttributes[semantic_conventions_1.SemanticAttributes.NET_PEER_PORT];
350
- metricAttributes[semantic_conventions_1.SemanticAttributes.HTTP_STATUS_CODE] =
351
- spanAttributes[semantic_conventions_1.SemanticAttributes.HTTP_STATUS_CODE];
352
- metricAttributes[semantic_conventions_1.SemanticAttributes.HTTP_FLAVOR] =
353
- spanAttributes[semantic_conventions_1.SemanticAttributes.HTTP_FLAVOR];
341
+ metricAttributes[semantic_conventions_1.SEMATTRS_NET_PEER_PORT] =
342
+ spanAttributes[semantic_conventions_1.SEMATTRS_NET_PEER_PORT];
343
+ metricAttributes[semantic_conventions_1.SEMATTRS_HTTP_STATUS_CODE] =
344
+ spanAttributes[semantic_conventions_1.SEMATTRS_HTTP_STATUS_CODE];
345
+ metricAttributes[semantic_conventions_1.SEMATTRS_HTTP_FLAVOR] = spanAttributes[semantic_conventions_1.SEMATTRS_HTTP_FLAVOR];
354
346
  return metricAttributes;
355
347
  };
356
348
  exports.getOutgoingRequestMetricAttributesOnResponse = getOutgoingRequestMetricAttributesOnResponse;
@@ -372,27 +364,27 @@ const getIncomingRequestAttributes = (request, options) => {
372
364
  'localhost';
373
365
  const serverName = options.serverName;
374
366
  const attributes = {
375
- [semantic_conventions_1.SemanticAttributes.HTTP_URL]: (0, exports.getAbsoluteUrl)(requestUrl, headers, `${options.component}:`),
376
- [semantic_conventions_1.SemanticAttributes.HTTP_HOST]: host,
377
- [semantic_conventions_1.SemanticAttributes.NET_HOST_NAME]: hostname,
378
- [semantic_conventions_1.SemanticAttributes.HTTP_METHOD]: method,
379
- [semantic_conventions_1.SemanticAttributes.HTTP_SCHEME]: options.component,
367
+ [semantic_conventions_1.SEMATTRS_HTTP_URL]: (0, exports.getAbsoluteUrl)(requestUrl, headers, `${options.component}:`),
368
+ [semantic_conventions_1.SEMATTRS_HTTP_HOST]: host,
369
+ [semantic_conventions_1.SEMATTRS_NET_HOST_NAME]: hostname,
370
+ [semantic_conventions_1.SEMATTRS_HTTP_METHOD]: method,
371
+ [semantic_conventions_1.SEMATTRS_HTTP_SCHEME]: options.component,
380
372
  };
381
373
  if (typeof ips === 'string') {
382
- attributes[semantic_conventions_1.SemanticAttributes.HTTP_CLIENT_IP] = ips.split(',')[0];
374
+ attributes[semantic_conventions_1.SEMATTRS_HTTP_CLIENT_IP] = ips.split(',')[0];
383
375
  }
384
376
  if (typeof serverName === 'string') {
385
- attributes[semantic_conventions_1.SemanticAttributes.HTTP_SERVER_NAME] = serverName;
377
+ attributes[semantic_conventions_1.SEMATTRS_HTTP_SERVER_NAME] = serverName;
386
378
  }
387
379
  if (requestUrl) {
388
- attributes[semantic_conventions_1.SemanticAttributes.HTTP_TARGET] = requestUrl.path || '/';
380
+ attributes[semantic_conventions_1.SEMATTRS_HTTP_TARGET] = requestUrl.path || '/';
389
381
  }
390
382
  if (userAgent !== undefined) {
391
- attributes[semantic_conventions_1.SemanticAttributes.HTTP_USER_AGENT] = userAgent;
383
+ attributes[semantic_conventions_1.SEMATTRS_HTTP_USER_AGENT] = userAgent;
392
384
  }
393
385
  (0, exports.setRequestContentLengthAttribute)(request, attributes);
394
- const httpKindAttributes = (0, exports.getAttributesFromHttpKind)(httpVersion);
395
- return Object.assign(attributes, httpKindAttributes, options.hookAttributes);
386
+ (0, exports.setAttributesFromHttpKind)(httpVersion, attributes);
387
+ return Object.assign(attributes, options.hookAttributes);
396
388
  };
397
389
  exports.getIncomingRequestAttributes = getIncomingRequestAttributes;
398
390
  /**
@@ -402,15 +394,12 @@ exports.getIncomingRequestAttributes = getIncomingRequestAttributes;
402
394
  */
403
395
  const getIncomingRequestMetricAttributes = (spanAttributes) => {
404
396
  const metricAttributes = {};
405
- metricAttributes[semantic_conventions_1.SemanticAttributes.HTTP_SCHEME] =
406
- spanAttributes[semantic_conventions_1.SemanticAttributes.HTTP_SCHEME];
407
- metricAttributes[semantic_conventions_1.SemanticAttributes.HTTP_METHOD] =
408
- spanAttributes[semantic_conventions_1.SemanticAttributes.HTTP_METHOD];
409
- metricAttributes[semantic_conventions_1.SemanticAttributes.NET_HOST_NAME] =
410
- spanAttributes[semantic_conventions_1.SemanticAttributes.NET_HOST_NAME];
411
- metricAttributes[semantic_conventions_1.SemanticAttributes.HTTP_FLAVOR] =
412
- spanAttributes[semantic_conventions_1.SemanticAttributes.HTTP_FLAVOR];
413
- //TODO: http.target attribute, it should susbtitute any parameters to avoid high cardinality.
397
+ metricAttributes[semantic_conventions_1.SEMATTRS_HTTP_SCHEME] = spanAttributes[semantic_conventions_1.SEMATTRS_HTTP_SCHEME];
398
+ metricAttributes[semantic_conventions_1.SEMATTRS_HTTP_METHOD] = spanAttributes[semantic_conventions_1.SEMATTRS_HTTP_METHOD];
399
+ metricAttributes[semantic_conventions_1.SEMATTRS_NET_HOST_NAME] =
400
+ spanAttributes[semantic_conventions_1.SEMATTRS_NET_HOST_NAME];
401
+ metricAttributes[semantic_conventions_1.SEMATTRS_HTTP_FLAVOR] = spanAttributes[semantic_conventions_1.SEMATTRS_HTTP_FLAVOR];
402
+ //TODO: http.target attribute, it should substitute any parameters to avoid high cardinality.
414
403
  return metricAttributes;
415
404
  };
416
405
  exports.getIncomingRequestMetricAttributes = getIncomingRequestMetricAttributes;
@@ -427,15 +416,15 @@ const getIncomingRequestAttributesOnResponse = (request, response) => {
427
416
  const attributes = {};
428
417
  if (socket) {
429
418
  const { localAddress, localPort, remoteAddress, remotePort } = socket;
430
- attributes[semantic_conventions_1.SemanticAttributes.NET_HOST_IP] = localAddress;
431
- attributes[semantic_conventions_1.SemanticAttributes.NET_HOST_PORT] = localPort;
432
- attributes[semantic_conventions_1.SemanticAttributes.NET_PEER_IP] = remoteAddress;
433
- attributes[semantic_conventions_1.SemanticAttributes.NET_PEER_PORT] = remotePort;
419
+ attributes[semantic_conventions_1.SEMATTRS_NET_HOST_IP] = localAddress;
420
+ attributes[semantic_conventions_1.SEMATTRS_NET_HOST_PORT] = localPort;
421
+ attributes[semantic_conventions_1.SEMATTRS_NET_PEER_IP] = remoteAddress;
422
+ attributes[semantic_conventions_1.SEMATTRS_NET_PEER_PORT] = remotePort;
434
423
  }
435
- attributes[semantic_conventions_1.SemanticAttributes.HTTP_STATUS_CODE] = statusCode;
424
+ attributes[semantic_conventions_1.SEMATTRS_HTTP_STATUS_CODE] = statusCode;
436
425
  attributes[AttributeNames_1.AttributeNames.HTTP_STATUS_TEXT] = (statusMessage || '').toUpperCase();
437
426
  if ((rpcMetadata === null || rpcMetadata === void 0 ? void 0 : rpcMetadata.type) === core_1.RPCType.HTTP && rpcMetadata.route !== undefined) {
438
- attributes[semantic_conventions_1.SemanticAttributes.HTTP_ROUTE] = rpcMetadata.route;
427
+ attributes[semantic_conventions_1.SEMATTRS_HTTP_ROUTE] = rpcMetadata.route;
439
428
  }
440
429
  return attributes;
441
430
  };
@@ -446,28 +435,29 @@ exports.getIncomingRequestAttributesOnResponse = getIncomingRequestAttributesOnR
446
435
  */
447
436
  const getIncomingRequestMetricAttributesOnResponse = (spanAttributes) => {
448
437
  const metricAttributes = {};
449
- metricAttributes[semantic_conventions_1.SemanticAttributes.HTTP_STATUS_CODE] =
450
- spanAttributes[semantic_conventions_1.SemanticAttributes.HTTP_STATUS_CODE];
451
- metricAttributes[semantic_conventions_1.SemanticAttributes.NET_HOST_PORT] =
452
- spanAttributes[semantic_conventions_1.SemanticAttributes.NET_HOST_PORT];
453
- if (spanAttributes[semantic_conventions_1.SemanticAttributes.HTTP_ROUTE] !== undefined) {
454
- metricAttributes[semantic_conventions_1.SemanticAttributes.HTTP_ROUTE] =
455
- spanAttributes[semantic_conventions_1.SemanticAttributes.HTTP_ROUTE];
438
+ metricAttributes[semantic_conventions_1.SEMATTRS_HTTP_STATUS_CODE] =
439
+ spanAttributes[semantic_conventions_1.SEMATTRS_HTTP_STATUS_CODE];
440
+ metricAttributes[semantic_conventions_1.SEMATTRS_NET_HOST_PORT] =
441
+ spanAttributes[semantic_conventions_1.SEMATTRS_NET_HOST_PORT];
442
+ if (spanAttributes[semantic_conventions_1.SEMATTRS_HTTP_ROUTE] !== undefined) {
443
+ metricAttributes[semantic_conventions_1.SEMATTRS_HTTP_ROUTE] = spanAttributes[semantic_conventions_1.SEMATTRS_HTTP_ROUTE];
456
444
  }
457
445
  return metricAttributes;
458
446
  };
459
447
  exports.getIncomingRequestMetricAttributesOnResponse = getIncomingRequestMetricAttributesOnResponse;
460
448
  function headerCapture(type, headers) {
461
- const normalizedHeaders = new Map(headers.map(header => [
462
- header.toLowerCase(),
463
- header.toLowerCase().replace(/-/g, '_'),
464
- ]));
449
+ const normalizedHeaders = new Map();
450
+ for (let i = 0, len = headers.length; i < len; i++) {
451
+ const capturedHeader = headers[i].toLowerCase();
452
+ normalizedHeaders.set(capturedHeader, capturedHeader.replace(/-/g, '_'));
453
+ }
465
454
  return (span, getHeader) => {
466
- for (const [capturedHeader, normalizedHeader] of normalizedHeaders) {
455
+ for (const capturedHeader of normalizedHeaders.keys()) {
467
456
  const value = getHeader(capturedHeader);
468
457
  if (value === undefined) {
469
458
  continue;
470
459
  }
460
+ const normalizedHeader = normalizedHeaders.get(capturedHeader);
471
461
  const key = `http.${type}.header.${normalizedHeader}`;
472
462
  if (typeof value === 'string') {
473
463
  span.setAttribute(key, [value]);
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,4CAO4B;AAC5B,8EAG6C;AAQ7C,8CAA8D;AAC9D,2BAA2B;AAC3B,2DAAwD;AAGxD;;GAEG;AACI,MAAM,cAAc,GAAG,CAC5B,UAAuC,EACvC,OAAkD,EAClD,gBAAgB,GAAG,OAAO,E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AC,KAAK,CAAC,EAAE;gBAC/B,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;aAC/B;iBAAM;gBACL,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;aACjC;SACF;IACH,CAAC,CAAC;AACJ,CAAC;AA9BD,sCA8BC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n MetricAttributes,\n SpanAttributes,\n SpanStatusCode,\n Span,\n context,\n SpanKind,\n} from '@opentelemetry/api';\nimport {\n NetTransportValues,\n SemanticAttributes,\n} from '@opentelemetry/semantic-conventions';\nimport {\n IncomingHttpHeaders,\n IncomingMessage,\n OutgoingHttpHeaders,\n RequestOptions,\n ServerResponse,\n} from 'http';\nimport { getRPCMetadata, RPCType } from '@opentelemetry/core';\nimport * as url from 'url';\nimport { AttributeNames } from './enums/AttributeNames';\nimport { Err, IgnoreMatcher, ParsedRequestOptions } from './types';\n\n/**\n * Get an absolute url\n */\nexport const getAbsoluteUrl = (\n requestUrl: ParsedRequestOptions | null,\n headers: IncomingHttpHeaders | OutgoingHttpHeaders,\n fallbackProtocol = 'http:'\n): string => {\n const reqUrlObject = requestUrl || {};\n const protocol = reqUrlObject.protocol || fallbackProtocol;\n const port = (reqUrlObject.port || '').toString();\n const path = reqUrlObject.path || '/';\n let host =\n reqUrlObject.host || reqUrlObject.hostname || headers.host || 'localhost';\n\n // if there is no port in host and there is a port\n // it should be displayed if it's not 80 and 443 (default ports)\n if (\n (host as string).indexOf(':') === -1 &&\n port &&\n port !== '80' &&\n port !== '443'\n ) {\n host += `:${port}`;\n }\n\n return `${protocol}//${host}${path}`;\n};\n\n/**\n * Parse status code from HTTP response. [More details](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/data-http.md#status)\n */\nexport const parseResponseStatus = (\n kind: SpanKind,\n statusCode?: number\n): SpanStatusCode => {\n const upperBound = kind === SpanKind.CLIENT ? 400 : 500;\n // 1xx, 2xx, 3xx are OK on client and server\n // 4xx is OK on server\n if (statusCode && statusCode >= 100 && statusCode < upperBound) {\n return SpanStatusCode.UNSET;\n }\n\n // All other codes are error\n return SpanStatusCode.ERROR;\n};\n\n/**\n * Check whether the given obj match pattern\n * @param constant e.g URL of request\n * @param pattern Match pattern\n */\nexport const satisfiesPattern = (\n constant: string,\n pattern: IgnoreMatcher\n): boolean => {\n if (typeof pattern === 'string') {\n return pattern === constant;\n } else if (pattern instanceof RegExp) {\n return pattern.test(constant);\n } else if (typeof pattern === 'function') {\n return pattern(constant);\n } else {\n throw new TypeError('Pattern is in unsupported datatype');\n }\n};\n\n/**\n * Check whether the given request is ignored by configuration\n * It will not re-throw exceptions from `list` provided by the client\n * @param constant e.g URL of request\n * @param [list] List of ignore patterns\n * @param [onException] callback for doing something when an exception has\n * occurred\n */\nexport const isIgnored = (\n constant: string,\n list?: IgnoreMatcher[],\n onException?: (error: unknown) => void\n): boolean => {\n if (!list) {\n // No ignored urls - trace everything\n return false;\n }\n // Try/catch outside the loop for failing fast\n try {\n for (const pattern of list) {\n if (satisfiesPattern(constant, pattern)) {\n return true;\n }\n }\n } catch (e) {\n if (onException) {\n onException(e);\n }\n }\n\n return false;\n};\n\n/**\n * Sets the span with the error passed in params\n * @param {Span} span the span that need to be set\n * @param {Error} error error that will be set to span\n */\nexport const setSpanWithError = (span: Span, error: Err): void => {\n const message = error.message;\n\n span.setAttributes({\n [AttributeNames.HTTP_ERROR_NAME]: error.name,\n [AttributeNames.HTTP_ERROR_MESSAGE]: message,\n });\n\n span.setStatus({ code: SpanStatusCode.ERROR, message });\n span.recordException(error);\n};\n\n/**\n * Adds attributes for request content-length and content-encoding HTTP headers\n * @param { IncomingMessage } Request object whose headers will be analyzed\n * @param { SpanAttributes } SpanAttributes object to be modified\n */\nexport const setRequestContentLengthAttribute = (\n request: IncomingMessage,\n attributes: SpanAttributes\n): void => {\n const length = getContentLength(request.headers);\n if (length === null) return;\n\n if (isCompressed(request.headers)) {\n attributes[SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH] = length;\n } else {\n attributes[SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH_UNCOMPRESSED] =\n length;\n }\n};\n\n/**\n * Adds attributes for response content-length and content-encoding HTTP headers\n * @param { IncomingMessage } Response object whose headers will be analyzed\n * @param { SpanAttributes } SpanAttributes object to be modified\n */\nexport const setResponseContentLengthAttribute = (\n response: IncomingMessage,\n attributes: SpanAttributes\n): void => {\n const length = getContentLength(response.headers);\n if (length === null) return;\n\n if (isCompressed(response.headers)) {\n attributes[SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH] = length;\n } else {\n attributes[SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH_UNCOMPRESSED] =\n length;\n }\n};\n\nfunction getContentLength(\n headers: OutgoingHttpHeaders | IncomingHttpHeaders\n): number | null {\n const contentLengthHeader = headers['content-length'];\n if (contentLengthHeader === undefined) return null;\n\n const contentLength = parseInt(contentLengthHeader as string, 10);\n if (isNaN(contentLength)) return null;\n\n return contentLength;\n}\n\nexport const isCompressed = (\n headers: OutgoingHttpHeaders | IncomingHttpHeaders\n): boolean => {\n const encoding = headers['content-encoding'];\n\n return !!encoding && encoding !== 'identity';\n};\n\n/**\n * Makes sure options is an url object\n * return an object with default value and parsed options\n * @param options original options for the request\n * @param [extraOptions] additional options for the request\n */\nexport const getRequestInfo = (\n options: url.URL | RequestOptions | string,\n extraOptions?: RequestOptions\n): {\n origin: string;\n pathname: string;\n method: string;\n optionsParsed: RequestOptions;\n} => {\n let pathname = '/';\n let origin = '';\n let optionsParsed: RequestOptions;\n if (typeof options === 'string') {\n optionsParsed = url.parse(options);\n pathname = (optionsParsed as url.UrlWithStringQuery).pathname || '/';\n origin = `${optionsParsed.protocol || 'http:'}//${optionsParsed.host}`;\n if (extraOptions !== undefined) {\n Object.assign(optionsParsed, extraOptions);\n }\n } else if (options instanceof url.URL) {\n optionsParsed = {\n protocol: options.protocol,\n hostname:\n typeof options.hostname === 'string' && options.hostname.startsWith('[')\n ? options.hostname.slice(1, -1)\n : options.hostname,\n path: `${options.pathname || ''}${options.search || ''}`,\n };\n if (options.port !== '') {\n optionsParsed.port = Number(options.port);\n }\n if (options.username || options.password) {\n optionsParsed.auth = `${options.username}:${options.password}`;\n }\n pathname = options.pathname;\n origin = options.origin;\n if (extraOptions !== undefined) {\n Object.assign(optionsParsed, extraOptions);\n }\n } else {\n optionsParsed = Object.assign(\n { protocol: options.host ? 'http:' : undefined },\n options\n );\n pathname = (options as url.URL).pathname;\n if (!pathname && optionsParsed.path) {\n pathname = url.parse(optionsParsed.path).pathname || '/';\n }\n const hostname =\n optionsParsed.host ||\n (optionsParsed.port != null\n ? `${optionsParsed.hostname}${optionsParsed.port}`\n : optionsParsed.hostname);\n origin = `${optionsParsed.protocol || 'http:'}//${hostname}`;\n }\n\n // some packages return method in lowercase..\n // ensure upperCase for consistency\n const method = optionsParsed.method\n ? optionsParsed.method.toUpperCase()\n : 'GET';\n\n return { origin, pathname, method, optionsParsed };\n};\n\n/**\n * Makes sure options is of type string or object\n * @param options for the request\n */\nexport const isValidOptionsType = (options: unknown): boolean => {\n if (!options) {\n return false;\n }\n\n const type = typeof options;\n return type === 'string' || (type === 'object' && !Array.isArray(options));\n};\n\nexport const extractHostnameAndPort = (\n requestOptions: Pick<\n ParsedRequestOptions,\n 'hostname' | 'host' | 'port' | 'protocol'\n >\n): { hostname: string; port: number | string } => {\n if (requestOptions.hostname && requestOptions.port) {\n return { hostname: requestOptions.hostname, port: requestOptions.port };\n }\n const matches = requestOptions.host?.match(/^([^:/ ]+)(:\\d{1,5})?/) || null;\n const hostname =\n requestOptions.hostname || (matches === null ? 'localhost' : matches[1]);\n let port = requestOptions.port;\n if (!port) {\n if (matches && matches[2]) {\n // remove the leading \":\". The extracted port would be something like \":8080\"\n port = matches[2].substring(1);\n } else {\n port = requestOptions.protocol === 'https:' ? '443' : '80';\n }\n }\n return { hostname, port };\n};\n\n/**\n * Returns outgoing request attributes scoped to the options passed to the request\n * @param {ParsedRequestOptions} requestOptions the same options used to make the request\n * @param {{ component: string, hostname: string, hookAttributes?: SpanAttributes }} options used to pass data needed to create attributes\n */\nexport const getOutgoingRequestAttributes = (\n requestOptions: ParsedRequestOptions,\n options: {\n component: string;\n hostname: string;\n port: string | number;\n hookAttributes?: SpanAttributes;\n }\n): SpanAttributes => {\n const hostname = options.hostname;\n const port = options.port;\n const requestMethod = requestOptions.method;\n const method = requestMethod ? requestMethod.toUpperCase() : 'GET';\n const headers = requestOptions.headers || {};\n const userAgent = headers['user-agent'];\n const attributes: SpanAttributes = {\n [SemanticAttributes.HTTP_URL]: getAbsoluteUrl(\n requestOptions,\n headers,\n `${options.component}:`\n ),\n [SemanticAttributes.HTTP_METHOD]: method,\n [SemanticAttributes.HTTP_TARGET]: requestOptions.path || '/',\n [SemanticAttributes.NET_PEER_NAME]: hostname,\n [SemanticAttributes.HTTP_HOST]:\n requestOptions.headers?.host ?? `${hostname}:${port}`,\n };\n\n if (userAgent !== undefined) {\n attributes[SemanticAttributes.HTTP_USER_AGENT] = userAgent;\n }\n return Object.assign(attributes, options.hookAttributes);\n};\n\n/**\n * Returns outgoing request Metric attributes scoped to the request data\n * @param {SpanAttributes} spanAttributes the span attributes\n */\nexport const getOutgoingRequestMetricAttributes = (\n spanAttributes: SpanAttributes\n): MetricAttributes => {\n const metricAttributes: MetricAttributes = {};\n metricAttributes[SemanticAttributes.HTTP_METHOD] =\n spanAttributes[SemanticAttributes.HTTP_METHOD];\n metricAttributes[SemanticAttributes.NET_PEER_NAME] =\n spanAttributes[SemanticAttributes.NET_PEER_NAME];\n //TODO: http.url attribute, it should susbtitute any parameters to avoid high cardinality.\n return metricAttributes;\n};\n\n/**\n * Returns attributes related to the kind of HTTP protocol used\n * @param {string} [kind] Kind of HTTP protocol used: \"1.0\", \"1.1\", \"2\", \"SPDY\" or \"QUIC\".\n */\nexport const getAttributesFromHttpKind = (kind?: string): SpanAttributes => {\n const attributes: SpanAttributes = {};\n if (kind) {\n attributes[SemanticAttributes.HTTP_FLAVOR] = kind;\n if (kind.toUpperCase() !== 'QUIC') {\n attributes[SemanticAttributes.NET_TRANSPORT] = NetTransportValues.IP_TCP;\n } else {\n attributes[SemanticAttributes.NET_TRANSPORT] = NetTransportValues.IP_UDP;\n }\n }\n return attributes;\n};\n\n/**\n * Returns outgoing request attributes scoped to the response data\n * @param {IncomingMessage} response the response object\n * @param {{ hostname: string }} options used to pass data needed to create attributes\n */\nexport const getOutgoingRequestAttributesOnResponse = (\n response: IncomingMessage\n): SpanAttributes => {\n const { statusCode, statusMessage, httpVersion, socket } = response;\n const attributes: SpanAttributes = {};\n if (socket) {\n const { remoteAddress, remotePort } = socket;\n attributes[SemanticAttributes.NET_PEER_IP] = remoteAddress;\n attributes[SemanticAttributes.NET_PEER_PORT] = remotePort;\n }\n setResponseContentLengthAttribute(response, attributes);\n\n if (statusCode) {\n attributes[SemanticAttributes.HTTP_STATUS_CODE] = statusCode;\n attributes[AttributeNames.HTTP_STATUS_TEXT] = (\n statusMessage || ''\n ).toUpperCase();\n }\n\n const httpKindAttributes = getAttributesFromHttpKind(httpVersion);\n return Object.assign(attributes, httpKindAttributes);\n};\n\n/**\n * Returns outgoing request Metric attributes scoped to the response data\n * @param {SpanAttributes} spanAttributes the span attributes\n */\nexport const getOutgoingRequestMetricAttributesOnResponse = (\n spanAttributes: SpanAttributes\n): MetricAttributes => {\n const metricAttributes: MetricAttributes = {};\n metricAttributes[SemanticAttributes.NET_PEER_PORT] =\n spanAttributes[SemanticAttributes.NET_PEER_PORT];\n metricAttributes[SemanticAttributes.HTTP_STATUS_CODE] =\n spanAttributes[SemanticAttributes.HTTP_STATUS_CODE];\n metricAttributes[SemanticAttributes.HTTP_FLAVOR] =\n spanAttributes[SemanticAttributes.HTTP_FLAVOR];\n return metricAttributes;\n};\n\n/**\n * Returns incoming request attributes scoped to the request data\n * @param {IncomingMessage} request the request object\n * @param {{ component: string, serverName?: string, hookAttributes?: SpanAttributes }} options used to pass data needed to create attributes\n */\nexport const getIncomingRequestAttributes = (\n request: IncomingMessage,\n options: {\n component: string;\n serverName?: string;\n hookAttributes?: SpanAttributes;\n }\n): SpanAttributes => {\n const headers = request.headers;\n const userAgent = headers['user-agent'];\n const ips = headers['x-forwarded-for'];\n const method = request.method || 'GET';\n const httpVersion = request.httpVersion;\n const requestUrl = request.url ? url.parse(request.url) : null;\n const host = requestUrl?.host || headers.host;\n const hostname =\n requestUrl?.hostname ||\n host?.replace(/^(.*)(:[0-9]{1,5})/, '$1') ||\n 'localhost';\n const serverName = options.serverName;\n const attributes: SpanAttributes = {\n [SemanticAttributes.HTTP_URL]: getAbsoluteUrl(\n requestUrl,\n headers,\n `${options.component}:`\n ),\n [SemanticAttributes.HTTP_HOST]: host,\n [SemanticAttributes.NET_HOST_NAME]: hostname,\n [SemanticAttributes.HTTP_METHOD]: method,\n [SemanticAttributes.HTTP_SCHEME]: options.component,\n };\n\n if (typeof ips === 'string') {\n attributes[SemanticAttributes.HTTP_CLIENT_IP] = ips.split(',')[0];\n }\n\n if (typeof serverName === 'string') {\n attributes[SemanticAttributes.HTTP_SERVER_NAME] = serverName;\n }\n\n if (requestUrl) {\n attributes[SemanticAttributes.HTTP_TARGET] = requestUrl.path || '/';\n }\n\n if (userAgent !== undefined) {\n attributes[SemanticAttributes.HTTP_USER_AGENT] = userAgent;\n }\n setRequestContentLengthAttribute(request, attributes);\n\n const httpKindAttributes = getAttributesFromHttpKind(httpVersion);\n return Object.assign(attributes, httpKindAttributes, options.hookAttributes);\n};\n\n/**\n * Returns incoming request Metric attributes scoped to the request data\n * @param {SpanAttributes} spanAttributes the span attributes\n * @param {{ component: string }} options used to pass data needed to create attributes\n */\nexport const getIncomingRequestMetricAttributes = (\n spanAttributes: SpanAttributes\n): MetricAttributes => {\n const metricAttributes: MetricAttributes = {};\n metricAttributes[SemanticAttributes.HTTP_SCHEME] =\n spanAttributes[SemanticAttributes.HTTP_SCHEME];\n metricAttributes[SemanticAttributes.HTTP_METHOD] =\n spanAttributes[SemanticAttributes.HTTP_METHOD];\n metricAttributes[SemanticAttributes.NET_HOST_NAME] =\n spanAttributes[SemanticAttributes.NET_HOST_NAME];\n metricAttributes[SemanticAttributes.HTTP_FLAVOR] =\n spanAttributes[SemanticAttributes.HTTP_FLAVOR];\n //TODO: http.target attribute, it should susbtitute any parameters to avoid high cardinality.\n return metricAttributes;\n};\n\n/**\n * Returns incoming request attributes scoped to the response data\n * @param {(ServerResponse & { socket: Socket; })} response the response object\n */\nexport const getIncomingRequestAttributesOnResponse = (\n request: IncomingMessage,\n response: ServerResponse\n): SpanAttributes => {\n // take socket from the request,\n // since it may be detached from the response object in keep-alive mode\n const { socket } = request;\n const { statusCode, statusMessage } = response;\n\n const rpcMetadata = getRPCMetadata(context.active());\n const attributes: SpanAttributes = {};\n if (socket) {\n const { localAddress, localPort, remoteAddress, remotePort } = socket;\n attributes[SemanticAttributes.NET_HOST_IP] = localAddress;\n attributes[SemanticAttributes.NET_HOST_PORT] = localPort;\n attributes[SemanticAttributes.NET_PEER_IP] = remoteAddress;\n attributes[SemanticAttributes.NET_PEER_PORT] = remotePort;\n }\n attributes[SemanticAttributes.HTTP_STATUS_CODE] = statusCode;\n attributes[AttributeNames.HTTP_STATUS_TEXT] = (\n statusMessage || ''\n ).toUpperCase();\n\n if (rpcMetadata?.type === RPCType.HTTP && rpcMetadata.route !== undefined) {\n attributes[SemanticAttributes.HTTP_ROUTE] = rpcMetadata.route;\n }\n return attributes;\n};\n\n/**\n * Returns incoming request Metric attributes scoped to the request data\n * @param {SpanAttributes} spanAttributes the span attributes\n */\nexport const getIncomingRequestMetricAttributesOnResponse = (\n spanAttributes: SpanAttributes\n): MetricAttributes => {\n const metricAttributes: MetricAttributes = {};\n metricAttributes[SemanticAttributes.HTTP_STATUS_CODE] =\n spanAttributes[SemanticAttributes.HTTP_STATUS_CODE];\n metricAttributes[SemanticAttributes.NET_HOST_PORT] =\n spanAttributes[SemanticAttributes.NET_HOST_PORT];\n if (spanAttributes[SemanticAttributes.HTTP_ROUTE] !== undefined) {\n metricAttributes[SemanticAttributes.HTTP_ROUTE] =\n spanAttributes[SemanticAttributes.HTTP_ROUTE];\n }\n return metricAttributes;\n};\n\nexport function headerCapture(type: 'request' | 'response', headers: string[]) {\n const normalizedHeaders = new Map(\n headers.map(header => [\n header.toLowerCase(),\n header.toLowerCase().replace(/-/g, '_'),\n ])\n );\n\n return (\n span: Span,\n getHeader: (key: string) => undefined | string | string[] | number\n ) => {\n for (const [capturedHeader, normalizedHeader] of normalizedHeaders) {\n const value = getHeader(capturedHeader);\n\n if (value === undefined) {\n continue;\n }\n\n const key = `http.${type}.header.${normalizedHeader}`;\n\n if (typeof value === 'string') {\n span.setAttribute(key, [value]);\n } else if (Array.isArray(value)) {\n span.setAttribute(key, value);\n } else {\n span.setAttribute(key, [value]);\n }\n }\n };\n}\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,4CAO4B;AAC5B,8EAyB6C;AAQ7C,8CAA8D;AAC9D,2BAA2B;AAC3B,2DAAwD;AAGxD;;GAEG;AACI,MAAM,cAAc,GAAG,CAC5B,UAAuC,EACvC,OAAkD,EAClD,gBAAgB,GAAG,OAAO,EAClB,EAAE;IACV,MAAM,YAAY,GAAG,UAAU,IAAI,EAAE,CAAC;IACtC,MAAM,QAAQ,GAAG,YAAY,CAAC,QAAQ,IAAI,gBAAgB,CAAC;IAC3D,MAAM,IAAI,GAAG,CAAC,YA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AAM,KAAK,GAAG,SAAS,CAAC,cAAc,CAAC,CAAC;YAExC,IAAI,KAAK,KAAK,SAAS,EAAE;gBACvB,SAAS;aACV;YAED,MAAM,gBAAgB,GAAG,iBAAiB,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;YAC/D,MAAM,GAAG,GAAG,QAAQ,IAAI,WAAW,gBAAgB,EAAE,CAAC;YAEtD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;gBAC7B,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;aACjC;iBAAM,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;gBAC/B,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;aAC/B;iBAAM;gBACL,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;aACjC;SACF;IACH,CAAC,CAAC;AACJ,CAAC;AA9BD,sCA8BC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n MetricAttributes,\n SpanAttributes,\n SpanStatusCode,\n Span,\n context,\n SpanKind,\n} from '@opentelemetry/api';\nimport {\n NETTRANSPORTVALUES_IP_TCP,\n NETTRANSPORTVALUES_IP_UDP,\n SEMATTRS_HTTP_CLIENT_IP,\n SEMATTRS_HTTP_FLAVOR,\n SEMATTRS_HTTP_HOST,\n SEMATTRS_HTTP_METHOD,\n SEMATTRS_HTTP_REQUEST_CONTENT_LENGTH,\n SEMATTRS_HTTP_REQUEST_CONTENT_LENGTH_UNCOMPRESSED,\n SEMATTRS_HTTP_RESPONSE_CONTENT_LENGTH,\n SEMATTRS_HTTP_RESPONSE_CONTENT_LENGTH_UNCOMPRESSED,\n SEMATTRS_HTTP_ROUTE,\n SEMATTRS_HTTP_SCHEME,\n SEMATTRS_HTTP_SERVER_NAME,\n SEMATTRS_HTTP_STATUS_CODE,\n SEMATTRS_HTTP_TARGET,\n SEMATTRS_HTTP_URL,\n SEMATTRS_HTTP_USER_AGENT,\n SEMATTRS_NET_HOST_IP,\n SEMATTRS_NET_HOST_NAME,\n SEMATTRS_NET_HOST_PORT,\n SEMATTRS_NET_PEER_IP,\n SEMATTRS_NET_PEER_NAME,\n SEMATTRS_NET_PEER_PORT,\n SEMATTRS_NET_TRANSPORT,\n} from '@opentelemetry/semantic-conventions';\nimport {\n IncomingHttpHeaders,\n IncomingMessage,\n OutgoingHttpHeaders,\n RequestOptions,\n ServerResponse,\n} from 'http';\nimport { getRPCMetadata, RPCType } from '@opentelemetry/core';\nimport * as url from 'url';\nimport { AttributeNames } from './enums/AttributeNames';\nimport { Err, IgnoreMatcher, ParsedRequestOptions } from './types';\n\n/**\n * Get an absolute url\n */\nexport const getAbsoluteUrl = (\n requestUrl: ParsedRequestOptions | null,\n headers: IncomingHttpHeaders | OutgoingHttpHeaders,\n fallbackProtocol = 'http:'\n): string => {\n const reqUrlObject = requestUrl || {};\n const protocol = reqUrlObject.protocol || fallbackProtocol;\n const port = (reqUrlObject.port || '').toString();\n const path = reqUrlObject.path || '/';\n let host =\n reqUrlObject.host || reqUrlObject.hostname || headers.host || 'localhost';\n\n // if there is no port in host and there is a port\n // it should be displayed if it's not 80 and 443 (default ports)\n if (\n (host as string).indexOf(':') === -1 &&\n port &&\n port !== '80' &&\n port !== '443'\n ) {\n host += `:${port}`;\n }\n\n return `${protocol}//${host}${path}`;\n};\n\n/**\n * Parse status code from HTTP response. [More details](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/data-http.md#status)\n */\nexport const parseResponseStatus = (\n kind: SpanKind,\n statusCode?: number\n): SpanStatusCode => {\n const upperBound = kind === SpanKind.CLIENT ? 400 : 500;\n // 1xx, 2xx, 3xx are OK on client and server\n // 4xx is OK on server\n if (statusCode && statusCode >= 100 && statusCode < upperBound) {\n return SpanStatusCode.UNSET;\n }\n\n // All other codes are error\n return SpanStatusCode.ERROR;\n};\n\n/**\n * Check whether the given obj match pattern\n * @param constant e.g URL of request\n * @param pattern Match pattern\n */\nexport const satisfiesPattern = (\n constant: string,\n pattern: IgnoreMatcher\n): boolean => {\n if (typeof pattern === 'string') {\n return pattern === constant;\n } else if (pattern instanceof RegExp) {\n return pattern.test(constant);\n } else if (typeof pattern === 'function') {\n return pattern(constant);\n } else {\n throw new TypeError('Pattern is in unsupported datatype');\n }\n};\n\n/**\n * Check whether the given request is ignored by configuration\n * It will not re-throw exceptions from `list` provided by the client\n * @param constant e.g URL of request\n * @param [list] List of ignore patterns\n * @param [onException] callback for doing something when an exception has\n * occurred\n */\nexport const isIgnored = (\n constant: string,\n list?: IgnoreMatcher[],\n onException?: (error: unknown) => void\n): boolean => {\n if (!list) {\n // No ignored urls - trace everything\n return false;\n }\n // Try/catch outside the loop for failing fast\n try {\n for (const pattern of list) {\n if (satisfiesPattern(constant, pattern)) {\n return true;\n }\n }\n } catch (e) {\n if (onException) {\n onException(e);\n }\n }\n\n return false;\n};\n\n/**\n * Sets the span with the error passed in params\n * @param {Span} span the span that need to be set\n * @param {Error} error error that will be set to span\n */\nexport const setSpanWithError = (span: Span, error: Err): void => {\n const message = error.message;\n\n span.setAttribute(AttributeNames.HTTP_ERROR_NAME, error.name);\n span.setAttribute(AttributeNames.HTTP_ERROR_MESSAGE, message);\n span.setStatus({ code: SpanStatusCode.ERROR, message });\n span.recordException(error);\n};\n\n/**\n * Adds attributes for request content-length and content-encoding HTTP headers\n * @param { IncomingMessage } Request object whose headers will be analyzed\n * @param { SpanAttributes } SpanAttributes object to be modified\n */\nexport const setRequestContentLengthAttribute = (\n request: IncomingMessage,\n attributes: SpanAttributes\n): void => {\n const length = getContentLength(request.headers);\n if (length === null) return;\n\n if (isCompressed(request.headers)) {\n attributes[SEMATTRS_HTTP_REQUEST_CONTENT_LENGTH] = length;\n } else {\n attributes[SEMATTRS_HTTP_REQUEST_CONTENT_LENGTH_UNCOMPRESSED] = length;\n }\n};\n\n/**\n * Adds attributes for response content-length and content-encoding HTTP headers\n * @param { IncomingMessage } Response object whose headers will be analyzed\n * @param { SpanAttributes } SpanAttributes object to be modified\n */\nexport const setResponseContentLengthAttribute = (\n response: IncomingMessage,\n attributes: SpanAttributes\n): void => {\n const length = getContentLength(response.headers);\n if (length === null) return;\n\n if (isCompressed(response.headers)) {\n attributes[SEMATTRS_HTTP_RESPONSE_CONTENT_LENGTH] = length;\n } else {\n attributes[SEMATTRS_HTTP_RESPONSE_CONTENT_LENGTH_UNCOMPRESSED] = length;\n }\n};\n\nfunction getContentLength(\n headers: OutgoingHttpHeaders | IncomingHttpHeaders\n): number | null {\n const contentLengthHeader = headers['content-length'];\n if (contentLengthHeader === undefined) return null;\n\n const contentLength = parseInt(contentLengthHeader as string, 10);\n if (isNaN(contentLength)) return null;\n\n return contentLength;\n}\n\nexport const isCompressed = (\n headers: OutgoingHttpHeaders | IncomingHttpHeaders\n): boolean => {\n const encoding = headers['content-encoding'];\n\n return !!encoding && encoding !== 'identity';\n};\n\n/**\n * Makes sure options is an url object\n * return an object with default value and parsed options\n * @param options original options for the request\n * @param [extraOptions] additional options for the request\n */\nexport const getRequestInfo = (\n options: url.URL | RequestOptions | string,\n extraOptions?: RequestOptions\n): {\n origin: string;\n pathname: string;\n method: string;\n optionsParsed: RequestOptions;\n} => {\n let pathname = '/';\n let origin = '';\n let optionsParsed: RequestOptions;\n if (typeof options === 'string') {\n optionsParsed = url.parse(options);\n pathname = (optionsParsed as url.UrlWithStringQuery).pathname || '/';\n origin = `${optionsParsed.protocol || 'http:'}//${optionsParsed.host}`;\n if (extraOptions !== undefined) {\n Object.assign(optionsParsed, extraOptions);\n }\n } else if (options instanceof url.URL) {\n optionsParsed = {\n protocol: options.protocol,\n hostname:\n typeof options.hostname === 'string' && options.hostname.startsWith('[')\n ? options.hostname.slice(1, -1)\n : options.hostname,\n path: `${options.pathname || ''}${options.search || ''}`,\n };\n if (options.port !== '') {\n optionsParsed.port = Number(options.port);\n }\n if (options.username || options.password) {\n optionsParsed.auth = `${options.username}:${options.password}`;\n }\n pathname = options.pathname;\n origin = options.origin;\n if (extraOptions !== undefined) {\n Object.assign(optionsParsed, extraOptions);\n }\n } else {\n optionsParsed = Object.assign(\n { protocol: options.host ? 'http:' : undefined },\n options\n );\n pathname = (options as url.URL).pathname;\n if (!pathname && optionsParsed.path) {\n pathname = url.parse(optionsParsed.path).pathname || '/';\n }\n const hostname =\n optionsParsed.host ||\n (optionsParsed.port != null\n ? `${optionsParsed.hostname}${optionsParsed.port}`\n : optionsParsed.hostname);\n origin = `${optionsParsed.protocol || 'http:'}//${hostname}`;\n }\n\n // some packages return method in lowercase..\n // ensure upperCase for consistency\n const method = optionsParsed.method\n ? optionsParsed.method.toUpperCase()\n : 'GET';\n\n return { origin, pathname, method, optionsParsed };\n};\n\n/**\n * Makes sure options is of type string or object\n * @param options for the request\n */\nexport const isValidOptionsType = (options: unknown): boolean => {\n if (!options) {\n return false;\n }\n\n const type = typeof options;\n return type === 'string' || (type === 'object' && !Array.isArray(options));\n};\n\nexport const extractHostnameAndPort = (\n requestOptions: Pick<\n ParsedRequestOptions,\n 'hostname' | 'host' | 'port' | 'protocol'\n >\n): { hostname: string; port: number | string } => {\n if (requestOptions.hostname && requestOptions.port) {\n return { hostname: requestOptions.hostname, port: requestOptions.port };\n }\n const matches = requestOptions.host?.match(/^([^:/ ]+)(:\\d{1,5})?/) || null;\n const hostname =\n requestOptions.hostname || (matches === null ? 'localhost' : matches[1]);\n let port = requestOptions.port;\n if (!port) {\n if (matches && matches[2]) {\n // remove the leading \":\". The extracted port would be something like \":8080\"\n port = matches[2].substring(1);\n } else {\n port = requestOptions.protocol === 'https:' ? '443' : '80';\n }\n }\n return { hostname, port };\n};\n\n/**\n * Returns outgoing request attributes scoped to the options passed to the request\n * @param {ParsedRequestOptions} requestOptions the same options used to make the request\n * @param {{ component: string, hostname: string, hookAttributes?: SpanAttributes }} options used to pass data needed to create attributes\n */\nexport const getOutgoingRequestAttributes = (\n requestOptions: ParsedRequestOptions,\n options: {\n component: string;\n hostname: string;\n port: string | number;\n hookAttributes?: SpanAttributes;\n }\n): SpanAttributes => {\n const hostname = options.hostname;\n const port = options.port;\n const requestMethod = requestOptions.method;\n const method = requestMethod ? requestMethod.toUpperCase() : 'GET';\n const headers = requestOptions.headers || {};\n const userAgent = headers['user-agent'];\n const attributes: SpanAttributes = {\n [SEMATTRS_HTTP_URL]: getAbsoluteUrl(\n requestOptions,\n headers,\n `${options.component}:`\n ),\n [SEMATTRS_HTTP_METHOD]: method,\n [SEMATTRS_HTTP_TARGET]: requestOptions.path || '/',\n [SEMATTRS_NET_PEER_NAME]: hostname,\n [SEMATTRS_HTTP_HOST]: headers.host ?? `${hostname}:${port}`,\n };\n\n if (userAgent !== undefined) {\n attributes[SEMATTRS_HTTP_USER_AGENT] = userAgent;\n }\n return Object.assign(attributes, options.hookAttributes);\n};\n\n/**\n * Returns outgoing request Metric attributes scoped to the request data\n * @param {SpanAttributes} spanAttributes the span attributes\n */\nexport const getOutgoingRequestMetricAttributes = (\n spanAttributes: SpanAttributes\n): MetricAttributes => {\n const metricAttributes: MetricAttributes = {};\n metricAttributes[SEMATTRS_HTTP_METHOD] = spanAttributes[SEMATTRS_HTTP_METHOD];\n metricAttributes[SEMATTRS_NET_PEER_NAME] =\n spanAttributes[SEMATTRS_NET_PEER_NAME];\n //TODO: http.url attribute, it should substitute any parameters to avoid high cardinality.\n return metricAttributes;\n};\n\n/**\n * Returns attributes related to the kind of HTTP protocol used\n * @param {string} [kind] Kind of HTTP protocol used: \"1.0\", \"1.1\", \"2\", \"SPDY\" or \"QUIC\".\n */\nexport const setAttributesFromHttpKind = (\n kind: string | undefined,\n attributes: SpanAttributes\n): void => {\n if (kind) {\n attributes[SEMATTRS_HTTP_FLAVOR] = kind;\n if (kind.toUpperCase() !== 'QUIC') {\n attributes[SEMATTRS_NET_TRANSPORT] = NETTRANSPORTVALUES_IP_TCP;\n } else {\n attributes[SEMATTRS_NET_TRANSPORT] = NETTRANSPORTVALUES_IP_UDP;\n }\n }\n};\n\n/**\n * Returns outgoing request attributes scoped to the response data\n * @param {IncomingMessage} response the response object\n * @param {{ hostname: string }} options used to pass data needed to create attributes\n */\nexport const getOutgoingRequestAttributesOnResponse = (\n response: IncomingMessage\n): SpanAttributes => {\n const { statusCode, statusMessage, httpVersion, socket } = response;\n const attributes: SpanAttributes = {};\n if (socket) {\n const { remoteAddress, remotePort } = socket;\n attributes[SEMATTRS_NET_PEER_IP] = remoteAddress;\n attributes[SEMATTRS_NET_PEER_PORT] = remotePort;\n }\n setResponseContentLengthAttribute(response, attributes);\n\n if (statusCode) {\n attributes[SEMATTRS_HTTP_STATUS_CODE] = statusCode;\n attributes[AttributeNames.HTTP_STATUS_TEXT] = (\n statusMessage || ''\n ).toUpperCase();\n }\n\n setAttributesFromHttpKind(httpVersion, attributes);\n return attributes;\n};\n\n/**\n * Returns outgoing request Metric attributes scoped to the response data\n * @param {SpanAttributes} spanAttributes the span attributes\n */\nexport const getOutgoingRequestMetricAttributesOnResponse = (\n spanAttributes: SpanAttributes\n): MetricAttributes => {\n const metricAttributes: MetricAttributes = {};\n metricAttributes[SEMATTRS_NET_PEER_PORT] =\n spanAttributes[SEMATTRS_NET_PEER_PORT];\n metricAttributes[SEMATTRS_HTTP_STATUS_CODE] =\n spanAttributes[SEMATTRS_HTTP_STATUS_CODE];\n metricAttributes[SEMATTRS_HTTP_FLAVOR] = spanAttributes[SEMATTRS_HTTP_FLAVOR];\n return metricAttributes;\n};\n\n/**\n * Returns incoming request attributes scoped to the request data\n * @param {IncomingMessage} request the request object\n * @param {{ component: string, serverName?: string, hookAttributes?: SpanAttributes }} options used to pass data needed to create attributes\n */\nexport const getIncomingRequestAttributes = (\n request: IncomingMessage,\n options: {\n component: string;\n serverName?: string;\n hookAttributes?: SpanAttributes;\n }\n): SpanAttributes => {\n const headers = request.headers;\n const userAgent = headers['user-agent'];\n const ips = headers['x-forwarded-for'];\n const method = request.method || 'GET';\n const httpVersion = request.httpVersion;\n const requestUrl = request.url ? url.parse(request.url) : null;\n const host = requestUrl?.host || headers.host;\n const hostname =\n requestUrl?.hostname ||\n host?.replace(/^(.*)(:[0-9]{1,5})/, '$1') ||\n 'localhost';\n const serverName = options.serverName;\n const attributes: SpanAttributes = {\n [SEMATTRS_HTTP_URL]: getAbsoluteUrl(\n requestUrl,\n headers,\n `${options.component}:`\n ),\n [SEMATTRS_HTTP_HOST]: host,\n [SEMATTRS_NET_HOST_NAME]: hostname,\n [SEMATTRS_HTTP_METHOD]: method,\n [SEMATTRS_HTTP_SCHEME]: options.component,\n };\n\n if (typeof ips === 'string') {\n attributes[SEMATTRS_HTTP_CLIENT_IP] = ips.split(',')[0];\n }\n\n if (typeof serverName === 'string') {\n attributes[SEMATTRS_HTTP_SERVER_NAME] = serverName;\n }\n\n if (requestUrl) {\n attributes[SEMATTRS_HTTP_TARGET] = requestUrl.path || '/';\n }\n\n if (userAgent !== undefined) {\n attributes[SEMATTRS_HTTP_USER_AGENT] = userAgent;\n }\n setRequestContentLengthAttribute(request, attributes);\n setAttributesFromHttpKind(httpVersion, attributes);\n return Object.assign(attributes, options.hookAttributes);\n};\n\n/**\n * Returns incoming request Metric attributes scoped to the request data\n * @param {SpanAttributes} spanAttributes the span attributes\n * @param {{ component: string }} options used to pass data needed to create attributes\n */\nexport const getIncomingRequestMetricAttributes = (\n spanAttributes: SpanAttributes\n): MetricAttributes => {\n const metricAttributes: MetricAttributes = {};\n metricAttributes[SEMATTRS_HTTP_SCHEME] = spanAttributes[SEMATTRS_HTTP_SCHEME];\n metricAttributes[SEMATTRS_HTTP_METHOD] = spanAttributes[SEMATTRS_HTTP_METHOD];\n metricAttributes[SEMATTRS_NET_HOST_NAME] =\n spanAttributes[SEMATTRS_NET_HOST_NAME];\n metricAttributes[SEMATTRS_HTTP_FLAVOR] = spanAttributes[SEMATTRS_HTTP_FLAVOR];\n //TODO: http.target attribute, it should substitute any parameters to avoid high cardinality.\n return metricAttributes;\n};\n\n/**\n * Returns incoming request attributes scoped to the response data\n * @param {(ServerResponse & { socket: Socket; })} response the response object\n */\nexport const getIncomingRequestAttributesOnResponse = (\n request: IncomingMessage,\n response: ServerResponse\n): SpanAttributes => {\n // take socket from the request,\n // since it may be detached from the response object in keep-alive mode\n const { socket } = request;\n const { statusCode, statusMessage } = response;\n\n const rpcMetadata = getRPCMetadata(context.active());\n const attributes: SpanAttributes = {};\n if (socket) {\n const { localAddress, localPort, remoteAddress, remotePort } = socket;\n attributes[SEMATTRS_NET_HOST_IP] = localAddress;\n attributes[SEMATTRS_NET_HOST_PORT] = localPort;\n attributes[SEMATTRS_NET_PEER_IP] = remoteAddress;\n attributes[SEMATTRS_NET_PEER_PORT] = remotePort;\n }\n attributes[SEMATTRS_HTTP_STATUS_CODE] = statusCode;\n attributes[AttributeNames.HTTP_STATUS_TEXT] = (\n statusMessage || ''\n ).toUpperCase();\n\n if (rpcMetadata?.type === RPCType.HTTP && rpcMetadata.route !== undefined) {\n attributes[SEMATTRS_HTTP_ROUTE] = rpcMetadata.route;\n }\n return attributes;\n};\n\n/**\n * Returns incoming request Metric attributes scoped to the request data\n * @param {SpanAttributes} spanAttributes the span attributes\n */\nexport const getIncomingRequestMetricAttributesOnResponse = (\n spanAttributes: SpanAttributes\n): MetricAttributes => {\n const metricAttributes: MetricAttributes = {};\n metricAttributes[SEMATTRS_HTTP_STATUS_CODE] =\n spanAttributes[SEMATTRS_HTTP_STATUS_CODE];\n metricAttributes[SEMATTRS_NET_HOST_PORT] =\n spanAttributes[SEMATTRS_NET_HOST_PORT];\n if (spanAttributes[SEMATTRS_HTTP_ROUTE] !== undefined) {\n metricAttributes[SEMATTRS_HTTP_ROUTE] = spanAttributes[SEMATTRS_HTTP_ROUTE];\n }\n return metricAttributes;\n};\n\nexport function headerCapture(type: 'request' | 'response', headers: string[]) {\n const normalizedHeaders = new Map<string, string>();\n for (let i = 0, len = headers.length; i < len; i++) {\n const capturedHeader = headers[i].toLowerCase();\n normalizedHeaders.set(capturedHeader, capturedHeader.replace(/-/g, '_'));\n }\n\n return (\n span: Span,\n getHeader: (key: string) => undefined | string | string[] | number\n ) => {\n for (const capturedHeader of normalizedHeaders.keys()) {\n const value = getHeader(capturedHeader);\n\n if (value === undefined) {\n continue;\n }\n\n const normalizedHeader = normalizedHeaders.get(capturedHeader);\n const key = `http.${type}.header.${normalizedHeader}`;\n\n if (typeof value === 'string') {\n span.setAttribute(key, [value]);\n } else if (Array.isArray(value)) {\n span.setAttribute(key, value);\n } else {\n span.setAttribute(key, [value]);\n }\n }\n };\n}\n"]}
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.49.1";
1
+ export declare const VERSION = "0.51.0";
2
2
  //# sourceMappingURL=version.d.ts.map
@@ -17,5 +17,5 @@
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.VERSION = void 0;
19
19
  // this is autogenerated file, see scripts/version-update.js
20
- exports.VERSION = '0.49.1';
20
+ exports.VERSION = '0.51.0';
21
21
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4DAA4D;AAC/C,QAAA,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '0.49.1';\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4DAA4D;AAC/C,QAAA,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '0.51.0';\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentelemetry/instrumentation-http",
3
- "version": "0.49.1",
3
+ "version": "0.51.0",
4
4
  "description": "OpenTelemetry http/https automatic instrumentation package.",
5
5
  "main": "build/src/index.js",
6
6
  "types": "build/src/index.d.ts",
@@ -46,17 +46,17 @@
46
46
  },
47
47
  "devDependencies": {
48
48
  "@opentelemetry/api": "1.8.0",
49
- "@opentelemetry/context-async-hooks": "1.22.0",
50
- "@opentelemetry/sdk-metrics": "1.22.0",
51
- "@opentelemetry/sdk-trace-base": "1.22.0",
52
- "@opentelemetry/sdk-trace-node": "1.22.0",
49
+ "@opentelemetry/context-async-hooks": "1.24.0",
50
+ "@opentelemetry/sdk-metrics": "1.24.0",
51
+ "@opentelemetry/sdk-trace-base": "1.24.0",
52
+ "@opentelemetry/sdk-trace-node": "1.24.0",
53
53
  "@types/mocha": "10.0.6",
54
54
  "@types/node": "18.6.5",
55
55
  "@types/request-promise-native": "1.0.21",
56
56
  "@types/semver": "7.5.6",
57
57
  "@types/sinon": "10.0.20",
58
58
  "@types/superagent": "4.1.24",
59
- "axios": "1.5.1",
59
+ "axios": "1.6.0",
60
60
  "codecov": "3.8.3",
61
61
  "cross-var": "1.1.0",
62
62
  "lerna": "6.6.2",
@@ -74,12 +74,12 @@
74
74
  "@opentelemetry/api": "^1.3.0"
75
75
  },
76
76
  "dependencies": {
77
- "@opentelemetry/core": "1.22.0",
78
- "@opentelemetry/instrumentation": "0.49.1",
79
- "@opentelemetry/semantic-conventions": "1.22.0",
77
+ "@opentelemetry/core": "1.24.0",
78
+ "@opentelemetry/instrumentation": "0.51.0",
79
+ "@opentelemetry/semantic-conventions": "1.24.0",
80
80
  "semver": "^7.5.2"
81
81
  },
82
82
  "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/opentelemetry-instrumentation-http",
83
83
  "sideEffects": false,
84
- "gitHead": "3920b158d08daa776280bde68a79e44bafa4e8ea"
84
+ "gitHead": "3ab4f765d8d696327b7d139ae6a45e7bd7edd924"
85
85
  }