@opentelemetry/instrumentation-http 0.219.0 → 0.221.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 +13 -15
- package/build/src/http.d.ts +3 -7
- package/build/src/http.js +49 -80
- package/build/src/http.js.map +1 -1
- package/build/src/semconv.d.ts +0 -222
- package/build/src/semconv.js +1 -223
- package/build/src/semconv.js.map +1 -1
- package/build/src/types.d.ts +5 -1
- package/build/src/types.js.map +1 -1
- package/build/src/utils.d.ts +6 -49
- package/build/src/utils.js +74 -284
- package/build/src/utils.js.map +1 -1
- package/build/src/version.d.ts +1 -1
- package/build/src/version.js +1 -1
- package/build/src/version.js.map +1 -1
- package/package.json +15 -16
- package/build/src/enums/AttributeNames.d.ts +0 -9
- package/build/src/enums/AttributeNames.js +0 -17
- package/build/src/enums/AttributeNames.js.map +0 -1
package/README.md
CHANGED
|
@@ -7,9 +7,6 @@
|
|
|
7
7
|
|
|
8
8
|
This module provides automatic instrumentation for [`http`](https://nodejs.org/api/http.html) and [`https`](https://nodejs.org/api/https.html).
|
|
9
9
|
|
|
10
|
-
For automatic instrumentation see the
|
|
11
|
-
[@opentelemetry/sdk-trace-node](https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-sdk-trace-node) package.
|
|
12
|
-
|
|
13
10
|
## Installation
|
|
14
11
|
|
|
15
12
|
```bash
|
|
@@ -27,24 +24,23 @@ OpenTelemetry HTTP Instrumentation allows the user to automatically collect tele
|
|
|
27
24
|
To load a specific instrumentation (HTTP in this case), specify it in the Node Tracer's configuration.
|
|
28
25
|
|
|
29
26
|
```js
|
|
27
|
+
const { trace } = require('@opentelemetry/api');
|
|
30
28
|
const { HttpInstrumentation } = require('@opentelemetry/instrumentation-http');
|
|
31
|
-
const {
|
|
32
|
-
ConsoleSpanExporter,
|
|
33
|
-
NodeTracerProvider,
|
|
34
|
-
SimpleSpanProcessor,
|
|
35
|
-
} = require('@opentelemetry/sdk-trace-node');
|
|
29
|
+
const { ConsoleSpanExporter, TracerProvider, SimpleSpanProcessor } = require('@opentelemetry/sdk-trace');
|
|
36
30
|
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
|
|
37
31
|
|
|
38
|
-
const
|
|
39
|
-
spanProcessors: [
|
|
32
|
+
const tracerProvider = new TracerProvider({
|
|
33
|
+
spanProcessors: [
|
|
34
|
+
new SimpleSpanProcessor({ exporter: new ConsoleSpanExporter() })
|
|
35
|
+
]
|
|
40
36
|
});
|
|
41
|
-
|
|
42
|
-
|
|
37
|
+
trace.setGlobalTracerProvider(tracerProvider);
|
|
38
|
+
// See https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/sdk-trace/
|
|
39
|
+
// for a more complete example setting up a *context manager* and *propagators*.
|
|
43
40
|
|
|
44
41
|
registerInstrumentations({
|
|
45
42
|
instrumentations: [new HttpInstrumentation()],
|
|
46
43
|
});
|
|
47
|
-
|
|
48
44
|
```
|
|
49
45
|
|
|
50
46
|
See [examples/http](https://github.com/open-telemetry/opentelemetry-js/tree/main/examples/http) for a short example.
|
|
@@ -65,7 +61,7 @@ Options | Type
|
|
|
65
61
|
`ignoreOutgoingRequestHook` | `IgnoreOutgoingRequestFunction` | Function for filtering outgoing requests. HTTP instrumentation will not trace outgoing requests for which the function returns `true`.
|
|
66
62
|
`disableOutgoingRequestInstrumentation` | `boolean` | Set to true to avoid instrumenting outgoing requests at all. This can be helpful when another instrumentation handles outgoing requests.
|
|
67
63
|
`disableIncomingRequestInstrumentation` | `boolean` | Set to true to avoid instrumenting incoming requests at all. This can be helpful when another instrumentation handles incoming requests.
|
|
68
|
-
`serverName` | `string` |
|
|
64
|
+
`serverName` | `string` | **Deprecated.** No longer used. Stable HTTP semantic conventions do not include the `http.server_name` attribute; this option has no effect.
|
|
69
65
|
`requireParentforOutgoingSpans` | Boolean | Require that is a parent span to create new span for outgoing requests.
|
|
70
66
|
`requireParentforIncomingSpans` | Boolean | Require that is a parent span to create new span for incoming requests.
|
|
71
67
|
`headersToSpanAttributes` | `object` | Specify which HTTP headers should be captured as span attributes. This is an object of the form `{client: {requestHeaders: [...], responseHeaders: [...]}, server: {requestHeaders: [...], responseHeaders: [...]}}`, where each `[...]` is an array of HTTP header names (case-insensitive) to capture. 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`. By default hyphens in header names are converted to underscore. However, if stable semantic conventions are selected (see next section), then, hyphens in header names are not changed, e.g. `http.response.header.content-length`.
|
|
@@ -87,7 +83,7 @@ Hook type | Parameters
|
|
|
87
83
|
Prior to version `0.54.0`, this instrumentation created spans targeting an experimental semantic convention [Version 1.7.0](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.7.0/semantic_conventions/README.md).
|
|
88
84
|
|
|
89
85
|
HTTP semantic conventions (semconv) were stabilized in v1.23.0, and a [migration process](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/non-normative/http-migration.md#http-semantic-convention-stability-migration) was defined.
|
|
90
|
-
`instrumentation-http` versions 0.54.0
|
|
86
|
+
`instrumentation-http` versions 0.54.0 - XXXX include support for migrating to stable HTTP semantic conventions, as described below.
|
|
91
87
|
The intent is to provide an approximate 6 month time window for users of this instrumentation to migrate to the new HTTP semconv, after which a new minor version will use the *new* semconv by default and drop support for the old semconv.
|
|
92
88
|
See the [HTTP semconv migration plan for OpenTelemetry JS instrumentations](https://github.com/open-telemetry/opentelemetry-js/issues/5646).
|
|
93
89
|
|
|
@@ -97,6 +93,8 @@ To select which semconv version(s) is emitted from this instrumentation, use the
|
|
|
97
93
|
- `http/dup`: emit **both** the old v1.7.0 and the new (stable) v1.23.0+ semantics
|
|
98
94
|
- By default, if `OTEL_SEMCONV_STABILITY_OPT_IN` includes neither of the above tokens, the old v1.7.0 semconv is used.
|
|
99
95
|
|
|
96
|
+
`instrumentation-http` versions XXX and later emit the stable v1.23.0+ semantics only.
|
|
97
|
+
|
|
100
98
|
### Attributes collected
|
|
101
99
|
|
|
102
100
|
v1.7.0 semconv | v1.23.0 semconv | Short Description
|
package/build/src/http.d.ts
CHANGED
|
@@ -9,11 +9,8 @@ export declare class HttpInstrumentation extends InstrumentationBase<HttpInstrum
|
|
|
9
9
|
private _headerCapture;
|
|
10
10
|
private _httpPatched;
|
|
11
11
|
private _httpsPatched;
|
|
12
|
-
private
|
|
13
|
-
private
|
|
14
|
-
private _oldHttpClientDurationHistogram;
|
|
15
|
-
private _stableHttpClientDurationHistogram;
|
|
16
|
-
private _semconvStability;
|
|
12
|
+
private _httpServerDurationHistogram;
|
|
13
|
+
private _httpClientDurationHistogram;
|
|
17
14
|
constructor(config?: HttpInstrumentationConfig);
|
|
18
15
|
protected _updateMetricInstruments(): void;
|
|
19
16
|
private _recordServerDuration;
|
|
@@ -46,8 +43,7 @@ export declare class HttpInstrumentation extends InstrumentationBase<HttpInstrum
|
|
|
46
43
|
* @param request The original request object.
|
|
47
44
|
* @param span representing the current operation
|
|
48
45
|
* @param startTime representing the start time of the request to calculate duration in Metric
|
|
49
|
-
* @param
|
|
50
|
-
* @param stableMetricAttributes metric attributes for new semantic conventions
|
|
46
|
+
* @param metricAttributes metric attributes for the request duration metric
|
|
51
47
|
*/
|
|
52
48
|
private _traceClientRequest;
|
|
53
49
|
private _incomingRequestFunction;
|
package/build/src/http.js
CHANGED
|
@@ -22,24 +22,12 @@ class HttpInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
|
22
22
|
_headerCapture;
|
|
23
23
|
_httpPatched = false;
|
|
24
24
|
_httpsPatched = false;
|
|
25
|
-
_semconvStability = instrumentation_1.SemconvStability.OLD;
|
|
26
25
|
constructor(config = {}) {
|
|
27
26
|
super('@opentelemetry/instrumentation-http', version_1.VERSION, config);
|
|
28
|
-
this.
|
|
29
|
-
this._headerCapture = this._createHeaderCapture(this._semconvStability);
|
|
27
|
+
this._headerCapture = this._createHeaderCapture();
|
|
30
28
|
}
|
|
31
29
|
_updateMetricInstruments() {
|
|
32
|
-
this.
|
|
33
|
-
description: 'Measures the duration of inbound HTTP requests.',
|
|
34
|
-
unit: 'ms',
|
|
35
|
-
valueType: api_1.ValueType.DOUBLE,
|
|
36
|
-
});
|
|
37
|
-
this._oldHttpClientDurationHistogram = this.meter.createHistogram('http.client.duration', {
|
|
38
|
-
description: 'Measures the duration of outbound HTTP requests.',
|
|
39
|
-
unit: 'ms',
|
|
40
|
-
valueType: api_1.ValueType.DOUBLE,
|
|
41
|
-
});
|
|
42
|
-
this._stableHttpServerDurationHistogram = this.meter.createHistogram(semantic_conventions_1.METRIC_HTTP_SERVER_REQUEST_DURATION, {
|
|
30
|
+
this._httpServerDurationHistogram = this.meter.createHistogram(semantic_conventions_1.METRIC_HTTP_SERVER_REQUEST_DURATION, {
|
|
43
31
|
description: 'Duration of HTTP server requests.',
|
|
44
32
|
unit: 's',
|
|
45
33
|
valueType: api_1.ValueType.DOUBLE,
|
|
@@ -50,7 +38,7 @@ class HttpInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
|
50
38
|
],
|
|
51
39
|
},
|
|
52
40
|
});
|
|
53
|
-
this.
|
|
41
|
+
this._httpClientDurationHistogram = this.meter.createHistogram(semantic_conventions_1.METRIC_HTTP_CLIENT_REQUEST_DURATION, {
|
|
54
42
|
description: 'Duration of HTTP client requests.',
|
|
55
43
|
unit: 's',
|
|
56
44
|
valueType: api_1.ValueType.DOUBLE,
|
|
@@ -62,29 +50,17 @@ class HttpInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
|
62
50
|
},
|
|
63
51
|
});
|
|
64
52
|
}
|
|
65
|
-
_recordServerDuration(durationMs,
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
this._oldHttpServerDurationHistogram.record(durationMs, oldAttributes);
|
|
69
|
-
}
|
|
70
|
-
if (this._semconvStability & instrumentation_1.SemconvStability.STABLE) {
|
|
71
|
-
// stable histogram is counted in S
|
|
72
|
-
this._stableHttpServerDurationHistogram.record(durationMs / 1000, stableAttributes);
|
|
73
|
-
}
|
|
53
|
+
_recordServerDuration(durationMs, attributes) {
|
|
54
|
+
// stable histogram is counted in S
|
|
55
|
+
this._httpServerDurationHistogram.record(durationMs / 1000, attributes);
|
|
74
56
|
}
|
|
75
|
-
_recordClientDuration(durationMs,
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
this._oldHttpClientDurationHistogram.record(durationMs, oldAttributes);
|
|
79
|
-
}
|
|
80
|
-
if (this._semconvStability & instrumentation_1.SemconvStability.STABLE) {
|
|
81
|
-
// stable histogram is counted in S
|
|
82
|
-
this._stableHttpClientDurationHistogram.record(durationMs / 1000, stableAttributes);
|
|
83
|
-
}
|
|
57
|
+
_recordClientDuration(durationMs, attributes) {
|
|
58
|
+
// stable histogram is counted in S
|
|
59
|
+
this._httpClientDurationHistogram.record(durationMs / 1000, attributes);
|
|
84
60
|
}
|
|
85
61
|
setConfig(config = {}) {
|
|
86
62
|
super.setConfig(config);
|
|
87
|
-
this._headerCapture = this._createHeaderCapture(
|
|
63
|
+
this._headerCapture = this._createHeaderCapture();
|
|
88
64
|
}
|
|
89
65
|
init() {
|
|
90
66
|
return [this._getHttpsInstrumentation(), this._getHttpInstrumentation()];
|
|
@@ -238,10 +214,9 @@ class HttpInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
|
238
214
|
* @param request The original request object.
|
|
239
215
|
* @param span representing the current operation
|
|
240
216
|
* @param startTime representing the start time of the request to calculate duration in Metric
|
|
241
|
-
* @param
|
|
242
|
-
* @param stableMetricAttributes metric attributes for new semantic conventions
|
|
217
|
+
* @param metricAttributes metric attributes for the request duration metric
|
|
243
218
|
*/
|
|
244
|
-
_traceClientRequest(request, span, startTime,
|
|
219
|
+
_traceClientRequest(request, span, startTime, metricAttributes) {
|
|
245
220
|
if (this.getConfig().requestHook) {
|
|
246
221
|
this._callRequestHook(span, request);
|
|
247
222
|
}
|
|
@@ -259,10 +234,9 @@ class HttpInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
|
259
234
|
if (request.listenerCount('response') <= 1) {
|
|
260
235
|
response.resume();
|
|
261
236
|
}
|
|
262
|
-
const responseAttributes = (0, utils_1.getOutgoingRequestAttributesOnResponse)(response
|
|
237
|
+
const responseAttributes = (0, utils_1.getOutgoingRequestAttributesOnResponse)(response);
|
|
263
238
|
span.setAttributes(responseAttributes);
|
|
264
|
-
|
|
265
|
-
stableMetricAttributes = Object.assign(stableMetricAttributes, (0, utils_1.getOutgoingStableRequestMetricAttributesOnResponse)(responseAttributes));
|
|
239
|
+
metricAttributes = Object.assign(metricAttributes, (0, utils_1.getOutgoingStableRequestMetricAttributesOnResponse)(responseAttributes));
|
|
266
240
|
if (this.getConfig().responseHook) {
|
|
267
241
|
this._callResponseHook(span, response);
|
|
268
242
|
}
|
|
@@ -289,7 +263,7 @@ class HttpInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
|
289
263
|
if (this.getConfig().applyCustomAttributesOnSpan) {
|
|
290
264
|
(0, instrumentation_1.safeExecuteInTheMiddle)(() => this.getConfig().applyCustomAttributesOnSpan(span, request, response), () => { }, true);
|
|
291
265
|
}
|
|
292
|
-
this._closeHttpSpan(span, api_1.SpanKind.CLIENT, startTime,
|
|
266
|
+
this._closeHttpSpan(span, api_1.SpanKind.CLIENT, startTime, metricAttributes);
|
|
293
267
|
};
|
|
294
268
|
response.on('end', endHandler);
|
|
295
269
|
response.on(events_1.errorMonitor, (error) => {
|
|
@@ -298,7 +272,7 @@ class HttpInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
|
298
272
|
return;
|
|
299
273
|
}
|
|
300
274
|
responseFinished = true;
|
|
301
|
-
this._onOutgoingRequestError(span,
|
|
275
|
+
this._onOutgoingRequestError(span, metricAttributes, startTime, error);
|
|
302
276
|
});
|
|
303
277
|
});
|
|
304
278
|
request.on('close', () => {
|
|
@@ -307,7 +281,7 @@ class HttpInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
|
307
281
|
return;
|
|
308
282
|
}
|
|
309
283
|
responseFinished = true;
|
|
310
|
-
this._closeHttpSpan(span, api_1.SpanKind.CLIENT, startTime,
|
|
284
|
+
this._closeHttpSpan(span, api_1.SpanKind.CLIENT, startTime, metricAttributes);
|
|
311
285
|
});
|
|
312
286
|
request.on(events_1.errorMonitor, (error) => {
|
|
313
287
|
this._diag.debug('outgoingRequest on request error()', error);
|
|
@@ -315,7 +289,7 @@ class HttpInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
|
315
289
|
return;
|
|
316
290
|
}
|
|
317
291
|
responseFinished = true;
|
|
318
|
-
this._onOutgoingRequestError(span,
|
|
292
|
+
this._onOutgoingRequestError(span, metricAttributes, startTime, error);
|
|
319
293
|
});
|
|
320
294
|
this._diag.debug('http.ClientRequest return request');
|
|
321
295
|
return request;
|
|
@@ -345,9 +319,7 @@ class HttpInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
|
345
319
|
const headers = request.headers;
|
|
346
320
|
const spanAttributes = (0, utils_1.getIncomingRequestAttributes)(request, {
|
|
347
321
|
component: component,
|
|
348
|
-
serverName: instrumentation.getConfig().serverName,
|
|
349
322
|
hookAttributes: instrumentation._callStartSpanHook(request, instrumentation.getConfig().startIncomingSpanHook),
|
|
350
|
-
semconvStability: instrumentation._semconvStability,
|
|
351
323
|
enableSyntheticSourceDetection: instrumentation.getConfig().enableSyntheticSourceDetection || false,
|
|
352
324
|
}, instrumentation._diag);
|
|
353
325
|
Object.assign(spanAttributes, instrumentation._headerCapture.server.captureRequestHeaders(header => request.headers[header]));
|
|
@@ -356,15 +328,14 @@ class HttpInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
|
356
328
|
attributes: spanAttributes,
|
|
357
329
|
};
|
|
358
330
|
const startTime = (0, core_1.hrTime)();
|
|
359
|
-
const oldMetricAttributes = (0, utils_1.getIncomingRequestMetricAttributes)(spanAttributes);
|
|
360
331
|
// request method and url.scheme are both required span attributes
|
|
361
|
-
const
|
|
332
|
+
const metricAttributes = {
|
|
362
333
|
[semantic_conventions_1.ATTR_HTTP_REQUEST_METHOD]: spanAttributes[semantic_conventions_1.ATTR_HTTP_REQUEST_METHOD],
|
|
363
334
|
[semantic_conventions_1.ATTR_URL_SCHEME]: spanAttributes[semantic_conventions_1.ATTR_URL_SCHEME],
|
|
364
335
|
};
|
|
365
336
|
// recommended if and only if one was sent, same as span recommendation
|
|
366
337
|
if (spanAttributes[semantic_conventions_1.ATTR_NETWORK_PROTOCOL_VERSION]) {
|
|
367
|
-
|
|
338
|
+
metricAttributes[semantic_conventions_1.ATTR_NETWORK_PROTOCOL_VERSION] =
|
|
368
339
|
spanAttributes[semantic_conventions_1.ATTR_NETWORK_PROTOCOL_VERSION];
|
|
369
340
|
}
|
|
370
341
|
const ctx = api_1.propagation.extract(api_1.ROOT_CONTEXT, headers);
|
|
@@ -388,15 +359,15 @@ class HttpInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
|
388
359
|
if (hasError) {
|
|
389
360
|
return;
|
|
390
361
|
}
|
|
391
|
-
instrumentation._onServerResponseFinish(request, response, span,
|
|
362
|
+
instrumentation._onServerResponseFinish(request, response, span, metricAttributes, startTime);
|
|
392
363
|
});
|
|
393
364
|
response.on(events_1.errorMonitor, (err) => {
|
|
394
365
|
hasError = true;
|
|
395
|
-
instrumentation._onServerResponseError(span,
|
|
366
|
+
instrumentation._onServerResponseError(span, metricAttributes, startTime, err);
|
|
396
367
|
});
|
|
397
368
|
return (0, instrumentation_1.safeExecuteInTheMiddle)(() => original.apply(this, [event, ...args]), error => {
|
|
398
369
|
if (error) {
|
|
399
|
-
instrumentation._onServerResponseError(span,
|
|
370
|
+
instrumentation._onServerResponseError(span, metricAttributes, startTime, error);
|
|
400
371
|
throw error;
|
|
401
372
|
}
|
|
402
373
|
});
|
|
@@ -430,23 +401,22 @@ class HttpInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
|
430
401
|
hostname,
|
|
431
402
|
hookAttributes: instrumentation._callStartSpanHook(optionsParsed, instrumentation.getConfig().startOutgoingSpanHook),
|
|
432
403
|
redactedQueryParams: instrumentation.getConfig().redactedQueryParams, // Added config for adding custom query strings
|
|
433
|
-
}, instrumentation.
|
|
404
|
+
}, instrumentation.getConfig().enableSyntheticSourceDetection || false);
|
|
434
405
|
const startTime = (0, core_1.hrTime)();
|
|
435
|
-
const oldMetricAttributes = (0, utils_1.getOutgoingRequestMetricAttributes)(attributes);
|
|
436
406
|
// request method, server address, and server port are both required span attributes
|
|
437
|
-
const
|
|
407
|
+
const metricAttributes = {
|
|
438
408
|
[semantic_conventions_1.ATTR_HTTP_REQUEST_METHOD]: attributes[semantic_conventions_1.ATTR_HTTP_REQUEST_METHOD],
|
|
439
409
|
[semantic_conventions_1.ATTR_SERVER_ADDRESS]: attributes[semantic_conventions_1.ATTR_SERVER_ADDRESS],
|
|
440
410
|
[semantic_conventions_1.ATTR_SERVER_PORT]: attributes[semantic_conventions_1.ATTR_SERVER_PORT],
|
|
441
411
|
};
|
|
442
412
|
// required if and only if one was sent, same as span requirement
|
|
443
413
|
if (attributes[semantic_conventions_1.ATTR_HTTP_RESPONSE_STATUS_CODE]) {
|
|
444
|
-
|
|
414
|
+
metricAttributes[semantic_conventions_1.ATTR_HTTP_RESPONSE_STATUS_CODE] =
|
|
445
415
|
attributes[semantic_conventions_1.ATTR_HTTP_RESPONSE_STATUS_CODE];
|
|
446
416
|
}
|
|
447
417
|
// recommended if and only if one was sent, same as span recommendation
|
|
448
418
|
if (attributes[semantic_conventions_1.ATTR_NETWORK_PROTOCOL_VERSION]) {
|
|
449
|
-
|
|
419
|
+
metricAttributes[semantic_conventions_1.ATTR_NETWORK_PROTOCOL_VERSION] =
|
|
450
420
|
attributes[semantic_conventions_1.ATTR_NETWORK_PROTOCOL_VERSION];
|
|
451
421
|
}
|
|
452
422
|
const spanOptions = {
|
|
@@ -486,20 +456,19 @@ class HttpInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
|
486
456
|
}
|
|
487
457
|
}, error => {
|
|
488
458
|
if (error) {
|
|
489
|
-
instrumentation._onOutgoingRequestError(span,
|
|
459
|
+
instrumentation._onOutgoingRequestError(span, metricAttributes, startTime, error);
|
|
490
460
|
throw error;
|
|
491
461
|
}
|
|
492
462
|
});
|
|
493
463
|
instrumentation._diag.debug(`${component} instrumentation outgoingRequest`);
|
|
494
464
|
api_1.context.bind(parentContext, request);
|
|
495
|
-
return instrumentation._traceClientRequest(request, span, startTime,
|
|
465
|
+
return instrumentation._traceClientRequest(request, span, startTime, metricAttributes);
|
|
496
466
|
});
|
|
497
467
|
};
|
|
498
468
|
}
|
|
499
|
-
_onServerResponseFinish(request, response, span,
|
|
500
|
-
const attributes = (0, utils_1.getIncomingRequestAttributesOnResponse)(
|
|
501
|
-
|
|
502
|
-
stableMetricAttributes = Object.assign(stableMetricAttributes, (0, utils_1.getIncomingStableRequestMetricAttributesOnResponse)(attributes));
|
|
469
|
+
_onServerResponseFinish(request, response, span, metricAttributes, startTime) {
|
|
470
|
+
const attributes = (0, utils_1.getIncomingRequestAttributesOnResponse)(response);
|
|
471
|
+
metricAttributes = Object.assign(metricAttributes, (0, utils_1.getIncomingStableRequestMetricAttributesOnResponse)(attributes));
|
|
503
472
|
span.setAttributes(this._headerCapture.server.captureResponseHeaders(header => response.getHeader(header)));
|
|
504
473
|
span.setAttributes(attributes).setStatus({
|
|
505
474
|
code: (0, utils_1.parseResponseStatus)(api_1.SpanKind.SERVER, response.statusCode),
|
|
@@ -511,17 +480,17 @@ class HttpInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
|
511
480
|
if (this.getConfig().applyCustomAttributesOnSpan) {
|
|
512
481
|
(0, instrumentation_1.safeExecuteInTheMiddle)(() => this.getConfig().applyCustomAttributesOnSpan(span, request, response), () => { }, true);
|
|
513
482
|
}
|
|
514
|
-
this._closeHttpSpan(span, api_1.SpanKind.SERVER, startTime,
|
|
483
|
+
this._closeHttpSpan(span, api_1.SpanKind.SERVER, startTime, metricAttributes);
|
|
515
484
|
}
|
|
516
|
-
_onOutgoingRequestError(span,
|
|
517
|
-
(0, utils_1.setSpanWithError)(span, error
|
|
518
|
-
|
|
519
|
-
this._closeHttpSpan(span, api_1.SpanKind.CLIENT, startTime,
|
|
485
|
+
_onOutgoingRequestError(span, metricAttributes, startTime, error) {
|
|
486
|
+
(0, utils_1.setSpanWithError)(span, error);
|
|
487
|
+
metricAttributes[semantic_conventions_1.ATTR_ERROR_TYPE] = error.name;
|
|
488
|
+
this._closeHttpSpan(span, api_1.SpanKind.CLIENT, startTime, metricAttributes);
|
|
520
489
|
}
|
|
521
|
-
_onServerResponseError(span,
|
|
522
|
-
(0, utils_1.setSpanWithError)(span, error
|
|
523
|
-
|
|
524
|
-
this._closeHttpSpan(span, api_1.SpanKind.SERVER, startTime,
|
|
490
|
+
_onServerResponseError(span, metricAttributes, startTime, error) {
|
|
491
|
+
(0, utils_1.setSpanWithError)(span, error);
|
|
492
|
+
metricAttributes[semantic_conventions_1.ATTR_ERROR_TYPE] = error.name;
|
|
493
|
+
this._closeHttpSpan(span, api_1.SpanKind.SERVER, startTime, metricAttributes);
|
|
525
494
|
}
|
|
526
495
|
_startHttpSpan(name, options, ctx = api_1.context.active()) {
|
|
527
496
|
/*
|
|
@@ -546,7 +515,7 @@ class HttpInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
|
546
515
|
this._spanNotEnded.add(span);
|
|
547
516
|
return span;
|
|
548
517
|
}
|
|
549
|
-
_closeHttpSpan(span, spanKind, startTime,
|
|
518
|
+
_closeHttpSpan(span, spanKind, startTime, metricAttributes) {
|
|
550
519
|
if (!this._spanNotEnded.has(span)) {
|
|
551
520
|
return;
|
|
552
521
|
}
|
|
@@ -555,10 +524,10 @@ class HttpInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
|
555
524
|
// Record metrics
|
|
556
525
|
const duration = (0, core_1.hrTimeToMilliseconds)((0, core_1.hrTimeDuration)(startTime, (0, core_1.hrTime)()));
|
|
557
526
|
if (spanKind === api_1.SpanKind.SERVER) {
|
|
558
|
-
this._recordServerDuration(duration,
|
|
527
|
+
this._recordServerDuration(duration, metricAttributes);
|
|
559
528
|
}
|
|
560
529
|
else if (spanKind === api_1.SpanKind.CLIENT) {
|
|
561
|
-
this._recordClientDuration(duration,
|
|
530
|
+
this._recordClientDuration(duration, metricAttributes);
|
|
562
531
|
}
|
|
563
532
|
}
|
|
564
533
|
_callResponseHook(span, response) {
|
|
@@ -572,16 +541,16 @@ class HttpInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
|
572
541
|
return (0, instrumentation_1.safeExecuteInTheMiddle)(() => hookFunc(request), () => { }, true);
|
|
573
542
|
}
|
|
574
543
|
}
|
|
575
|
-
_createHeaderCapture(
|
|
544
|
+
_createHeaderCapture() {
|
|
576
545
|
const config = this.getConfig();
|
|
577
546
|
return {
|
|
578
547
|
client: {
|
|
579
|
-
captureRequestHeaders: (0, utils_1.headerCapture)('request', config.headersToSpanAttributes?.client?.requestHeaders ?? []
|
|
580
|
-
captureResponseHeaders: (0, utils_1.headerCapture)('response', config.headersToSpanAttributes?.client?.responseHeaders ?? []
|
|
548
|
+
captureRequestHeaders: (0, utils_1.headerCapture)('request', config.headersToSpanAttributes?.client?.requestHeaders ?? []),
|
|
549
|
+
captureResponseHeaders: (0, utils_1.headerCapture)('response', config.headersToSpanAttributes?.client?.responseHeaders ?? []),
|
|
581
550
|
},
|
|
582
551
|
server: {
|
|
583
|
-
captureRequestHeaders: (0, utils_1.headerCapture)('request', config.headersToSpanAttributes?.server?.requestHeaders ?? []
|
|
584
|
-
captureResponseHeaders: (0, utils_1.headerCapture)('response', config.headersToSpanAttributes?.server?.responseHeaders ?? []
|
|
552
|
+
captureRequestHeaders: (0, utils_1.headerCapture)('request', config.headersToSpanAttributes?.server?.requestHeaders ?? []),
|
|
553
|
+
captureResponseHeaders: (0, utils_1.headerCapture)('response', config.headersToSpanAttributes?.server?.responseHeaders ?? []),
|
|
585
554
|
},
|
|
586
555
|
};
|
|
587
556
|
}
|