@opentelemetry/instrumentation-http 0.220.0 → 0.222.0-development.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 +72 -52
- package/build/src/http.d.ts +3 -7
- package/build/src/http.js +52 -80
- package/build/src/http.js.map +1 -1
- package/build/src/internal-types.d.ts +1 -1
- package/build/src/internal-types.js +3 -0
- package/build/src/internal-types.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 +17 -3
- package/build/src/types.js.map +1 -1
- package/build/src/utils.d.ts +12 -49
- package/build/src/utils.js +92 -292
- 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 +10 -10
- 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
|
@@ -61,11 +61,53 @@ Options | Type
|
|
|
61
61
|
`ignoreOutgoingRequestHook` | `IgnoreOutgoingRequestFunction` | Function for filtering outgoing requests. HTTP instrumentation will not trace outgoing requests for which the function returns `true`.
|
|
62
62
|
`disableOutgoingRequestInstrumentation` | `boolean` | Set to true to avoid instrumenting outgoing requests at all. This can be helpful when another instrumentation handles outgoing requests.
|
|
63
63
|
`disableIncomingRequestInstrumentation` | `boolean` | Set to true to avoid instrumenting incoming requests at all. This can be helpful when another instrumentation handles incoming requests.
|
|
64
|
-
`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.
|
|
65
65
|
`requireParentforOutgoingSpans` | Boolean | Require that is a parent span to create new span for outgoing requests.
|
|
66
66
|
`requireParentforIncomingSpans` | Boolean | Require that is a parent span to create new span for incoming requests.
|
|
67
|
+
`redactedQueryParams` | `string[]` | **Experimental.** Query parameter names whose values are redacted on outgoing (client) spans. Replaces the built-in list. See [Query parameter redaction](#query-parameter-redaction).
|
|
68
|
+
`redactedQueryParamsServer` | `string[]` | **Experimental.** Query parameter names whose values are redacted on incoming (server) spans. Replaces the built-in list. See [Query parameter redaction](#query-parameter-redaction).
|
|
67
69
|
`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`.
|
|
68
70
|
|
|
71
|
+
#### Query parameter redaction
|
|
72
|
+
|
|
73
|
+
Query parameters that commonly carry credentials are redacted before URLs are recorded as span attributes. On client spans the redacted URL is recorded as `url.full`; on server spans the redacted query string is recorded as `url.query`. Matching values are replaced with the literal string `REDACTED`.
|
|
74
|
+
|
|
75
|
+
By default both sides redact the following parameters:
|
|
76
|
+
|
|
77
|
+
```text
|
|
78
|
+
sig, Signature, AWSAccessKeyId, X-Goog-Signature,
|
|
79
|
+
X-Amz-Signature, X-Amz-Credential, X-Amz-Security-Token
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
`redactedQueryParams` controls the client side and `redactedQueryParamsServer` controls the server side, independently. For each option:
|
|
83
|
+
|
|
84
|
+
- Omit it to use the built-in list above.
|
|
85
|
+
- Supply an array to **replace** the built-in list entirely. The arrays are not merged, so include any built-in parameters you still want redacted.
|
|
86
|
+
- Supply an empty array to disable redaction on that side.
|
|
87
|
+
|
|
88
|
+
The two options do not fall back to each other: when `redactedQueryParamsServer` is omitted, server spans use the built-in list, *not* the value of `redactedQueryParams`. Setting `redactedQueryParams` alone therefore leaves custom parameters unredacted on server spans. To redact the same custom parameters on both sides, set both options to the same array.
|
|
89
|
+
|
|
90
|
+
Parameter names are matched exactly and are case-sensitive, which is why the built-in list contains both `sig` and `Signature`.
|
|
91
|
+
|
|
92
|
+
```js
|
|
93
|
+
// The built-in list plus an application-specific parameter, applied to both sides.
|
|
94
|
+
const redacted = [
|
|
95
|
+
'sig',
|
|
96
|
+
'Signature',
|
|
97
|
+
'AWSAccessKeyId',
|
|
98
|
+
'X-Goog-Signature',
|
|
99
|
+
'X-Amz-Signature',
|
|
100
|
+
'X-Amz-Credential',
|
|
101
|
+
'X-Amz-Security-Token',
|
|
102
|
+
'api_key',
|
|
103
|
+
];
|
|
104
|
+
|
|
105
|
+
new HttpInstrumentation({
|
|
106
|
+
redactedQueryParams: redacted,
|
|
107
|
+
redactedQueryParamsServer: redacted,
|
|
108
|
+
});
|
|
109
|
+
```
|
|
110
|
+
|
|
69
111
|
#### Hook function signatures
|
|
70
112
|
|
|
71
113
|
Hook type | Parameters | Return value
|
|
@@ -80,61 +122,39 @@ Hook type | Parameters
|
|
|
80
122
|
|
|
81
123
|
## Semantic Conventions
|
|
82
124
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
The
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
- `
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
`
|
|
101
|
-
`
|
|
102
|
-
`
|
|
103
|
-
`
|
|
104
|
-
`
|
|
105
|
-
`
|
|
106
|
-
`
|
|
107
|
-
`
|
|
108
|
-
`
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
`http.status_code` | `http.response.status_code` | HTTP response status code
|
|
112
|
-
`http.target` | `url.path` and `url.query` | The URI path and query component
|
|
113
|
-
`http.url` | `url.full` | Full HTTP request URL in the form `scheme://host[:port]/path?query[#fragment]`
|
|
114
|
-
`http.user_agent` | `user_agent.original` | Value of the HTTP User-Agent header sent by the client
|
|
115
|
-
`net.host.ip` | `network.local.address` | Like net.peer.ip but for the host IP. Useful in case of a multi-IP host
|
|
116
|
-
`net.host.name` | `server.address` | Local hostname or similar
|
|
117
|
-
`net.host.port` | `server.port` | Like net.peer.port but for the host port
|
|
118
|
-
`net.peer.ip` | `network.peer.address` | Remote address of the peer (dotted decimal for IPv4 or RFC5952 for IPv6)
|
|
119
|
-
`net.peer.name` | `server.address` | Server domain name if available without reverse DNS lookup
|
|
120
|
-
`net.peer.port` | `server.port` | Server port number
|
|
121
|
-
`net.transport` | `network.transport` | Transport protocol used
|
|
122
|
-
|
|
123
|
-
Metrics Exported:
|
|
125
|
+
**Span attributes:**
|
|
126
|
+
|
|
127
|
+
v1.23.0 semconv | Short Description
|
|
128
|
+
----------------------------------- | -----
|
|
129
|
+
`client.address` | The IP address of the original client behind all proxies, if known
|
|
130
|
+
`network.protocol.version` | Kind of HTTP protocol used
|
|
131
|
+
`server.address` | The value of the HTTP host header
|
|
132
|
+
`http.request.method` | HTTP request method
|
|
133
|
+
(opt-in, `headersToSpanAttributes`) | The size of the request payload body in bytes. For newer semconv, use the `headersToSpanAttributes` option to capture this as `http.request.header.content-length`.
|
|
134
|
+
(not included) | The size of the uncompressed request payload body after transport decoding. (In semconv v1.23.0 this is defined by `http.request.body.size`, which is experimental and opt-in.)
|
|
135
|
+
(opt-in, `headersToSpanAttributes`) | The size of the response payload body in bytes. For newer semconv, use the `headersToSpanAttributes` option to capture this as `http.response.header.content-length`.
|
|
136
|
+
(not included) | The size of the uncompressed response payload body after transport decoding. (In semconv v1.23.0 this is defined by `http.response.body.size`, which is experimental and opt-in.)
|
|
137
|
+
no change | The matched route (path template).
|
|
138
|
+
`url.scheme` | The URI scheme identifying the used protocol
|
|
139
|
+
`server.address` | The primary server name of the matched virtual host
|
|
140
|
+
`http.response.status_code` | HTTP response status code
|
|
141
|
+
`url.path` and `url.query` | The URI path and query component
|
|
142
|
+
`url.full` | Full HTTP request URL in the form `scheme://host[:port]/path?query[#fragment]`
|
|
143
|
+
`user_agent.original` | Value of the HTTP User-Agent header sent by the client
|
|
144
|
+
`network.local.address` | Like net.peer.ip but for the host IP. Useful in case of a multi-IP host
|
|
145
|
+
`server.address` | Local hostname or similar
|
|
146
|
+
`server.port` | Like net.peer.port but for the host port
|
|
147
|
+
`network.peer.address` | Remote address of the peer (dotted decimal for IPv4 or RFC5952 for IPv6)
|
|
148
|
+
`server.address` | Server domain name if available without reverse DNS lookup
|
|
149
|
+
`server.port` | Server port number
|
|
150
|
+
`network.transport` | Transport protocol used
|
|
151
|
+
|
|
152
|
+
**Metrics:**
|
|
124
153
|
|
|
125
154
|
- [`http.server.request.duration`](https://github.com/open-telemetry/semantic-conventions/blob/v1.27.0/docs/http/http-metrics.md#metric-httpserverrequestduration)
|
|
126
155
|
- [`http.client.request.duration`](https://github.com/open-telemetry/semantic-conventions/blob/v1.27.0/docs/http/http-metrics.md#metric-httpclientrequestduration)
|
|
127
156
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
When upgrading to the new semantic conventions, it is recommended to do so in the following order:
|
|
131
|
-
|
|
132
|
-
1. Upgrade `@opentelemetry/instrumentation-http` to the latest version
|
|
133
|
-
2. Set `OTEL_SEMCONV_STABILITY_OPT_IN=http/dup` to emit both old and new semantic conventions
|
|
134
|
-
3. Modify alerts, dashboards, metrics, and other processes to expect the new semantic conventions
|
|
135
|
-
4. Set `OTEL_SEMCONV_STABILITY_OPT_IN=http` to emit only the new semantic conventions
|
|
136
|
-
|
|
137
|
-
This will cause both the old and new semantic conventions to be emitted during the transition period.
|
|
157
|
+
Versions of `@opentelemetry/instrumentation-http` to 0.221.0 used semantic conventions [v1.7.0](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.7.0/semantic_conventions/README.md) by default. Versions 0.54.0 - 0.220.0 supported [the `OTEL_SEMCONV_STABILITY_OPT_IN` environment variable for migrating from old to stable semantic conventions](https://opentelemetry.io/docs/specs/semconv/non-normative/http-migration/).
|
|
138
158
|
|
|
139
159
|
## Useful links
|
|
140
160
|
|
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
|
@@ -13,6 +13,7 @@ const instrumentation_1 = require("@opentelemetry/instrumentation");
|
|
|
13
13
|
const events_1 = require("events");
|
|
14
14
|
const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
|
|
15
15
|
const utils_1 = require("./utils");
|
|
16
|
+
const internal_types_1 = require("./internal-types");
|
|
16
17
|
/**
|
|
17
18
|
* `node:http` and `node:https` instrumentation for OpenTelemetry
|
|
18
19
|
*/
|
|
@@ -22,24 +23,12 @@ class HttpInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
|
22
23
|
_headerCapture;
|
|
23
24
|
_httpPatched = false;
|
|
24
25
|
_httpsPatched = false;
|
|
25
|
-
_semconvStability = instrumentation_1.SemconvStability.OLD;
|
|
26
26
|
constructor(config = {}) {
|
|
27
27
|
super('@opentelemetry/instrumentation-http', version_1.VERSION, config);
|
|
28
|
-
this.
|
|
29
|
-
this._headerCapture = this._createHeaderCapture(this._semconvStability);
|
|
28
|
+
this._headerCapture = this._createHeaderCapture();
|
|
30
29
|
}
|
|
31
30
|
_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, {
|
|
31
|
+
this._httpServerDurationHistogram = this.meter.createHistogram(semantic_conventions_1.METRIC_HTTP_SERVER_REQUEST_DURATION, {
|
|
43
32
|
description: 'Duration of HTTP server requests.',
|
|
44
33
|
unit: 's',
|
|
45
34
|
valueType: api_1.ValueType.DOUBLE,
|
|
@@ -50,7 +39,7 @@ class HttpInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
|
50
39
|
],
|
|
51
40
|
},
|
|
52
41
|
});
|
|
53
|
-
this.
|
|
42
|
+
this._httpClientDurationHistogram = this.meter.createHistogram(semantic_conventions_1.METRIC_HTTP_CLIENT_REQUEST_DURATION, {
|
|
54
43
|
description: 'Duration of HTTP client requests.',
|
|
55
44
|
unit: 's',
|
|
56
45
|
valueType: api_1.ValueType.DOUBLE,
|
|
@@ -62,29 +51,17 @@ class HttpInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
|
62
51
|
},
|
|
63
52
|
});
|
|
64
53
|
}
|
|
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
|
-
}
|
|
54
|
+
_recordServerDuration(durationMs, attributes) {
|
|
55
|
+
// stable histogram is counted in S
|
|
56
|
+
this._httpServerDurationHistogram.record(durationMs / 1000, attributes);
|
|
74
57
|
}
|
|
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
|
-
}
|
|
58
|
+
_recordClientDuration(durationMs, attributes) {
|
|
59
|
+
// stable histogram is counted in S
|
|
60
|
+
this._httpClientDurationHistogram.record(durationMs / 1000, attributes);
|
|
84
61
|
}
|
|
85
62
|
setConfig(config = {}) {
|
|
86
63
|
super.setConfig(config);
|
|
87
|
-
this._headerCapture = this._createHeaderCapture(
|
|
64
|
+
this._headerCapture = this._createHeaderCapture();
|
|
88
65
|
}
|
|
89
66
|
init() {
|
|
90
67
|
return [this._getHttpsInstrumentation(), this._getHttpInstrumentation()];
|
|
@@ -238,10 +215,9 @@ class HttpInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
|
238
215
|
* @param request The original request object.
|
|
239
216
|
* @param span representing the current operation
|
|
240
217
|
* @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
|
|
218
|
+
* @param metricAttributes metric attributes for the request duration metric
|
|
243
219
|
*/
|
|
244
|
-
_traceClientRequest(request, span, startTime,
|
|
220
|
+
_traceClientRequest(request, span, startTime, metricAttributes) {
|
|
245
221
|
if (this.getConfig().requestHook) {
|
|
246
222
|
this._callRequestHook(span, request);
|
|
247
223
|
}
|
|
@@ -259,10 +235,9 @@ class HttpInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
|
259
235
|
if (request.listenerCount('response') <= 1) {
|
|
260
236
|
response.resume();
|
|
261
237
|
}
|
|
262
|
-
const responseAttributes = (0, utils_1.getOutgoingRequestAttributesOnResponse)(response
|
|
238
|
+
const responseAttributes = (0, utils_1.getOutgoingRequestAttributesOnResponse)(response);
|
|
263
239
|
span.setAttributes(responseAttributes);
|
|
264
|
-
|
|
265
|
-
stableMetricAttributes = Object.assign(stableMetricAttributes, (0, utils_1.getOutgoingStableRequestMetricAttributesOnResponse)(responseAttributes));
|
|
240
|
+
metricAttributes = Object.assign(metricAttributes, (0, utils_1.getOutgoingStableRequestMetricAttributesOnResponse)(responseAttributes));
|
|
266
241
|
if (this.getConfig().responseHook) {
|
|
267
242
|
this._callResponseHook(span, response);
|
|
268
243
|
}
|
|
@@ -289,7 +264,7 @@ class HttpInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
|
289
264
|
if (this.getConfig().applyCustomAttributesOnSpan) {
|
|
290
265
|
(0, instrumentation_1.safeExecuteInTheMiddle)(() => this.getConfig().applyCustomAttributesOnSpan(span, request, response), () => { }, true);
|
|
291
266
|
}
|
|
292
|
-
this._closeHttpSpan(span, api_1.SpanKind.CLIENT, startTime,
|
|
267
|
+
this._closeHttpSpan(span, api_1.SpanKind.CLIENT, startTime, metricAttributes);
|
|
293
268
|
};
|
|
294
269
|
response.on('end', endHandler);
|
|
295
270
|
response.on(events_1.errorMonitor, (error) => {
|
|
@@ -298,7 +273,7 @@ class HttpInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
|
298
273
|
return;
|
|
299
274
|
}
|
|
300
275
|
responseFinished = true;
|
|
301
|
-
this._onOutgoingRequestError(span,
|
|
276
|
+
this._onOutgoingRequestError(span, metricAttributes, startTime, error);
|
|
302
277
|
});
|
|
303
278
|
});
|
|
304
279
|
request.on('close', () => {
|
|
@@ -307,7 +282,7 @@ class HttpInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
|
307
282
|
return;
|
|
308
283
|
}
|
|
309
284
|
responseFinished = true;
|
|
310
|
-
this._closeHttpSpan(span, api_1.SpanKind.CLIENT, startTime,
|
|
285
|
+
this._closeHttpSpan(span, api_1.SpanKind.CLIENT, startTime, metricAttributes);
|
|
311
286
|
});
|
|
312
287
|
request.on(events_1.errorMonitor, (error) => {
|
|
313
288
|
this._diag.debug('outgoingRequest on request error()', error);
|
|
@@ -315,7 +290,7 @@ class HttpInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
|
315
290
|
return;
|
|
316
291
|
}
|
|
317
292
|
responseFinished = true;
|
|
318
|
-
this._onOutgoingRequestError(span,
|
|
293
|
+
this._onOutgoingRequestError(span, metricAttributes, startTime, error);
|
|
319
294
|
});
|
|
320
295
|
this._diag.debug('http.ClientRequest return request');
|
|
321
296
|
return request;
|
|
@@ -345,10 +320,10 @@ class HttpInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
|
345
320
|
const headers = request.headers;
|
|
346
321
|
const spanAttributes = (0, utils_1.getIncomingRequestAttributes)(request, {
|
|
347
322
|
component: component,
|
|
348
|
-
serverName: instrumentation.getConfig().serverName,
|
|
349
323
|
hookAttributes: instrumentation._callStartSpanHook(request, instrumentation.getConfig().startIncomingSpanHook),
|
|
350
|
-
semconvStability: instrumentation._semconvStability,
|
|
351
324
|
enableSyntheticSourceDetection: instrumentation.getConfig().enableSyntheticSourceDetection || false,
|
|
325
|
+
redactedQueryParams: instrumentation.getConfig().redactedQueryParamsServer ??
|
|
326
|
+
Array.from(internal_types_1.DEFAULT_QUERY_STRINGS_TO_REDACT),
|
|
352
327
|
}, instrumentation._diag);
|
|
353
328
|
Object.assign(spanAttributes, instrumentation._headerCapture.server.captureRequestHeaders(header => request.headers[header]));
|
|
354
329
|
const spanOptions = {
|
|
@@ -356,15 +331,14 @@ class HttpInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
|
356
331
|
attributes: spanAttributes,
|
|
357
332
|
};
|
|
358
333
|
const startTime = (0, core_1.hrTime)();
|
|
359
|
-
const oldMetricAttributes = (0, utils_1.getIncomingRequestMetricAttributes)(spanAttributes);
|
|
360
334
|
// request method and url.scheme are both required span attributes
|
|
361
|
-
const
|
|
335
|
+
const metricAttributes = {
|
|
362
336
|
[semantic_conventions_1.ATTR_HTTP_REQUEST_METHOD]: spanAttributes[semantic_conventions_1.ATTR_HTTP_REQUEST_METHOD],
|
|
363
337
|
[semantic_conventions_1.ATTR_URL_SCHEME]: spanAttributes[semantic_conventions_1.ATTR_URL_SCHEME],
|
|
364
338
|
};
|
|
365
339
|
// recommended if and only if one was sent, same as span recommendation
|
|
366
340
|
if (spanAttributes[semantic_conventions_1.ATTR_NETWORK_PROTOCOL_VERSION]) {
|
|
367
|
-
|
|
341
|
+
metricAttributes[semantic_conventions_1.ATTR_NETWORK_PROTOCOL_VERSION] =
|
|
368
342
|
spanAttributes[semantic_conventions_1.ATTR_NETWORK_PROTOCOL_VERSION];
|
|
369
343
|
}
|
|
370
344
|
const ctx = api_1.propagation.extract(api_1.ROOT_CONTEXT, headers);
|
|
@@ -388,15 +362,15 @@ class HttpInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
|
388
362
|
if (hasError) {
|
|
389
363
|
return;
|
|
390
364
|
}
|
|
391
|
-
instrumentation._onServerResponseFinish(request, response, span,
|
|
365
|
+
instrumentation._onServerResponseFinish(request, response, span, metricAttributes, startTime);
|
|
392
366
|
});
|
|
393
367
|
response.on(events_1.errorMonitor, (err) => {
|
|
394
368
|
hasError = true;
|
|
395
|
-
instrumentation._onServerResponseError(span,
|
|
369
|
+
instrumentation._onServerResponseError(span, metricAttributes, startTime, err);
|
|
396
370
|
});
|
|
397
371
|
return (0, instrumentation_1.safeExecuteInTheMiddle)(() => original.apply(this, [event, ...args]), error => {
|
|
398
372
|
if (error) {
|
|
399
|
-
instrumentation._onServerResponseError(span,
|
|
373
|
+
instrumentation._onServerResponseError(span, metricAttributes, startTime, error);
|
|
400
374
|
throw error;
|
|
401
375
|
}
|
|
402
376
|
});
|
|
@@ -430,23 +404,22 @@ class HttpInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
|
430
404
|
hostname,
|
|
431
405
|
hookAttributes: instrumentation._callStartSpanHook(optionsParsed, instrumentation.getConfig().startOutgoingSpanHook),
|
|
432
406
|
redactedQueryParams: instrumentation.getConfig().redactedQueryParams, // Added config for adding custom query strings
|
|
433
|
-
}, instrumentation.
|
|
407
|
+
}, instrumentation.getConfig().enableSyntheticSourceDetection || false);
|
|
434
408
|
const startTime = (0, core_1.hrTime)();
|
|
435
|
-
const oldMetricAttributes = (0, utils_1.getOutgoingRequestMetricAttributes)(attributes);
|
|
436
409
|
// request method, server address, and server port are both required span attributes
|
|
437
|
-
const
|
|
410
|
+
const metricAttributes = {
|
|
438
411
|
[semantic_conventions_1.ATTR_HTTP_REQUEST_METHOD]: attributes[semantic_conventions_1.ATTR_HTTP_REQUEST_METHOD],
|
|
439
412
|
[semantic_conventions_1.ATTR_SERVER_ADDRESS]: attributes[semantic_conventions_1.ATTR_SERVER_ADDRESS],
|
|
440
413
|
[semantic_conventions_1.ATTR_SERVER_PORT]: attributes[semantic_conventions_1.ATTR_SERVER_PORT],
|
|
441
414
|
};
|
|
442
415
|
// required if and only if one was sent, same as span requirement
|
|
443
416
|
if (attributes[semantic_conventions_1.ATTR_HTTP_RESPONSE_STATUS_CODE]) {
|
|
444
|
-
|
|
417
|
+
metricAttributes[semantic_conventions_1.ATTR_HTTP_RESPONSE_STATUS_CODE] =
|
|
445
418
|
attributes[semantic_conventions_1.ATTR_HTTP_RESPONSE_STATUS_CODE];
|
|
446
419
|
}
|
|
447
420
|
// recommended if and only if one was sent, same as span recommendation
|
|
448
421
|
if (attributes[semantic_conventions_1.ATTR_NETWORK_PROTOCOL_VERSION]) {
|
|
449
|
-
|
|
422
|
+
metricAttributes[semantic_conventions_1.ATTR_NETWORK_PROTOCOL_VERSION] =
|
|
450
423
|
attributes[semantic_conventions_1.ATTR_NETWORK_PROTOCOL_VERSION];
|
|
451
424
|
}
|
|
452
425
|
const spanOptions = {
|
|
@@ -486,20 +459,19 @@ class HttpInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
|
486
459
|
}
|
|
487
460
|
}, error => {
|
|
488
461
|
if (error) {
|
|
489
|
-
instrumentation._onOutgoingRequestError(span,
|
|
462
|
+
instrumentation._onOutgoingRequestError(span, metricAttributes, startTime, error);
|
|
490
463
|
throw error;
|
|
491
464
|
}
|
|
492
465
|
});
|
|
493
466
|
instrumentation._diag.debug(`${component} instrumentation outgoingRequest`);
|
|
494
467
|
api_1.context.bind(parentContext, request);
|
|
495
|
-
return instrumentation._traceClientRequest(request, span, startTime,
|
|
468
|
+
return instrumentation._traceClientRequest(request, span, startTime, metricAttributes);
|
|
496
469
|
});
|
|
497
470
|
};
|
|
498
471
|
}
|
|
499
|
-
_onServerResponseFinish(request, response, span,
|
|
500
|
-
const attributes = (0, utils_1.getIncomingRequestAttributesOnResponse)(
|
|
501
|
-
|
|
502
|
-
stableMetricAttributes = Object.assign(stableMetricAttributes, (0, utils_1.getIncomingStableRequestMetricAttributesOnResponse)(attributes));
|
|
472
|
+
_onServerResponseFinish(request, response, span, metricAttributes, startTime) {
|
|
473
|
+
const attributes = (0, utils_1.getIncomingRequestAttributesOnResponse)(response);
|
|
474
|
+
metricAttributes = Object.assign(metricAttributes, (0, utils_1.getIncomingStableRequestMetricAttributesOnResponse)(attributes));
|
|
503
475
|
span.setAttributes(this._headerCapture.server.captureResponseHeaders(header => response.getHeader(header)));
|
|
504
476
|
span.setAttributes(attributes).setStatus({
|
|
505
477
|
code: (0, utils_1.parseResponseStatus)(api_1.SpanKind.SERVER, response.statusCode),
|
|
@@ -511,17 +483,17 @@ class HttpInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
|
511
483
|
if (this.getConfig().applyCustomAttributesOnSpan) {
|
|
512
484
|
(0, instrumentation_1.safeExecuteInTheMiddle)(() => this.getConfig().applyCustomAttributesOnSpan(span, request, response), () => { }, true);
|
|
513
485
|
}
|
|
514
|
-
this._closeHttpSpan(span, api_1.SpanKind.SERVER, startTime,
|
|
486
|
+
this._closeHttpSpan(span, api_1.SpanKind.SERVER, startTime, metricAttributes);
|
|
515
487
|
}
|
|
516
|
-
_onOutgoingRequestError(span,
|
|
517
|
-
(0, utils_1.setSpanWithError)(span, error
|
|
518
|
-
|
|
519
|
-
this._closeHttpSpan(span, api_1.SpanKind.CLIENT, startTime,
|
|
488
|
+
_onOutgoingRequestError(span, metricAttributes, startTime, error) {
|
|
489
|
+
(0, utils_1.setSpanWithError)(span, error);
|
|
490
|
+
metricAttributes[semantic_conventions_1.ATTR_ERROR_TYPE] = error.name;
|
|
491
|
+
this._closeHttpSpan(span, api_1.SpanKind.CLIENT, startTime, metricAttributes);
|
|
520
492
|
}
|
|
521
|
-
_onServerResponseError(span,
|
|
522
|
-
(0, utils_1.setSpanWithError)(span, error
|
|
523
|
-
|
|
524
|
-
this._closeHttpSpan(span, api_1.SpanKind.SERVER, startTime,
|
|
493
|
+
_onServerResponseError(span, metricAttributes, startTime, error) {
|
|
494
|
+
(0, utils_1.setSpanWithError)(span, error);
|
|
495
|
+
metricAttributes[semantic_conventions_1.ATTR_ERROR_TYPE] = error.name;
|
|
496
|
+
this._closeHttpSpan(span, api_1.SpanKind.SERVER, startTime, metricAttributes);
|
|
525
497
|
}
|
|
526
498
|
_startHttpSpan(name, options, ctx = api_1.context.active()) {
|
|
527
499
|
/*
|
|
@@ -546,7 +518,7 @@ class HttpInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
|
546
518
|
this._spanNotEnded.add(span);
|
|
547
519
|
return span;
|
|
548
520
|
}
|
|
549
|
-
_closeHttpSpan(span, spanKind, startTime,
|
|
521
|
+
_closeHttpSpan(span, spanKind, startTime, metricAttributes) {
|
|
550
522
|
if (!this._spanNotEnded.has(span)) {
|
|
551
523
|
return;
|
|
552
524
|
}
|
|
@@ -555,10 +527,10 @@ class HttpInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
|
555
527
|
// Record metrics
|
|
556
528
|
const duration = (0, core_1.hrTimeToMilliseconds)((0, core_1.hrTimeDuration)(startTime, (0, core_1.hrTime)()));
|
|
557
529
|
if (spanKind === api_1.SpanKind.SERVER) {
|
|
558
|
-
this._recordServerDuration(duration,
|
|
530
|
+
this._recordServerDuration(duration, metricAttributes);
|
|
559
531
|
}
|
|
560
532
|
else if (spanKind === api_1.SpanKind.CLIENT) {
|
|
561
|
-
this._recordClientDuration(duration,
|
|
533
|
+
this._recordClientDuration(duration, metricAttributes);
|
|
562
534
|
}
|
|
563
535
|
}
|
|
564
536
|
_callResponseHook(span, response) {
|
|
@@ -572,16 +544,16 @@ class HttpInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
|
572
544
|
return (0, instrumentation_1.safeExecuteInTheMiddle)(() => hookFunc(request), () => { }, true);
|
|
573
545
|
}
|
|
574
546
|
}
|
|
575
|
-
_createHeaderCapture(
|
|
547
|
+
_createHeaderCapture() {
|
|
576
548
|
const config = this.getConfig();
|
|
577
549
|
return {
|
|
578
550
|
client: {
|
|
579
|
-
captureRequestHeaders: (0, utils_1.headerCapture)('request', config.headersToSpanAttributes?.client?.requestHeaders ?? []
|
|
580
|
-
captureResponseHeaders: (0, utils_1.headerCapture)('response', config.headersToSpanAttributes?.client?.responseHeaders ?? []
|
|
551
|
+
captureRequestHeaders: (0, utils_1.headerCapture)('request', config.headersToSpanAttributes?.client?.requestHeaders ?? []),
|
|
552
|
+
captureResponseHeaders: (0, utils_1.headerCapture)('response', config.headersToSpanAttributes?.client?.responseHeaders ?? []),
|
|
581
553
|
},
|
|
582
554
|
server: {
|
|
583
|
-
captureRequestHeaders: (0, utils_1.headerCapture)('request', config.headersToSpanAttributes?.server?.requestHeaders ?? []
|
|
584
|
-
captureResponseHeaders: (0, utils_1.headerCapture)('response', config.headersToSpanAttributes?.server?.responseHeaders ?? []
|
|
555
|
+
captureRequestHeaders: (0, utils_1.headerCapture)('request', config.headersToSpanAttributes?.server?.requestHeaders ?? []),
|
|
556
|
+
captureResponseHeaders: (0, utils_1.headerCapture)('response', config.headersToSpanAttributes?.server?.responseHeaders ?? []),
|
|
585
557
|
},
|
|
586
558
|
};
|
|
587
559
|
}
|