@opentelemetry/instrumentation-http 0.27.0 → 0.28.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
@@ -1,8 +1,6 @@
1
1
  # OpenTelemetry HTTP and HTTPS Instrumentation for Node.js
2
2
 
3
3
  [![NPM Published Version][npm-img]][npm-url]
4
- [![dependencies][dependencies-image]][dependencies-url]
5
- [![devDependencies][devDependencies-image]][devDependencies-url]
6
4
  [![Apache License][license-image]][license-image]
7
5
 
8
6
  This module provides automatic instrumentation for [`http`](https://nodejs.org/api/http.html) and [`https`](https://nodejs.org/api/https.html).
@@ -52,13 +50,20 @@ Http instrumentation has few options available to choose from. You can set the f
52
50
  | [`responseHook`](https://github.com/open-telemetry/opentelemetry-js/blob/main/experimental/packages/opentelemetry-instrumentation-http/src/types.ts#L95) | `HttpResponseCustomAttributeFunction` | Function for adding custom attributes before response is handled |
53
51
  | [`startIncomingSpanHook`](https://github.com/open-telemetry/opentelemetry-js/blob/main/experimental/packages/opentelemetry-instrumentation-http/src/types.ts#L97) | `StartIncomingSpanCustomAttributeFunction` | Function for adding custom attributes before a span is started in incomingRequest |
54
52
  | [`startOutgoingSpanHook`](https://github.com/open-telemetry/opentelemetry-js/blob/main/experimental/packages/opentelemetry-instrumentation-http/src/types.ts#L99) | `StartOutgoingSpanCustomAttributeFunction` | Function for adding custom attributes before a span is started in outgoingRequest |
55
- | [`ignoreIncomingPaths`](https://github.com/open-telemetry/opentelemetry-js/blob/main/experimental/packages/opentelemetry-instrumentation-http/src/types.ts#L87) | `IgnoreMatcher[]` | Http instrumentation will not trace all incoming requests that match paths |
56
- | [`ignoreOutgoingUrls`](https://github.com/open-telemetry/opentelemetry-js/blob/main/experimental/packages/opentelemetry-instrumentation-http/src/types.ts#L89) | `IgnoreMatcher[]` | Http instrumentation will not trace all outgoing requests that match urls |
53
+ | `ignoreIncomingRequestHook` | `IgnoreIncomingRequestFunction` | Http instrumentation will not trace all incoming requests that matched with custom function |
54
+ | `ignoreOutgoingRequestHook` | `IgnoreOutgoingRequestFunction` | Http instrumentation will not trace all outgoing requests that matched with custom function |
57
55
  | [`serverName`](https://github.com/open-telemetry/opentelemetry-js/blob/main/experimental/packages/opentelemetry-instrumentation-http/src/types.ts#L101) | `string` | The primary server name of the matched virtual host. |
58
56
  | [`requireParentforOutgoingSpans`](https://github.com/open-telemetry/opentelemetry-js/blob/main/experimental/packages/opentelemetry-instrumentation-http/src/types.ts#L103) | Boolean | Require that is a parent span to create new span for outgoing requests. |
59
57
  | [`requireParentforIncomingSpans`](https://github.com/open-telemetry/opentelemetry-js/blob/main/experimental/packages/opentelemetry-instrumentation-http/src/types.ts#L105) | Boolean | Require that is a parent span to create new span for incoming requests. |
60
58
  | [`headersToSpanAttributes`](https://github.com/open-telemetry/opentelemetry-js/blob/main/experimental/packages/opentelemetry-instrumentation-http/src/types.ts#L107) | `object` | List of case insensitive HTTP headers to convert to span attributes. Client (outgoing requests, incoming responses) and server (incoming requests, outgoing responses) headers will be converted to span attributes in the form of `http.{request\|response}.header.header_name`, e.g. `http.response.header.content_length` |
61
59
 
60
+ The following options are deprecated:
61
+
62
+ | Options | Type | Description |
63
+ | ------- | ---- | ----------- |
64
+ | `ignoreIncomingPaths` | `IgnoreMatcher[]` | Http instrumentation will not trace all incoming requests that match paths |
65
+ | `ignoreOutgoingUrls` | `IgnoreMatcher[]` | Http instrumentation will not trace all outgoing requests that match urls |
66
+
62
67
  ## Useful links
63
68
 
64
69
  - For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
@@ -72,9 +77,5 @@ Apache 2.0 - See [LICENSE][license-url] for more information.
72
77
  [discussions-url]: https://github.com/open-telemetry/opentelemetry-js/discussions
73
78
  [license-url]: https://github.com/open-telemetry/opentelemetry-js/blob/main/LICENSE
74
79
  [license-image]: https://img.shields.io/badge/license-Apache_2.0-green.svg?style=flat
75
- [dependencies-image]: https://status.david-dm.org/gh/open-telemetry/opentelemetry-js.svg?path=packages%2Fopentelemetry-instrumentation-http
76
- [dependencies-url]: https://david-dm.org/open-telemetry/opentelemetry-js?path=packages%2Fopentelemetry-instrumentation-http
77
- [devDependencies-image]: https://status.david-dm.org/gh/open-telemetry/opentelemetry-js.svg?path=packages%2Fopentelemetry-instrumentation-http&type=dev
78
- [devDependencies-url]: https://david-dm.org/open-telemetry/opentelemetry-js?path=packages%2Fopentelemetry-instrumentation-http&type=dev
79
80
  [npm-url]: https://www.npmjs.com/package/@opentelemetry/instrumentation-http
80
81
  [npm-img]: https://badge.fury.io/js/%40opentelemetry%2Finstrumentation-http.svg
package/build/src/http.js CHANGED
@@ -48,15 +48,15 @@ class HttpInstrumentation extends instrumentation_1.InstrumentationBase {
48
48
  _getHttpInstrumentation() {
49
49
  return new instrumentation_1.InstrumentationNodeModuleDefinition('http', ['*'], moduleExports => {
50
50
  this._diag.debug(`Applying patch for http@${this._version}`);
51
- if (instrumentation_1.isWrapped(moduleExports.request)) {
51
+ if ((0, instrumentation_1.isWrapped)(moduleExports.request)) {
52
52
  this._unwrap(moduleExports, 'request');
53
53
  }
54
54
  this._wrap(moduleExports, 'request', this._getPatchOutgoingRequestFunction('http'));
55
- if (instrumentation_1.isWrapped(moduleExports.get)) {
55
+ if ((0, instrumentation_1.isWrapped)(moduleExports.get)) {
56
56
  this._unwrap(moduleExports, 'get');
57
57
  }
58
58
  this._wrap(moduleExports, 'get', this._getPatchOutgoingGetFunction(moduleExports.request));
59
- if (instrumentation_1.isWrapped(moduleExports.Server.prototype.emit)) {
59
+ if ((0, instrumentation_1.isWrapped)(moduleExports.Server.prototype.emit)) {
60
60
  this._unwrap(moduleExports.Server.prototype, 'emit');
61
61
  }
62
62
  this._wrap(moduleExports.Server.prototype, 'emit', this._getPatchIncomingRequestFunction('http'));
@@ -73,15 +73,15 @@ class HttpInstrumentation extends instrumentation_1.InstrumentationBase {
73
73
  _getHttpsInstrumentation() {
74
74
  return new instrumentation_1.InstrumentationNodeModuleDefinition('https', ['*'], moduleExports => {
75
75
  this._diag.debug(`Applying patch for https@${this._version}`);
76
- if (instrumentation_1.isWrapped(moduleExports.request)) {
76
+ if ((0, instrumentation_1.isWrapped)(moduleExports.request)) {
77
77
  this._unwrap(moduleExports, 'request');
78
78
  }
79
79
  this._wrap(moduleExports, 'request', this._getPatchHttpsOutgoingRequestFunction('https'));
80
- if (instrumentation_1.isWrapped(moduleExports.get)) {
80
+ if ((0, instrumentation_1.isWrapped)(moduleExports.get)) {
81
81
  this._unwrap(moduleExports, 'get');
82
82
  }
83
83
  this._wrap(moduleExports, 'get', this._getPatchHttpsOutgoingGetFunction(moduleExports.request));
84
- if (instrumentation_1.isWrapped(moduleExports.Server.prototype.emit)) {
84
+ if ((0, instrumentation_1.isWrapped)(moduleExports.Server.prototype.emit)) {
85
85
  this._unwrap(moduleExports.Server.prototype, 'emit');
86
86
  }
87
87
  this._wrap(moduleExports.Server.prototype, 'emit', this._getPatchIncomingRequestFunction('https'));
@@ -198,17 +198,19 @@ class HttpInstrumentation extends instrumentation_1.InstrumentationBase {
198
198
  status = { code: api_1.SpanStatusCode.ERROR };
199
199
  }
200
200
  else {
201
- status = utils.parseResponseStatus(response.statusCode);
201
+ status = { code: utils.parseResponseStatus(api_1.SpanKind.CLIENT, response.statusCode) };
202
202
  }
203
203
  span.setStatus(status);
204
204
  if (this._getConfig().applyCustomAttributesOnSpan) {
205
- instrumentation_1.safeExecuteInTheMiddle(() => this._getConfig().applyCustomAttributesOnSpan(span, request, response), () => { }, true);
205
+ (0, instrumentation_1.safeExecuteInTheMiddle)(() => this._getConfig().applyCustomAttributesOnSpan(span, request, response), () => { }, true);
206
206
  }
207
207
  this._closeHttpSpan(span);
208
208
  });
209
209
  response.on('error', (error) => {
210
210
  this._diag.debug('outgoingRequest on error()', error);
211
- utils.setSpanWithError(span, error, response);
211
+ utils.setSpanWithError(span, error);
212
+ const code = utils.parseResponseStatus(api_1.SpanKind.CLIENT, response.statusCode);
213
+ span.setStatus({ code, message: error.message });
212
214
  this._closeHttpSpan(span);
213
215
  });
214
216
  });
@@ -220,7 +222,7 @@ class HttpInstrumentation extends instrumentation_1.InstrumentationBase {
220
222
  });
221
223
  request.on('error', (error) => {
222
224
  this._diag.debug('outgoingRequest on request error()', error);
223
- utils.setSpanWithError(span, error, request);
225
+ utils.setSpanWithError(span, error);
224
226
  this._closeHttpSpan(span);
225
227
  });
226
228
  this._diag.debug('http.ClientRequest return request');
@@ -240,8 +242,13 @@ class HttpInstrumentation extends instrumentation_1.InstrumentationBase {
240
242
  : '/';
241
243
  const method = request.method || 'GET';
242
244
  instrumentation._diag.debug(`${component} instrumentation incomingRequest`);
243
- if (utils.isIgnored(pathname, instrumentation._getConfig().ignoreIncomingPaths, (e) => instrumentation._diag.error('caught ignoreIncomingPaths error: ', e))) {
244
- return api_1.context.with(core_1.suppressTracing(api_1.context.active()), () => {
245
+ if (utils.isIgnored(pathname, instrumentation._getConfig().ignoreIncomingPaths, (e) => instrumentation._diag.error('caught ignoreIncomingPaths error: ', e)) ||
246
+ (0, instrumentation_1.safeExecuteInTheMiddle)(() => { var _a, _b; return (_b = (_a = instrumentation._getConfig()).ignoreIncomingRequestHook) === null || _b === void 0 ? void 0 : _b.call(_a, request); }, (e) => {
247
+ if (e != null) {
248
+ instrumentation._diag.error('caught ignoreIncomingRequestHook error: ', e);
249
+ }
250
+ }, true)) {
251
+ return api_1.context.with((0, core_1.suppressTracing)(api_1.context.active()), () => {
245
252
  api_1.context.bind(api_1.context.active(), request);
246
253
  api_1.context.bind(api_1.context.active(), response);
247
254
  return original.apply(this, [event, ...args]);
@@ -262,7 +269,7 @@ class HttpInstrumentation extends instrumentation_1.InstrumentationBase {
262
269
  type: core_2.RPCType.HTTP,
263
270
  span,
264
271
  };
265
- return api_1.context.with(core_2.setRPCMetadata(api_1.trace.setSpan(ctx, span), rpcMetadata), () => {
272
+ return api_1.context.with((0, core_2.setRPCMetadata)(api_1.trace.setSpan(ctx, span), rpcMetadata), () => {
266
273
  api_1.context.bind(api_1.context.active(), request);
267
274
  api_1.context.bind(api_1.context.active(), response);
268
275
  if (instrumentation._getConfig().requestHook) {
@@ -278,7 +285,7 @@ class HttpInstrumentation extends instrumentation_1.InstrumentationBase {
278
285
  response.end = function (..._args) {
279
286
  response.end = originalEnd;
280
287
  // Cannot pass args of type ResponseEndArgs,
281
- const returned = instrumentation_1.safeExecuteInTheMiddle(() => response.end.apply(this, arguments), error => {
288
+ const returned = (0, instrumentation_1.safeExecuteInTheMiddle)(() => response.end.apply(this, arguments), error => {
282
289
  if (error) {
283
290
  utils.setSpanWithError(span, error);
284
291
  instrumentation._closeHttpSpan(span);
@@ -289,14 +296,14 @@ class HttpInstrumentation extends instrumentation_1.InstrumentationBase {
289
296
  instrumentation._headerCapture.server.captureResponseHeaders(span, header => response.getHeader(header));
290
297
  span
291
298
  .setAttributes(attributes)
292
- .setStatus(utils.parseResponseStatus(response.statusCode));
299
+ .setStatus({ code: utils.parseResponseStatus(api_1.SpanKind.SERVER, response.statusCode) });
293
300
  if (instrumentation._getConfig().applyCustomAttributesOnSpan) {
294
- instrumentation_1.safeExecuteInTheMiddle(() => instrumentation._getConfig().applyCustomAttributesOnSpan(span, request, response), () => { }, true);
301
+ (0, instrumentation_1.safeExecuteInTheMiddle)(() => instrumentation._getConfig().applyCustomAttributesOnSpan(span, request, response), () => { }, true);
295
302
  }
296
303
  instrumentation._closeHttpSpan(span);
297
304
  return returned;
298
305
  };
299
- return instrumentation_1.safeExecuteInTheMiddle(() => original.apply(this, [event, ...args]), error => {
306
+ return (0, instrumentation_1.safeExecuteInTheMiddle)(() => original.apply(this, [event, ...args]), error => {
300
307
  if (error) {
301
308
  utils.setSpanWithError(span, error);
302
309
  instrumentation._closeHttpSpan(span);
@@ -328,7 +335,12 @@ class HttpInstrumentation extends instrumentation_1.InstrumentationBase {
328
335
  optionsParsed.protocol === 'https:') {
329
336
  return original.apply(this, [optionsParsed, ...args]);
330
337
  }
331
- if (utils.isIgnored(origin + pathname, instrumentation._getConfig().ignoreOutgoingUrls, (e) => instrumentation._diag.error('caught ignoreOutgoingUrls error: ', e))) {
338
+ if (utils.isIgnored(origin + pathname, instrumentation._getConfig().ignoreOutgoingUrls, (e) => instrumentation._diag.error('caught ignoreOutgoingUrls error: ', e)) ||
339
+ (0, instrumentation_1.safeExecuteInTheMiddle)(() => { var _a, _b; return (_b = (_a = instrumentation._getConfig()).ignoreOutgoingRequestHook) === null || _b === void 0 ? void 0 : _b.call(_a, optionsParsed); }, (e) => {
340
+ if (e != null) {
341
+ instrumentation._diag.error('caught ignoreOutgoingRequestHook error: ', e);
342
+ }
343
+ }, true)) {
332
344
  return original.apply(this, [optionsParsed, ...args]);
333
345
  }
334
346
  const operationName = `${component.toUpperCase()} ${method}`;
@@ -360,7 +372,7 @@ class HttpInstrumentation extends instrumentation_1.InstrumentationBase {
360
372
  if (typeof cb === 'function') {
361
373
  args[args.length - 1] = api_1.context.bind(parentContext, cb);
362
374
  }
363
- const request = instrumentation_1.safeExecuteInTheMiddle(() => original.apply(this, [optionsParsed, ...args]), error => {
375
+ const request = (0, instrumentation_1.safeExecuteInTheMiddle)(() => original.apply(this, [optionsParsed, ...args]), error => {
364
376
  if (error) {
365
377
  utils.setSpanWithError(span, error);
366
378
  instrumentation._closeHttpSpan(span);
@@ -403,14 +415,14 @@ class HttpInstrumentation extends instrumentation_1.InstrumentationBase {
403
415
  this._spanNotEnded.delete(span);
404
416
  }
405
417
  _callResponseHook(span, response) {
406
- instrumentation_1.safeExecuteInTheMiddle(() => this._getConfig().responseHook(span, response), () => { }, true);
418
+ (0, instrumentation_1.safeExecuteInTheMiddle)(() => this._getConfig().responseHook(span, response), () => { }, true);
407
419
  }
408
420
  _callRequestHook(span, request) {
409
- instrumentation_1.safeExecuteInTheMiddle(() => this._getConfig().requestHook(span, request), () => { }, true);
421
+ (0, instrumentation_1.safeExecuteInTheMiddle)(() => this._getConfig().requestHook(span, request), () => { }, true);
410
422
  }
411
423
  _callStartSpanHook(request, hookFunc) {
412
424
  if (typeof hookFunc === 'function') {
413
- return instrumentation_1.safeExecuteInTheMiddle(() => hookFunc(request), () => { }, true);
425
+ return (0, instrumentation_1.safeExecuteInTheMiddle)(() => hookFunc(request), () => { }, true);
414
426
  }
415
427
  }
416
428
  _createHeaderCapture() {
@@ -1 +1 @@
1
- {"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/http.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,4CAW4B;AAC5B,8CAAsD;AAItD,iCAAiC;AACjC,2BAA2B;AAU3B,iCAAiC;AACjC,uCAAoC;AACpC,oEAKwC;AACxC,8CAA2E;AAE3E;;GAEG;AACH,MAAa,mBAAoB,SAAQ,qCAAyB;IAMhE,YAAY,MAAkC;QAC5C,KAAK,CACH,qCAAqC,EACrC,iBAAO,EACP,MAAM,CACP,CAAC;QAVJ,oCAAoC;QACnB,kBAAa,GAAkB,IAAI,OAAO,EAAQ,CAAC;QACnD,aAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;QAUhD,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,oBAAoB,EAAE,CAAC;IACpD,CAAC;IAEO,UAAU;QAChB,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAEQ,SAAS,CAAC,MAAkC;QACnD,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QACxB,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,oBAAoB,EAAE,CAAC;IACpD,CAAC;IAED,IAAI;QACF,OAAO,CAAC,IAAI,CAAC,wBAAwB,EAAE,EAAE,IAAI,CAAC,uBAAuB,EAAE,CAAC,CAAC;IAC3E,CAAC;IAEO,uBAAuB;QAC7B,OAAO,IAAI,qDAAmC,CAC5C,MAAM,EACN,CAAC,GAAG,CAAC,EACL,aAAa,CAAC,EAAE;YACd,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,2BAA2B,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;YAC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IAEO,kBAAkB,CACxB,OAAmD,EACnD,QAA8B;QAE9B,IAAG,OAAO,QAAQ,KAAK,UAAU,EAAC;YAChC,OAAO,wCAAsB,CAC3B,GAAG,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,EACvB,GAAG,EAAE,GAAG,CAAC,EACT,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,CAAC,SAAS,EAAE,MAAA,MAAA,MAAA,MAAM,CAAC,uBAAuB,0CAAE,MAAM,0CAAE,cAAc,mCAAI,EAAE,CAAC;gBACnH,sBAAsB,EAAE,KAAK,CAAC,aAAa,CAAC,UAAU,EAAE,MAAA,MAAA,MAAA,MAAM,CAAC,uBAAuB,0CAAE,MAAM,0CAAE,eAAe,mCAAI,EAAE,CAAC;aACvH;YACD,MAAM,EAAE;gBACN,qBAAqB,EAAE,KAAK,CAAC,aAAa,CAAC,SAAS,EAAE,MAAA,MAAA,MAAA,MAAM,CAAC,uBAAuB,0CAAE,MAAM,0CAAE,cAAc,mCAAI,EAAE,CAAC;gBACnH,sBAAsB,EAAE,KAAK,CAAC,aAAa,CAAC,UAAU,EAAE,MAAA,MAAA,MAAA,MAAM,CAAC,uBAAuB,0CAAE,MAAM,0CAAE,eAAe,mCAAI,EAAE,CAAC;aACvH;SACF,CAAA;IACH,CAAC;CACF;AA1nBD,kDA0nBC","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 INVALID_SPAN_CONTEXT,\n propagation,\n ROOT_CONTEXT,\n Span,\n SpanKind,\n SpanOptions,\n SpanStatus,\n SpanStatusCode,\n trace,\n} from '@opentelemetry/api';\nimport { suppressTracing } 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 ResponseEndArgs,\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';\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 readonly _version = process.versions.node;\n private _headerCapture;\n\n constructor(config?: HttpInstrumentationConfig) {\n super(\n '@opentelemetry/instrumentation-http',\n VERSION,\n config\n );\n\n this._headerCapture = this._createHeaderCapture();\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(): [InstrumentationNodeModuleDefinition<Https>, InstrumentationNodeModuleDefinition<Http>] {\n return [this._getHttpsInstrumentation(), this._getHttpInstrumentation()];\n }\n\n private _getHttpInstrumentation() {\n return new InstrumentationNodeModuleDefinition<Http>(\n 'http',\n ['*'],\n moduleExports => {\n this._diag.debug(`Applying patch for http@${this._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@${this._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 return new InstrumentationNodeModuleDefinition<Https>(\n 'https',\n ['*'],\n moduleExports => {\n this._diag.debug(`Applying patch for https@${this._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@${this._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 (original: (event: string, ...args: unknown[]) => boolean): (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 options The arguments to the original function.\n * @param span representing the current operation\n */\n private _traceClientRequest(\n request: http.ClientRequest,\n hostname: string,\n span: Span\n ): http.ClientRequest {\n if (this._getConfig().requestHook) {\n this._callRequestHook(span, request);\n }\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 const responseAttributes = utils.getOutgoingRequestAttributesOnResponse(\n response,\n { hostname }\n );\n span.setAttributes(responseAttributes);\n if (this._getConfig().responseHook) {\n this._callResponseHook(span, response);\n }\n\n this._headerCapture.client.captureRequestHeaders(span, header => request.getHeader(header));\n this._headerCapture.client.captureResponseHeaders(span, header => response.headers[header]);\n\n context.bind(context.active(), response);\n this._diag.debug('outgoingRequest on response()');\n response.on('end', () => {\n this._diag.debug('outgoingRequest on end()');\n let status: SpanStatus;\n\n if (response.aborted && !response.complete) {\n status = { code: SpanStatusCode.ERROR };\n } else {\n status = utils.parseResponseStatus(response.statusCode);\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(span);\n });\n response.on('error', (error: Err) => {\n this._diag.debug('outgoingRequest on error()', error);\n utils.setSpanWithError(span, error, response);\n this._closeHttpSpan(span);\n });\n }\n );\n request.on('close', () => {\n this._diag.debug('outgoingRequest on request close()');\n if (!request.aborted) {\n this._closeHttpSpan(span);\n }\n });\n request.on('error', (error: Err) => {\n this._diag.debug('outgoingRequest on request error()', error);\n utils.setSpanWithError(span, error, request);\n this._closeHttpSpan(span);\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(`${component} instrumentation incomingRequest`);\n\n if (\n utils.isIgnored(\n pathname,\n instrumentation._getConfig().ignoreIncomingPaths,\n (e: Error) => instrumentation._diag.error('caught ignoreIncomingPaths error: ', e)\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 spanOptions: SpanOptions = {\n kind: SpanKind.SERVER,\n attributes: 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\n const ctx = propagation.extract(ROOT_CONTEXT, headers);\n const span = instrumentation._startHttpSpan(\n `${component.toLocaleUpperCase()} ${method}`,\n spanOptions,\n ctx\n );\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(span, header => request.headers[header]);\n\n // Wraps end (inspired by:\n // https://github.com/GoogleCloudPlatform/cloud-trace-nodejs/blob/master/src/instrumentations/instrumentation-connect.ts#L75)\n const originalEnd = response.end;\n response.end = function (\n this: http.ServerResponse,\n ..._args: ResponseEndArgs\n ) {\n response.end = originalEnd;\n // Cannot pass args of type ResponseEndArgs,\n const returned = safeExecuteInTheMiddle(\n () => response.end.apply(this, arguments as never),\n error => {\n if (error) {\n utils.setSpanWithError(span, error);\n instrumentation._closeHttpSpan(span);\n throw error;\n }\n }\n );\n\n const attributes = utils.getIncomingRequestAttributesOnResponse(\n request,\n response\n );\n\n instrumentation._headerCapture.server.captureResponseHeaders(span, header => response.getHeader(header));\n\n span\n .setAttributes(attributes)\n .setStatus(utils.parseResponseStatus(response.statusCode));\n\n if (instrumentation._getConfig().applyCustomAttributesOnSpan) {\n safeExecuteInTheMiddle(\n () =>\n instrumentation._getConfig().applyCustomAttributesOnSpan!(\n span,\n request,\n response\n ),\n () => {},\n true\n );\n }\n\n instrumentation._closeHttpSpan(span);\n return returned;\n };\n\n return safeExecuteInTheMiddle(\n () => original.apply(this, [event, ...args]),\n error => {\n if (error) {\n utils.setSpanWithError(span, error);\n instrumentation._closeHttpSpan(span);\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: Error) => instrumentation._diag.error('caught ignoreOutgoingUrls error: ', e)\n )\n ) {\n return original.apply(this, [optionsParsed, ...args]);\n }\n\n const operationName = `${component.toUpperCase()} ${method}`;\n\n const hostname =\n optionsParsed.hostname ||\n optionsParsed.host?.replace(/^(.*)(:[0-9]{1,5})/, '$1') ||\n 'localhost';\n const attributes = utils.getOutgoingRequestAttributes(optionsParsed, {\n component,\n hostname,\n hookAttributes: instrumentation._callStartSpanHook(\n optionsParsed,\n instrumentation._getConfig().startOutgoingSpanHook\n ),\n });\n\n const spanOptions: SpanOptions = {\n kind: SpanKind.CLIENT,\n attributes,\n };\n const span = instrumentation._startHttpSpan(operationName, spanOptions);\n\n const parentContext = context.active();\n const requestContext = trace.setSpan(parentContext, span);\n\n if (!optionsParsed.headers) {\n 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(span);\n throw error;\n }\n }\n );\n\n instrumentation._diag.debug(`${component} instrumentation outgoingRequest`);\n context.bind(parentContext, request);\n return instrumentation._traceClientRequest(\n request,\n hostname,\n span\n );\n });\n };\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(span: Span) {\n if (!this._spanNotEnded.has(span)) {\n return;\n }\n\n span.end();\n this._spanNotEnded.delete(span);\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('request', config.headersToSpanAttributes?.client?.requestHeaders ?? []),\n captureResponseHeaders: utils.headerCapture('response', config.headersToSpanAttributes?.client?.responseHeaders ?? [])\n },\n server: {\n captureRequestHeaders: utils.headerCapture('request', config.headersToSpanAttributes?.server?.requestHeaders ?? []),\n captureResponseHeaders: utils.headerCapture('response', config.headersToSpanAttributes?.server?.responseHeaders ?? []),\n }\n }\n }\n}\n"]}
1
+ {"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/http.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,4CAW4B;AAC5B,8CAAsD;AAItD,iCAAiC;AACjC,2BAA2B;AAU3B,iCAAiC;AACjC,uCAAoC;AACpC,oEAKwC;AACxC,8CAA2E;AAE3E;;GAEG;AACH,MAAa,mBAAoB,SAAQ,qCAAyB;IAMhE,YAAY,MAAkC;QAC5C,KAAK,CACH,qCAAqC,EACrC,iBAAO,EACP,MAAM,CACP,CAAC;QAVJ,oCAAoC;QACnB,kBAAa,GAAkB,IAAI,OAAO,EAAQ,CAAC;QACnD,aAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;QAUhD,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,oBAAoB,EAAE,CAAC;IACpD,CAAC;IAEO,UAAU;QAChB,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAEQ,SAAS,CAAC,MAAkC;QACnD,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QACxB,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,oBAAoB,EAAE,CAAC;IACpD,CAAC;IAED,IAAI;QACF,OAAO,CAAC,IAAI,CAAC,wBAAwB,EAAE,EAAE,IAAI,CAAC,uBAAuB,EAAE,CAAC,CAAC;IAC3E,CAAC;IAEO,uBAAuB;QAC7B,OAAO,IAAI,qDAAmC,CAC5C,MAAM,EACN,CAAC,GAAG,CAAC,EACL,aAAa,CAAC,EAAE;YACd,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,2BAA2B,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;YAC7D,IAAI,IAAA,2BAAS,EAAC,aAAa,CAAC,OAAO,CAAC,E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AEjC,OAAO;YACL,MAAM,EAAE;gBACN,qBAAqB,EAAE,KAAK,CAAC,aAAa,CAAC,SAAS,EAAE,MAAA,MAAA,MAAA,MAAM,CAAC,uBAAuB,0CAAE,MAAM,0CAAE,cAAc,mCAAI,EAAE,CAAC;gBACnH,sBAAsB,EAAE,KAAK,CAAC,aAAa,CAAC,UAAU,EAAE,MAAA,MAAA,MAAA,MAAM,CAAC,uBAAuB,0CAAE,MAAM,0CAAE,eAAe,mCAAI,EAAE,CAAC;aACvH;YACD,MAAM,EAAE;gBACN,qBAAqB,EAAE,KAAK,CAAC,aAAa,CAAC,SAAS,EAAE,MAAA,MAAA,MAAA,MAAM,CAAC,uBAAuB,0CAAE,MAAM,0CAAE,cAAc,mCAAI,EAAE,CAAC;gBACnH,sBAAsB,EAAE,KAAK,CAAC,aAAa,CAAC,UAAU,EAAE,MAAA,MAAA,MAAA,MAAM,CAAC,uBAAuB,0CAAE,MAAM,0CAAE,eAAe,mCAAI,EAAE,CAAC;aACvH;SACF,CAAC;IACJ,CAAC;CACF;AA9oBD,kDA8oBC","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 INVALID_SPAN_CONTEXT,\n propagation,\n ROOT_CONTEXT,\n Span,\n SpanKind,\n SpanOptions,\n SpanStatus,\n SpanStatusCode,\n trace,\n} from '@opentelemetry/api';\nimport { suppressTracing } 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 ResponseEndArgs,\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';\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 readonly _version = process.versions.node;\n private _headerCapture;\n\n constructor(config?: HttpInstrumentationConfig) {\n super(\n '@opentelemetry/instrumentation-http',\n VERSION,\n config\n );\n\n this._headerCapture = this._createHeaderCapture();\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(): [InstrumentationNodeModuleDefinition<Https>, InstrumentationNodeModuleDefinition<Http>] {\n return [this._getHttpsInstrumentation(), this._getHttpInstrumentation()];\n }\n\n private _getHttpInstrumentation() {\n return new InstrumentationNodeModuleDefinition<Http>(\n 'http',\n ['*'],\n moduleExports => {\n this._diag.debug(`Applying patch for http@${this._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@${this._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 return new InstrumentationNodeModuleDefinition<Https>(\n 'https',\n ['*'],\n moduleExports => {\n this._diag.debug(`Applying patch for https@${this._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@${this._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 (original: (event: string, ...args: unknown[]) => boolean): (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 options The arguments to the original function.\n * @param span representing the current operation\n */\n private _traceClientRequest(\n request: http.ClientRequest,\n hostname: string,\n span: Span\n ): http.ClientRequest {\n if (this._getConfig().requestHook) {\n this._callRequestHook(span, request);\n }\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 const responseAttributes = utils.getOutgoingRequestAttributesOnResponse(\n response,\n { hostname }\n );\n span.setAttributes(responseAttributes);\n if (this._getConfig().responseHook) {\n this._callResponseHook(span, response);\n }\n\n this._headerCapture.client.captureRequestHeaders(span, header => request.getHeader(header));\n this._headerCapture.client.captureResponseHeaders(span, header => response.headers[header]);\n\n context.bind(context.active(), response);\n this._diag.debug('outgoingRequest on response()');\n response.on('end', () => {\n this._diag.debug('outgoingRequest on end()');\n let status: SpanStatus;\n\n if (response.aborted && !response.complete) {\n status = { code: SpanStatusCode.ERROR };\n } else {\n status = { code: utils.parseResponseStatus(SpanKind.CLIENT, response.statusCode) };\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(span);\n });\n response.on('error', (error: Err) => {\n this._diag.debug('outgoingRequest on error()', error);\n utils.setSpanWithError(span, error);\n const code = utils.parseResponseStatus(SpanKind.CLIENT, response.statusCode);\n span.setStatus({ code, message: error.message });\n this._closeHttpSpan(span);\n });\n }\n );\n request.on('close', () => {\n this._diag.debug('outgoingRequest on request close()');\n if (!request.aborted) {\n this._closeHttpSpan(span);\n }\n });\n request.on('error', (error: Err) => {\n this._diag.debug('outgoingRequest on request error()', error);\n utils.setSpanWithError(span, error);\n this._closeHttpSpan(span);\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(`${component} instrumentation incomingRequest`);\n\n if (\n utils.isIgnored(\n pathname,\n instrumentation._getConfig().ignoreIncomingPaths,\n (e: unknown) => instrumentation._diag.error('caught ignoreIncomingPaths error: ', e)\n ) ||\n safeExecuteInTheMiddle(\n () => instrumentation._getConfig().ignoreIncomingRequestHook?.(request),\n (e: unknown) => {\n if (e != null) {\n instrumentation._diag.error('caught ignoreIncomingRequestHook error: ', e);\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 spanOptions: SpanOptions = {\n kind: SpanKind.SERVER,\n attributes: 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\n const ctx = propagation.extract(ROOT_CONTEXT, headers);\n const span = instrumentation._startHttpSpan(\n `${component.toLocaleUpperCase()} ${method}`,\n spanOptions,\n ctx\n );\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(span, header => request.headers[header]);\n\n // Wraps end (inspired by:\n // https://github.com/GoogleCloudPlatform/cloud-trace-nodejs/blob/master/src/instrumentations/instrumentation-connect.ts#L75)\n const originalEnd = response.end;\n response.end = function (\n this: http.ServerResponse,\n ..._args: ResponseEndArgs\n ) {\n response.end = originalEnd;\n // Cannot pass args of type ResponseEndArgs,\n const returned = safeExecuteInTheMiddle(\n () => response.end.apply(this, arguments as never),\n error => {\n if (error) {\n utils.setSpanWithError(span, error);\n instrumentation._closeHttpSpan(span);\n throw error;\n }\n }\n );\n\n const attributes = utils.getIncomingRequestAttributesOnResponse(\n request,\n response\n );\n\n instrumentation._headerCapture.server.captureResponseHeaders(span, header => response.getHeader(header));\n\n span\n .setAttributes(attributes)\n .setStatus({ code: utils.parseResponseStatus(SpanKind.SERVER, response.statusCode) });\n\n if (instrumentation._getConfig().applyCustomAttributesOnSpan) {\n safeExecuteInTheMiddle(\n () =>\n instrumentation._getConfig().applyCustomAttributesOnSpan!(\n span,\n request,\n response\n ),\n () => {},\n true\n );\n }\n\n instrumentation._closeHttpSpan(span);\n return returned;\n };\n\n return safeExecuteInTheMiddle(\n () => original.apply(this, [event, ...args]),\n error => {\n if (error) {\n utils.setSpanWithError(span, error);\n instrumentation._closeHttpSpan(span);\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) => instrumentation._diag.error('caught ignoreOutgoingUrls error: ', e)\n ) ||\n safeExecuteInTheMiddle(\n () => instrumentation._getConfig().ignoreOutgoingRequestHook?.(optionsParsed),\n (e: unknown) => {\n if (e != null) {\n instrumentation._diag.error('caught ignoreOutgoingRequestHook error: ', e);\n }\n },\n true\n )\n ) {\n return original.apply(this, [optionsParsed, ...args]);\n }\n\n const operationName = `${component.toUpperCase()} ${method}`;\n\n const hostname =\n optionsParsed.hostname ||\n optionsParsed.host?.replace(/^(.*)(:[0-9]{1,5})/, '$1') ||\n 'localhost';\n const attributes = utils.getOutgoingRequestAttributes(optionsParsed, {\n component,\n hostname,\n hookAttributes: instrumentation._callStartSpanHook(\n optionsParsed,\n instrumentation._getConfig().startOutgoingSpanHook\n ),\n });\n\n const spanOptions: SpanOptions = {\n kind: SpanKind.CLIENT,\n attributes,\n };\n const span = instrumentation._startHttpSpan(operationName, spanOptions);\n\n const parentContext = context.active();\n const requestContext = trace.setSpan(parentContext, span);\n\n if (!optionsParsed.headers) {\n 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(span);\n throw error;\n }\n }\n );\n\n instrumentation._diag.debug(`${component} instrumentation outgoingRequest`);\n context.bind(parentContext, request);\n return instrumentation._traceClientRequest(\n request,\n hostname,\n span\n );\n });\n };\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(span: Span) {\n if (!this._spanNotEnded.has(span)) {\n return;\n }\n\n span.end();\n this._spanNotEnded.delete(span);\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('request', config.headersToSpanAttributes?.client?.requestHeaders ?? []),\n captureResponseHeaders: utils.headerCapture('response', config.headersToSpanAttributes?.client?.responseHeaders ?? [])\n },\n server: {\n captureRequestHeaders: utils.headerCapture('request', config.headersToSpanAttributes?.server?.requestHeaders ?? []),\n captureResponseHeaders: utils.headerCapture('response', config.headersToSpanAttributes?.server?.responseHeaders ?? []),\n }\n };\n }\n}\n"]}
@@ -20,6 +20,12 @@ export declare type ResponseEndArgs = [((() => void) | undefined)?] | [unknown,
20
20
  export interface HttpCustomAttributeFunction {
21
21
  (span: Span, request: ClientRequest | IncomingMessage, response: IncomingMessage | ServerResponse): void;
22
22
  }
23
+ export interface IgnoreIncomingRequestFunction {
24
+ (request: IncomingMessage): boolean;
25
+ }
26
+ export interface IgnoreOutgoingRequestFunction {
27
+ (request: RequestOptions): boolean;
28
+ }
23
29
  export interface HttpRequestCustomAttributeFunction {
24
30
  (span: Span, request: ClientRequest | IncomingMessage): void;
25
31
  }
@@ -36,10 +42,20 @@ export interface StartOutgoingSpanCustomAttributeFunction {
36
42
  * Options available for the HTTP instrumentation (see [documentation](https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-instrumentation-http#http-instrumentation-options))
37
43
  */
38
44
  export interface HttpInstrumentationConfig extends InstrumentationConfig {
39
- /** Not trace all incoming requests that match paths */
45
+ /**
46
+ * Not trace all incoming requests that match paths
47
+ * @deprecated use `ignoreIncomingRequestHook` instead
48
+ */
40
49
  ignoreIncomingPaths?: IgnoreMatcher[];
41
- /** Not trace all outgoing requests that match urls */
50
+ /** Not trace all incoming requests that matched with custom function */
51
+ ignoreIncomingRequestHook?: IgnoreIncomingRequestFunction;
52
+ /**
53
+ * Not trace all outgoing requests that match urls
54
+ * @deprecated use `ignoreOutgoingRequestHook` instead
55
+ */
42
56
  ignoreOutgoingUrls?: IgnoreMatcher[];
57
+ /** Not trace all outgoing requests that matched with custom function */
58
+ ignoreOutgoingRequestHook?: IgnoreOutgoingRequestFunction;
43
59
  /** Function for adding custom attributes after response is handled */
44
60
  applyCustomAttributesOnSpan?: HttpCustomAttributeFunction;
45
61
  /** Function for adding custom attributes before request is handled */
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"","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 Span,\n SpanAttributes,\n } from '@opentelemetry/api';\nimport type * as http from 'http';\nimport type * as https from 'https';\nimport {\n ClientRequest,\n get,\n IncomingMessage,\n request,\n ServerResponse,\n RequestOptions,\n} from 'http';\nimport * as url from 'url';\nimport { InstrumentationConfig } from '@opentelemetry/instrumentation';\n\nexport type IgnoreMatcher = string | RegExp | ((url: string) => boolean);\nexport type HttpCallback = (res: IncomingMessage) => void;\nexport type RequestFunction = typeof request;\nexport type GetFunction = typeof get;\n\nexport type HttpCallbackOptional = HttpCallback | undefined;\n\n// from node 10+\nexport type RequestSignature = [http.RequestOptions, HttpCallbackOptional] &\n HttpCallback;\n\nexport type HttpRequestArgs = Array<HttpCallbackOptional | RequestSignature>;\n\nexport type ParsedRequestOptions =\n | (http.RequestOptions & Partial<url.UrlWithParsedQuery>)\n | http.RequestOptions;\nexport type Http = typeof http;\nexport type Https = typeof https;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type Func<T> = (...args: any[]) => T;\nexport type ResponseEndArgs =\n | [((() => void) | undefined)?]\n | [unknown, ((() => void) | undefined)?]\n | [unknown, string, ((() => void) | undefined)?];\n\nexport interface HttpCustomAttributeFunction {\n (\n span: Span,\n request: ClientRequest | IncomingMessage,\n response: IncomingMessage | ServerResponse\n ): void;\n}\n\nexport interface HttpRequestCustomAttributeFunction {\n (span: Span, request: ClientRequest | IncomingMessage): void;\n}\n\nexport interface HttpResponseCustomAttributeFunction {\n (span: Span, response: IncomingMessage | ServerResponse): void;\n}\n\nexport interface StartIncomingSpanCustomAttributeFunction {\n (request: IncomingMessage ): SpanAttributes;\n}\n\nexport interface StartOutgoingSpanCustomAttributeFunction {\n (request: RequestOptions ): SpanAttributes;\n}\n\n/**\n * Options available for the HTTP instrumentation (see [documentation](https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-instrumentation-http#http-instrumentation-options))\n */\nexport interface HttpInstrumentationConfig extends InstrumentationConfig {\n /** Not trace all incoming requests that match paths */\n ignoreIncomingPaths?: IgnoreMatcher[];\n /** Not trace all outgoing requests that match urls */\n ignoreOutgoingUrls?: IgnoreMatcher[];\n /** Function for adding custom attributes after response is handled */\n applyCustomAttributesOnSpan?: HttpCustomAttributeFunction;\n /** Function for adding custom attributes before request is handled */\n requestHook?: HttpRequestCustomAttributeFunction;\n /** Function for adding custom attributes before response is handled */\n responseHook?: HttpResponseCustomAttributeFunction;\n /** Function for adding custom attributes before a span is started in incomingRequest */\n startIncomingSpanHook?: StartIncomingSpanCustomAttributeFunction;\n /** Function for adding custom attributes before a span is started in outgoingRequest */\n startOutgoingSpanHook?: StartOutgoingSpanCustomAttributeFunction;\n /** The primary server name of the matched virtual host. */\n serverName?: string;\n /** Require parent to create span for outgoing requests */\n requireParentforOutgoingSpans?: boolean;\n /** Require parent to create span for incoming requests */\n requireParentforIncomingSpans?: boolean;\n /** Map the following HTTP headers to span attributes. */\n headersToSpanAttributes?: {\n client?: { requestHeaders?: string[]; responseHeaders?: string[]; },\n server?: { requestHeaders?: string[]; responseHeaders?: string[]; },\n }\n}\n\nexport interface Err extends Error {\n errno?: number;\n code?: string;\n path?: string;\n syscall?: string;\n stack?: string;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"","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 Span,\n SpanAttributes,\n } from '@opentelemetry/api';\nimport type * as http from 'http';\nimport type * as https from 'https';\nimport {\n ClientRequest,\n get,\n IncomingMessage,\n request,\n ServerResponse,\n RequestOptions,\n} from 'http';\nimport * as url from 'url';\nimport { InstrumentationConfig } from '@opentelemetry/instrumentation';\n\nexport type IgnoreMatcher = string | RegExp | ((url: string) => boolean);\nexport type HttpCallback = (res: IncomingMessage) => void;\nexport type RequestFunction = typeof request;\nexport type GetFunction = typeof get;\n\nexport type HttpCallbackOptional = HttpCallback | undefined;\n\n// from node 10+\nexport type RequestSignature = [http.RequestOptions, HttpCallbackOptional] &\n HttpCallback;\n\nexport type HttpRequestArgs = Array<HttpCallbackOptional | RequestSignature>;\n\nexport type ParsedRequestOptions =\n | (http.RequestOptions & Partial<url.UrlWithParsedQuery>)\n | http.RequestOptions;\nexport type Http = typeof http;\nexport type Https = typeof https;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type Func<T> = (...args: any[]) => T;\nexport type ResponseEndArgs =\n | [((() => void) | undefined)?]\n | [unknown, ((() => void) | undefined)?]\n | [unknown, string, ((() => void) | undefined)?];\n\nexport interface HttpCustomAttributeFunction {\n (\n span: Span,\n request: ClientRequest | IncomingMessage,\n response: IncomingMessage | ServerResponse\n ): void;\n}\n\nexport interface IgnoreIncomingRequestFunction {\n (request: IncomingMessage ): boolean;\n}\n\nexport interface IgnoreOutgoingRequestFunction {\n (request: RequestOptions ): boolean;\n}\n\nexport interface HttpRequestCustomAttributeFunction {\n (span: Span, request: ClientRequest | IncomingMessage): void;\n}\n\nexport interface HttpResponseCustomAttributeFunction {\n (span: Span, response: IncomingMessage | ServerResponse): void;\n}\n\nexport interface StartIncomingSpanCustomAttributeFunction {\n (request: IncomingMessage ): SpanAttributes;\n}\n\nexport interface StartOutgoingSpanCustomAttributeFunction {\n (request: RequestOptions ): SpanAttributes;\n}\n\n/**\n * Options available for the HTTP instrumentation (see [documentation](https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-instrumentation-http#http-instrumentation-options))\n */\nexport interface HttpInstrumentationConfig extends InstrumentationConfig {\n /**\n * Not trace all incoming requests that match paths\n * @deprecated use `ignoreIncomingRequestHook` instead\n */\n ignoreIncomingPaths?: IgnoreMatcher[];\n /** Not trace all incoming requests that matched with custom function */\n ignoreIncomingRequestHook?: IgnoreIncomingRequestFunction;\n /**\n * Not trace all outgoing requests that match urls\n * @deprecated use `ignoreOutgoingRequestHook` instead\n */\n ignoreOutgoingUrls?: IgnoreMatcher[];\n /** Not trace all outgoing requests that matched with custom function */\n ignoreOutgoingRequestHook?: IgnoreOutgoingRequestFunction;\n /** Function for adding custom attributes after response is handled */\n applyCustomAttributesOnSpan?: HttpCustomAttributeFunction;\n /** Function for adding custom attributes before request is handled */\n requestHook?: HttpRequestCustomAttributeFunction;\n /** Function for adding custom attributes before response is handled */\n responseHook?: HttpResponseCustomAttributeFunction;\n /** Function for adding custom attributes before a span is started in incomingRequest */\n startIncomingSpanHook?: StartIncomingSpanCustomAttributeFunction;\n /** Function for adding custom attributes before a span is started in outgoingRequest */\n startOutgoingSpanHook?: StartOutgoingSpanCustomAttributeFunction;\n /** The primary server name of the matched virtual host. */\n serverName?: string;\n /** Require parent to create span for outgoing requests */\n requireParentforOutgoingSpans?: boolean;\n /** Require parent to create span for incoming requests */\n requireParentforIncomingSpans?: boolean;\n /** Map the following HTTP headers to span attributes. */\n headersToSpanAttributes?: {\n client?: { requestHeaders?: string[]; responseHeaders?: string[]; },\n server?: { requestHeaders?: string[]; responseHeaders?: string[]; },\n }\n}\n\nexport interface Err extends Error {\n errno?: number;\n code?: string;\n path?: string;\n syscall?: string;\n stack?: string;\n}\n"]}
@@ -1,6 +1,5 @@
1
- /// <reference types="node" />
2
- import { SpanAttributes, Span, SpanStatus } from '@opentelemetry/api';
3
- import { ClientRequest, IncomingHttpHeaders, IncomingMessage, OutgoingHttpHeaders, RequestOptions, ServerResponse } from 'http';
1
+ import { SpanAttributes, SpanStatusCode, Span, SpanKind } from '@opentelemetry/api';
2
+ import { IncomingHttpHeaders, IncomingMessage, OutgoingHttpHeaders, RequestOptions, ServerResponse } from 'http';
4
3
  import * as url from 'url';
5
4
  import { Err, IgnoreMatcher, ParsedRequestOptions } from './types';
6
5
  /**
@@ -10,12 +9,7 @@ export declare const getAbsoluteUrl: (requestUrl: ParsedRequestOptions | null, h
10
9
  /**
11
10
  * Parse status code from HTTP response. [More details](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/data-http.md#status)
12
11
  */
13
- export declare const parseResponseStatus: (statusCode: number | undefined) => Omit<SpanStatus, 'message'>;
14
- /**
15
- * Returns whether the Expect header is on the given options object.
16
- * @param options Options for http.request.
17
- */
18
- export declare const hasExpectHeader: (options: RequestOptions) => boolean;
12
+ export declare const parseResponseStatus: (kind: SpanKind, statusCode?: number | undefined) => SpanStatusCode;
19
13
  /**
20
14
  * Check whether the given obj match pattern
21
15
  * @param constant e.g URL of request
@@ -30,14 +24,13 @@ export declare const satisfiesPattern: (constant: string, pattern: IgnoreMatcher
30
24
  * @param [onException] callback for doing something when an exception has
31
25
  * occurred
32
26
  */
33
- export declare const isIgnored: (constant: string, list?: IgnoreMatcher[] | undefined, onException?: ((error: Error) => void) | undefined) => boolean;
27
+ export declare const isIgnored: (constant: string, list?: IgnoreMatcher[] | undefined, onException?: ((error: unknown) => void) | undefined) => boolean;
34
28
  /**
35
29
  * Sets the span with the error passed in params
36
30
  * @param {Span} span the span that need to be set
37
31
  * @param {Error} error error that will be set to span
38
- * @param {(IncomingMessage | ClientRequest)} [obj] used for enriching the status by checking the statusCode.
39
32
  */
40
- export declare const setSpanWithError: (span: Span, error: Err, obj?: IncomingMessage | ClientRequest | undefined) => void;
33
+ export declare const setSpanWithError: (span: Span, error: Err) => void;
41
34
  /**
42
35
  * Adds attributes for request content-length and content-encoding HTTP headers
43
36
  * @param { IncomingMessage } Request object whose headers will be analyzed
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.headerCapture = exports.getIncomingRequestAttributesOnResponse = exports.getIncomingRequestAttributes = exports.getOutgoingRequestAttributesOnResponse = exports.getAttributesFromHttpKind = exports.getOutgoingRequestAttributes = exports.isValidOptionsType = exports.getRequestInfo = exports.isCompressed = exports.setResponseContentLengthAttribute = exports.setRequestContentLengthAttribute = exports.setSpanWithError = exports.isIgnored = exports.satisfiesPattern = exports.hasExpectHeader = exports.parseResponseStatus = exports.getAbsoluteUrl = void 0;
3
+ exports.headerCapture = exports.getIncomingRequestAttributesOnResponse = exports.getIncomingRequestAttributes = exports.getOutgoingRequestAttributesOnResponse = exports.getAttributesFromHttpKind = exports.getOutgoingRequestAttributes = 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
  *
@@ -44,30 +44,17 @@ exports.getAbsoluteUrl = getAbsoluteUrl;
44
44
  /**
45
45
  * Parse status code from HTTP response. [More details](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/data-http.md#status)
46
46
  */
47
- const parseResponseStatus = (statusCode) => {
48
- if (statusCode === undefined) {
49
- return { code: api_1.SpanStatusCode.ERROR };
50
- }
51
- // 1xx, 2xx, 3xx are OK
52
- if (statusCode >= 100 && statusCode < 400) {
53
- return { code: api_1.SpanStatusCode.OK };
47
+ const parseResponseStatus = (kind, statusCode) => {
48
+ const upperBound = kind === api_1.SpanKind.CLIENT ? 400 : 500;
49
+ // 1xx, 2xx, 3xx are OK on client and server
50
+ // 4xx is OK on server
51
+ if (statusCode && statusCode >= 100 && statusCode < upperBound) {
52
+ return api_1.SpanStatusCode.UNSET;
54
53
  }
55
54
  // All other codes are error
56
- return { code: api_1.SpanStatusCode.ERROR };
55
+ return api_1.SpanStatusCode.ERROR;
57
56
  };
58
57
  exports.parseResponseStatus = parseResponseStatus;
59
- /**
60
- * Returns whether the Expect header is on the given options object.
61
- * @param options Options for http.request.
62
- */
63
- const hasExpectHeader = (options) => {
64
- if (!options.headers) {
65
- return false;
66
- }
67
- const keys = Object.keys(options.headers);
68
- return !!keys.find(key => key.toLowerCase() === 'expect');
69
- };
70
- exports.hasExpectHeader = hasExpectHeader;
71
58
  /**
72
59
  * Check whether the given obj match pattern
73
60
  * @param constant e.g URL of request
@@ -104,7 +91,7 @@ const isIgnored = (constant, list, onException) => {
104
91
  // Try/catch outside the loop for failing fast
105
92
  try {
106
93
  for (const pattern of list) {
107
- if (exports.satisfiesPattern(constant, pattern)) {
94
+ if ((0, exports.satisfiesPattern)(constant, pattern)) {
108
95
  return true;
109
96
  }
110
97
  }
@@ -121,30 +108,14 @@ exports.isIgnored = isIgnored;
121
108
  * Sets the span with the error passed in params
122
109
  * @param {Span} span the span that need to be set
123
110
  * @param {Error} error error that will be set to span
124
- * @param {(IncomingMessage | ClientRequest)} [obj] used for enriching the status by checking the statusCode.
125
111
  */
126
- const setSpanWithError = (span, error, obj) => {
112
+ const setSpanWithError = (span, error) => {
127
113
  const message = error.message;
128
114
  span.setAttributes({
129
115
  [AttributeNames_1.AttributeNames.HTTP_ERROR_NAME]: error.name,
130
116
  [AttributeNames_1.AttributeNames.HTTP_ERROR_MESSAGE]: message,
131
117
  });
132
- if (!obj) {
133
- span.setStatus({ code: api_1.SpanStatusCode.ERROR, message });
134
- return;
135
- }
136
- let status;
137
- if (obj.statusCode) {
138
- status = exports.parseResponseStatus(obj.statusCode);
139
- }
140
- else if (obj.aborted) {
141
- status = { code: api_1.SpanStatusCode.ERROR };
142
- }
143
- else {
144
- status = { code: api_1.SpanStatusCode.ERROR };
145
- }
146
- status.message = message;
147
- span.setStatus(status);
118
+ span.setStatus({ code: api_1.SpanStatusCode.ERROR, message });
148
119
  };
149
120
  exports.setSpanWithError = setSpanWithError;
150
121
  /**
@@ -156,7 +127,7 @@ const setRequestContentLengthAttribute = (request, attributes) => {
156
127
  const length = getContentLength(request.headers);
157
128
  if (length === null)
158
129
  return;
159
- if (exports.isCompressed(request.headers)) {
130
+ if ((0, exports.isCompressed)(request.headers)) {
160
131
  attributes[semantic_conventions_1.SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH] = length;
161
132
  }
162
133
  else {
@@ -173,7 +144,7 @@ const setResponseContentLengthAttribute = (response, attributes) => {
173
144
  const length = getContentLength(response.headers);
174
145
  if (length === null)
175
146
  return;
176
- if (exports.isCompressed(response.headers)) {
147
+ if ((0, exports.isCompressed)(response.headers)) {
177
148
  attributes[semantic_conventions_1.SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH] = length;
178
149
  }
179
150
  else {
@@ -202,6 +173,7 @@ exports.isCompressed = isCompressed;
202
173
  * @param [extraOptions] additional options for the request
203
174
  */
204
175
  const getRequestInfo = (options, extraOptions) => {
176
+ var _a;
205
177
  let pathname = '/';
206
178
  let origin = '';
207
179
  let optionsParsed;
@@ -241,18 +213,17 @@ const getRequestInfo = (options, extraOptions) => {
241
213
  }
242
214
  origin = `${optionsParsed.protocol || 'http:'}//${optionsParsed.host || `${optionsParsed.hostname}:${optionsParsed.port}`}`;
243
215
  }
244
- if (exports.hasExpectHeader(optionsParsed)) {
245
- optionsParsed.headers = Object.assign({}, optionsParsed.headers);
246
- }
247
- else if (!optionsParsed.headers) {
248
- optionsParsed.headers = {};
249
- }
216
+ const headers = (_a = optionsParsed.headers) !== null && _a !== void 0 ? _a : {};
217
+ optionsParsed.headers = Object.keys(headers).reduce((normalizedHeader, key) => {
218
+ normalizedHeader[key.toLowerCase()] = headers[key];
219
+ return normalizedHeader;
220
+ }, {});
250
221
  // some packages return method in lowercase..
251
222
  // ensure upperCase for consistency
252
223
  const method = optionsParsed.method
253
224
  ? optionsParsed.method.toUpperCase()
254
225
  : 'GET';
255
- return { origin, pathname, method, optionsParsed };
226
+ return { origin, pathname, method, optionsParsed, };
256
227
  };
257
228
  exports.getRequestInfo = getRequestInfo;
258
229
  /**
@@ -282,7 +253,7 @@ const getOutgoingRequestAttributes = (requestOptions, options) => {
282
253
  const headers = requestOptions.headers || {};
283
254
  const userAgent = headers['user-agent'];
284
255
  const attributes = {
285
- [semantic_conventions_1.SemanticAttributes.HTTP_URL]: exports.getAbsoluteUrl(requestOptions, headers, `${options.component}:`),
256
+ [semantic_conventions_1.SemanticAttributes.HTTP_URL]: (0, exports.getAbsoluteUrl)(requestOptions, headers, `${options.component}:`),
286
257
  [semantic_conventions_1.SemanticAttributes.HTTP_METHOD]: method,
287
258
  [semantic_conventions_1.SemanticAttributes.HTTP_TARGET]: requestOptions.path || '/',
288
259
  [semantic_conventions_1.SemanticAttributes.NET_PEER_NAME]: hostname,
@@ -324,12 +295,12 @@ const getOutgoingRequestAttributesOnResponse = (response, options) => {
324
295
  [semantic_conventions_1.SemanticAttributes.NET_PEER_PORT]: remotePort,
325
296
  [semantic_conventions_1.SemanticAttributes.HTTP_HOST]: `${options.hostname}:${remotePort}`,
326
297
  };
327
- exports.setResponseContentLengthAttribute(response, attributes);
298
+ (0, exports.setResponseContentLengthAttribute)(response, attributes);
328
299
  if (statusCode) {
329
300
  attributes[semantic_conventions_1.SemanticAttributes.HTTP_STATUS_CODE] = statusCode;
330
301
  attributes[AttributeNames_1.AttributeNames.HTTP_STATUS_TEXT] = (statusMessage || '').toUpperCase();
331
302
  }
332
- const httpKindAttributes = exports.getAttributesFromHttpKind(httpVersion);
303
+ const httpKindAttributes = (0, exports.getAttributesFromHttpKind)(httpVersion);
333
304
  return Object.assign(attributes, httpKindAttributes);
334
305
  };
335
306
  exports.getOutgoingRequestAttributesOnResponse = getOutgoingRequestAttributesOnResponse;
@@ -351,7 +322,7 @@ const getIncomingRequestAttributes = (request, options) => {
351
322
  'localhost';
352
323
  const serverName = options.serverName;
353
324
  const attributes = {
354
- [semantic_conventions_1.SemanticAttributes.HTTP_URL]: exports.getAbsoluteUrl(requestUrl, headers, `${options.component}:`),
325
+ [semantic_conventions_1.SemanticAttributes.HTTP_URL]: (0, exports.getAbsoluteUrl)(requestUrl, headers, `${options.component}:`),
355
326
  [semantic_conventions_1.SemanticAttributes.HTTP_HOST]: host,
356
327
  [semantic_conventions_1.SemanticAttributes.NET_HOST_NAME]: hostname,
357
328
  [semantic_conventions_1.SemanticAttributes.HTTP_METHOD]: method,
@@ -368,8 +339,8 @@ const getIncomingRequestAttributes = (request, options) => {
368
339
  if (userAgent !== undefined) {
369
340
  attributes[semantic_conventions_1.SemanticAttributes.HTTP_USER_AGENT] = userAgent;
370
341
  }
371
- exports.setRequestContentLengthAttribute(request, attributes);
372
- const httpKindAttributes = exports.getAttributesFromHttpKind(httpVersion);
342
+ (0, exports.setRequestContentLengthAttribute)(request, attributes);
343
+ const httpKindAttributes = (0, exports.getAttributesFromHttpKind)(httpVersion);
373
344
  return Object.assign(attributes, httpKindAttributes, options.hookAttributes);
374
345
  };
375
346
  exports.getIncomingRequestAttributes = getIncomingRequestAttributes;
@@ -383,7 +354,7 @@ const getIncomingRequestAttributesOnResponse = (request, response) => {
383
354
  const { socket } = request;
384
355
  const { statusCode, statusMessage } = response;
385
356
  const { localAddress, localPort, remoteAddress, remotePort } = socket;
386
- const rpcMetadata = core_1.getRPCMetadata(api_1.context.active());
357
+ const rpcMetadata = (0, core_1.getRPCMetadata)(api_1.context.active());
387
358
  const attributes = {
388
359
  [semantic_conventions_1.SemanticAttributes.NET_HOST_IP]: localAddress,
389
360
  [semantic_conventions_1.SemanticAttributes.NET_HOST_PORT]: localPort,
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,4CAM4B;AAC5B,8EAG6C;AAS7C,8CAA8D;AAC9D,2BAA2B;AAC3B,2DAAwD;AAGxD;;GAEG;AACI,MAAM,cAAc,GAAG,CAC5B,UAAuC,EACvC,OAAkD,EAClD,gBAAgB,GAAG,OAAO,EAClB,EAAE;IACV,MAAM,YAAY,GAAG,UAAU,IAAI,EAAE,CAAC;IACtC,MAAM,QAAQ,GAAG,YAAY,CAAC,QAAQ,IAAI,gBAAgB,CAAC;IAC3D,MAAM,IAAI,GAAG,CAAC,YAAY,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC;IAClD,MAAM,IAAI,GAAG,YAAY,CAAC,IAAI,IAAI,GAAG,CAAC;IACtC,IAAI,IAAI,GACN,YAAY,CAAC,IAAI,IAAI,YAAY,CAAC,QAAQ,IAAI,OAAO,CAAC,IAAI,IAAI,WAAW,CAAC;IAE5E,kDAAkD;IAClD,gEAAgE;IAChE,IACG,IAAe,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACpC,IAAI;QACJ,IAAI,KAAK,IAAI;QACb,IAAI,KAAK,KAAK,EACd;QACA,IAAI,IAAI,IAAI,IAAI,EAAE,CAAC;KACpB;IAED,OAAO,GAAG,QAAQ,KAAK,IAAI,GAAG,IAAI,EAAE,CAAC;AACvC,CAAC,CAAC;AAxBW,QAAA,cAAc,kBAwBzB;AACF;;GAEG;AACI,MAAM,mBAAmB,GAAG,CACjC,UAA8B,EACD,EAAE;IAE/B,IAAG,UAAU,KAAK,SAAS,EAAE;QAC3B,OAAO,EAAE,IAAI,EAAE,oBAAc,CAAC,KAAK,EAAE,CAAC;KACvC;IAED,uBAAuB;IACvB,IAAI,UAAU,IAAI,GAAG,IAAI,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M,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAE1H,OAAO,CAAC,IAAU,EAAE,SAAkE,EAAE,EAAE;QACxF,KAAK,MAAM,CAAC,cAAc,EAAE,gBAAgB,CAAC,IAAI,iBAAiB,EAAE;YAClE,MAAM,KAAK,GAAG,SAAS,CAAC,cAAc,CAAC,CAAC;YAExC,IAAI,KAAK,KAAK,SAAS,EAAE;gBACvB,SAAS;aACV;YAED,MAAM,GAAG,GAAG,QAAQ,IAAI,WAAW,gBAAgB,EAAE,CAAC;YAEtD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;gBAC7B,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;aACjC;iBAAM,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;gBAC/B,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;aAC/B;iBAAM;gBACL,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;aACjC;SACF;IACH,CAAC,CAAC;AACJ,CAAC;AAtBD,sCAsBC","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 SpanAttributes,\n SpanStatusCode,\n Span,\n SpanStatus,\n context,\n} from '@opentelemetry/api';\nimport {\n NetTransportValues,\n SemanticAttributes,\n} from '@opentelemetry/semantic-conventions';\nimport {\n ClientRequest,\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 * 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 statusCode: number | undefined,\n): Omit<SpanStatus, 'message'> => {\n\n if(statusCode === undefined) {\n return { code: SpanStatusCode.ERROR };\n }\n\n // 1xx, 2xx, 3xx are OK\n if (statusCode >= 100 && statusCode < 400) {\n return { code: SpanStatusCode.OK };\n }\n\n // All other codes are error\n return { code: SpanStatusCode.ERROR };\n};\n\n/**\n * Returns whether the Expect header is on the given options object.\n * @param options Options for http.request.\n */\nexport const hasExpectHeader = (options: RequestOptions): boolean => {\n if (!options.headers) {\n return false;\n }\n\n const keys = Object.keys(options.headers);\n return !!keys.find(key => key.toLowerCase() === 'expect');\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: Error) => 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 * @param {(IncomingMessage | ClientRequest)} [obj] used for enriching the status by checking the statusCode.\n */\nexport const setSpanWithError = (\n span: Span,\n error: Err,\n obj?: IncomingMessage | ClientRequest\n): 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 if (!obj) {\n span.setStatus({ code: SpanStatusCode.ERROR, message });\n return;\n }\n\n let status: SpanStatus;\n if ((obj as IncomingMessage).statusCode) {\n status = parseResponseStatus((obj as IncomingMessage).statusCode);\n } else if ((obj as ClientRequest).aborted) {\n status = { code: SpanStatusCode.ERROR };\n } else {\n status = { code: SpanStatusCode.ERROR };\n }\n\n status.message = message;\n\n span.setStatus(status);\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[\n 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[\n 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): { origin: string; pathname: string; method: string; optionsParsed: RequestOptions; } => {\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 origin = `${optionsParsed.protocol || 'http:'}//${\n optionsParsed.host || `${optionsParsed.hostname}:${optionsParsed.port}`\n }`;\n }\n\n if (hasExpectHeader(optionsParsed)) {\n optionsParsed.headers = Object.assign({}, optionsParsed.headers);\n } else if (!optionsParsed.headers) {\n optionsParsed.headers = {};\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\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: { component: string; hostname: string; hookAttributes?: SpanAttributes }\n): SpanAttributes => {\n const host = requestOptions.host;\n const hostname =\n requestOptions.hostname ||\n host?.replace(/^(.*)(:[0-9]{1,5})/, '$1') ||\n 'localhost';\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 };\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 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 options: { hostname: string }\n): SpanAttributes => {\n const { statusCode, statusMessage, httpVersion, socket } = response;\n const { remoteAddress, remotePort } = socket;\n const attributes: SpanAttributes = {\n [SemanticAttributes.NET_PEER_IP]: remoteAddress,\n [SemanticAttributes.NET_PEER_PORT]: remotePort,\n [SemanticAttributes.HTTP_HOST]: `${options.hostname}:${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 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: { component: string; serverName?: string; hookAttributes?: SpanAttributes }\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 };\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.pathname || '/';\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 attributes scoped to the response data\n * @param {(ServerResponse & { socket: Socket; })} response the response object\n */\nexport const getIncomingRequestAttributesOnResponse = (\n request: IncomingMessage,\n response: ServerResponse\n): SpanAttributes => {\n // take socket from the request,\n // since it may be detached from the response object in keep-alive mode\n const { socket } = request;\n const { statusCode, statusMessage } = response;\n const { localAddress, localPort, remoteAddress, remotePort } = socket;\n const rpcMetadata = getRPCMetadata(context.active());\n\n const attributes: SpanAttributes = {\n [SemanticAttributes.NET_HOST_IP]: localAddress,\n [SemanticAttributes.NET_HOST_PORT]: localPort,\n [SemanticAttributes.NET_PEER_IP]: remoteAddress,\n [SemanticAttributes.NET_PEER_PORT]: remotePort,\n [SemanticAttributes.HTTP_STATUS_CODE]: statusCode,\n [AttributeNames.HTTP_STATUS_TEXT]: (statusMessage || '').toUpperCase(),\n };\n\n if (rpcMetadata?.type === RPCType.HTTP && rpcMetadata.route !== undefined) {\n attributes[SemanticAttributes.HTTP_ROUTE] = rpcMetadata.route;\n }\n return attributes;\n};\n\nexport function headerCapture(type: 'request' | 'response', headers: string[]) {\n const normalizedHeaders = new Map(headers.map(header => [header.toLowerCase(), header.toLowerCase().replace(/-/g, '_')]));\n\n return (span: Span, getHeader: (key: string) => undefined | string | string[] | number) => {\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,4CAM4B;AAC5B,8EAG6C;AAQ7C,8CAA8D;AAC9D,2BAA2B;AAC3B,2DAAwD;AAGxD;;GAEG;AACI,MAAM,cAAc,GAAG,CAC5B,UAAuC,EACvC,OAAkD,EAClD,gBAAgB,GAAG,OAAO,EAClB,EAAE;IACV,MAAM,YAAY,GAAG,UAAU,IAAI,EAAE,CAAC;IACtC,MAAM,QAAQ,GAAG,YAAY,CAAC,QAAQ,IAAI,gBAAgB,CAAC;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B,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,WAAW,EAAE,EAAE,MAAM,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAE1H,OAAO,CAAC,IAAU,EAAE,SAAkE,EAAE,EAAE;QACxF,KAAK,MAAM,CAAC,cAAc,EAAE,gBAAgB,CAAC,IAAI,iBAAiB,EAAE;YAClE,MAAM,KAAK,GAAG,SAAS,CAAC,cAAc,CAAC,CAAC;YAExC,IAAI,KAAK,KAAK,SAAS,EAAE;gBACvB,SAAS;aACV;YAED,MAAM,GAAG,GAAG,QAAQ,IAAI,WAAW,gBAAgB,EAAE,CAAC;YAEtD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;gBAC7B,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;aACjC;iBAAM,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;gBAC/B,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;aAC/B;iBAAM;gBACL,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;aACjC;SACF;IACH,CAAC,CAAC;AACJ,CAAC;AAtBD,sCAsBC","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 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 = (kind: SpanKind, statusCode?: number): 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 = (\n span: Span,\n error: Err\n): 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};\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[\n 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[\n 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): { origin: string; pathname: string; method: string; optionsParsed: RequestOptions; } => {\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 origin = `${optionsParsed.protocol || 'http:'}//${\n optionsParsed.host || `${optionsParsed.hostname}:${optionsParsed.port}`\n }`;\n }\n\n const headers = optionsParsed.headers ?? {};\n optionsParsed.headers = Object.keys(headers).reduce((normalizedHeader, key) => {\n normalizedHeader[key.toLowerCase()] = headers[key];\n return normalizedHeader;\n }, {} as OutgoingHttpHeaders);\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\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: { component: string; hostname: string; hookAttributes?: SpanAttributes }\n): SpanAttributes => {\n const host = requestOptions.host;\n const hostname =\n requestOptions.hostname ||\n host?.replace(/^(.*)(:[0-9]{1,5})/, '$1') ||\n 'localhost';\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 };\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 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 options: { hostname: string }\n): SpanAttributes => {\n const { statusCode, statusMessage, httpVersion, socket } = response;\n const { remoteAddress, remotePort } = socket;\n const attributes: SpanAttributes = {\n [SemanticAttributes.NET_PEER_IP]: remoteAddress,\n [SemanticAttributes.NET_PEER_PORT]: remotePort,\n [SemanticAttributes.HTTP_HOST]: `${options.hostname}:${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 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: { component: string; serverName?: string; hookAttributes?: SpanAttributes }\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 };\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.pathname || '/';\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 attributes scoped to the response data\n * @param {(ServerResponse & { socket: Socket; })} response the response object\n */\nexport const getIncomingRequestAttributesOnResponse = (\n request: IncomingMessage,\n response: ServerResponse\n): SpanAttributes => {\n // take socket from the request,\n // since it may be detached from the response object in keep-alive mode\n const { socket } = request;\n const { statusCode, statusMessage } = response;\n const { localAddress, localPort, remoteAddress, remotePort } = socket;\n const rpcMetadata = getRPCMetadata(context.active());\n\n const attributes: SpanAttributes = {\n [SemanticAttributes.NET_HOST_IP]: localAddress,\n [SemanticAttributes.NET_HOST_PORT]: localPort,\n [SemanticAttributes.NET_PEER_IP]: remoteAddress,\n [SemanticAttributes.NET_PEER_PORT]: remotePort,\n [SemanticAttributes.HTTP_STATUS_CODE]: statusCode,\n [AttributeNames.HTTP_STATUS_TEXT]: (statusMessage || '').toUpperCase(),\n };\n\n if (rpcMetadata?.type === RPCType.HTTP && rpcMetadata.route !== undefined) {\n attributes[SemanticAttributes.HTTP_ROUTE] = rpcMetadata.route;\n }\n return attributes;\n};\n\nexport function headerCapture(type: 'request' | 'response', headers: string[]) {\n const normalizedHeaders = new Map(headers.map(header => [header.toLowerCase(), header.toLowerCase().replace(/-/g, '_')]));\n\n return (span: Span, getHeader: (key: string) => undefined | string | string[] | number) => {\n for (const [capturedHeader, normalizedHeader] of normalizedHeaders) {\n const value = getHeader(capturedHeader);\n\n if (value === undefined) {\n continue;\n }\n\n const key = `http.${type}.header.${normalizedHeader}`;\n\n if (typeof value === 'string') {\n span.setAttribute(key, [value]);\n } else if (Array.isArray(value)) {\n span.setAttribute(key, value);\n } else {\n span.setAttribute(key, [value]);\n }\n }\n };\n}\n"]}
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.27.0";
1
+ export declare const VERSION = "0.28.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.27.0';
20
+ exports.VERSION = '0.28.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.27.0';\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4DAA4D;AAC/C,QAAA,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '0.28.0';\n"]}
package/package.json CHANGED
@@ -1,22 +1,24 @@
1
1
  {
2
2
  "name": "@opentelemetry/instrumentation-http",
3
- "version": "0.27.0",
3
+ "version": "0.28.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",
7
7
  "repository": "open-telemetry/opentelemetry-js",
8
8
  "scripts": {
9
+ "prepublishOnly": "npm run compile",
9
10
  "compile": "tsc --build",
10
11
  "clean": "tsc --build --clean",
11
12
  "test": "nyc ts-mocha -p tsconfig.json test/**/*.test.ts",
12
13
  "tdd": "npm run test -- --watch-extensions ts --watch",
13
14
  "lint": "eslint . --ext .ts",
14
15
  "lint:fix": "eslint . --ext .ts --fix",
15
- "codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../",
16
+ "codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../../",
16
17
  "version": "node ../../../scripts/version-update.js",
17
18
  "watch": "tsc --build --watch",
18
- "precompile": "lerna run version --scope $(npm pkg get name) --include-filtered-dependencies",
19
- "prewatch": "node ../../../scripts/version-update.js"
19
+ "precompile": "lerna run version --scope $(npm pkg get name) --include-dependencies",
20
+ "prewatch": "node ../../../scripts/version-update.js",
21
+ "peer-api-check": "node ../../../scripts/peer-api-check.js"
20
22
  },
21
23
  "keywords": [
22
24
  "opentelemetry",
@@ -29,7 +31,7 @@
29
31
  "author": "OpenTelemetry Authors",
30
32
  "license": "Apache-2.0",
31
33
  "engines": {
32
- "node": ">=8.0.0"
34
+ "node": ">=8.12.0"
33
35
  },
34
36
  "files": [
35
37
  "build/src/**/*.js",
@@ -43,22 +45,22 @@
43
45
  "access": "public"
44
46
  },
45
47
  "devDependencies": {
46
- "@opentelemetry/api": "^1.0.3",
47
- "@opentelemetry/context-async-hooks": "1.0.1",
48
- "@opentelemetry/sdk-trace-base": "1.0.1",
49
- "@opentelemetry/sdk-trace-node": "1.0.1",
48
+ "@opentelemetry/api": "^1.0.0",
49
+ "@opentelemetry/context-async-hooks": "1.2.0",
50
+ "@opentelemetry/sdk-trace-base": "1.2.0",
51
+ "@opentelemetry/sdk-trace-node": "1.2.0",
50
52
  "@types/got": "9.6.12",
51
53
  "@types/mocha": "8.2.3",
52
- "@types/node": "14.17.11",
54
+ "@types/node": "14.17.33",
53
55
  "@types/request-promise-native": "1.0.18",
54
- "@types/semver": "7.3.8",
55
- "@types/sinon": "10.0.2",
56
- "@types/superagent": "4.1.12",
57
- "axios": "0.21.1",
56
+ "@types/semver": "7.3.9",
57
+ "@types/sinon": "10.0.6",
58
+ "@types/superagent": "4.1.13",
59
+ "axios": "0.24.0",
58
60
  "codecov": "3.8.3",
59
61
  "got": "9.6.0",
60
62
  "mocha": "7.2.0",
61
- "nock": "12.0.3",
63
+ "nock": "13.0.11",
62
64
  "nyc": "15.1.0",
63
65
  "request": "2.88.2",
64
66
  "request-promise-native": "1.0.9",
@@ -66,16 +68,16 @@
66
68
  "sinon": "12.0.1",
67
69
  "superagent": "6.1.0",
68
70
  "ts-mocha": "8.0.0",
69
- "typescript": "4.3.5"
71
+ "typescript": "4.4.4"
70
72
  },
71
73
  "peerDependencies": {
72
74
  "@opentelemetry/api": "^1.0.0"
73
75
  },
74
76
  "dependencies": {
75
- "@opentelemetry/core": "1.0.1",
76
- "@opentelemetry/instrumentation": "0.27.0",
77
- "@opentelemetry/semantic-conventions": "1.0.1",
77
+ "@opentelemetry/core": "1.2.0",
78
+ "@opentelemetry/instrumentation": "0.28.0",
79
+ "@opentelemetry/semantic-conventions": "1.2.0",
78
80
  "semver": "^7.3.5"
79
81
  },
80
- "gitHead": "f5e227f0cb829df1ca2dc220a3e0e8ae0e607405"
82
+ "gitHead": "a0a670a03fd35b0799bee8cc466f79e93b5b6dd2"
81
83
  }