@opentelemetry/instrumentation-http 0.200.0 → 0.201.1
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 +57 -71
- package/build/src/http.js +10 -22
- package/build/src/http.js.map +1 -1
- package/build/src/internal-types.d.ts +6 -12
- package/build/src/internal-types.js +9 -0
- package/build/src/internal-types.js.map +1 -1
- package/build/src/semconv.d.ts +239 -0
- package/build/src/semconv.js +262 -0
- package/build/src/semconv.js.map +1 -0
- package/build/src/types.d.ts +5 -0
- package/build/src/types.js.map +1 -1
- package/build/src/utils.d.ts +9 -2
- package/build/src/utils.js +109 -65
- 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 +9 -9
package/build/src/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.headerCapture = exports.getIncomingStableRequestMetricAttributesOnResponse = exports.getIncomingRequestMetricAttributesOnResponse = exports.getIncomingRequestAttributesOnResponse = exports.getIncomingRequestMetricAttributes = exports.getIncomingRequestAttributes = exports.getRemoteClientAddress = exports.getOutgoingRequestMetricAttributesOnResponse = exports.getOutgoingRequestAttributesOnResponse = exports.setAttributesFromHttpKind = exports.getOutgoingRequestMetricAttributes = exports.getOutgoingRequestAttributes = exports.extractHostnameAndPort = exports.isValidOptionsType = exports.getRequestInfo = exports.isCompressed = exports.setResponseContentLengthAttribute = exports.setRequestContentLengthAttribute = exports.setSpanWithError = exports.satisfiesPattern = exports.parseResponseStatus = exports.getAbsoluteUrl = void 0;
|
|
3
|
+
exports.headerCapture = exports.getIncomingStableRequestMetricAttributesOnResponse = exports.getIncomingRequestMetricAttributesOnResponse = exports.getIncomingRequestAttributesOnResponse = exports.getIncomingRequestMetricAttributes = exports.getIncomingRequestAttributes = exports.getRemoteClientAddress = exports.getOutgoingStableRequestMetricAttributesOnResponse = exports.getOutgoingRequestMetricAttributesOnResponse = exports.getOutgoingRequestAttributesOnResponse = exports.setAttributesFromHttpKind = exports.getOutgoingRequestMetricAttributes = exports.getOutgoingRequestAttributes = exports.extractHostnameAndPort = exports.isValidOptionsType = exports.getRequestInfo = exports.isCompressed = exports.setResponseContentLengthAttribute = exports.setRequestContentLengthAttribute = exports.setSpanWithError = exports.satisfiesPattern = exports.parseResponseStatus = exports.getAbsoluteUrl = void 0;
|
|
4
4
|
/*
|
|
5
5
|
* Copyright The OpenTelemetry Authors
|
|
6
6
|
*
|
|
@@ -18,9 +18,12 @@ exports.headerCapture = exports.getIncomingStableRequestMetricAttributesOnRespon
|
|
|
18
18
|
*/
|
|
19
19
|
const api_1 = require("@opentelemetry/api");
|
|
20
20
|
const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
|
|
21
|
+
const semconv_1 = require("./semconv");
|
|
21
22
|
const core_1 = require("@opentelemetry/core");
|
|
23
|
+
const instrumentation_1 = require("@opentelemetry/instrumentation");
|
|
22
24
|
const url = require("url");
|
|
23
25
|
const AttributeNames_1 = require("./enums/AttributeNames");
|
|
26
|
+
const internal_types_1 = require("./internal-types");
|
|
24
27
|
const forwardedParse = require("forwarded-parse");
|
|
25
28
|
/**
|
|
26
29
|
* Get an absolute url
|
|
@@ -84,12 +87,11 @@ exports.satisfiesPattern = satisfiesPattern;
|
|
|
84
87
|
*/
|
|
85
88
|
const setSpanWithError = (span, error, semconvStability) => {
|
|
86
89
|
const message = error.message;
|
|
87
|
-
if (
|
|
90
|
+
if (semconvStability & instrumentation_1.SemconvStability.OLD) {
|
|
88
91
|
span.setAttribute(AttributeNames_1.AttributeNames.HTTP_ERROR_NAME, error.name);
|
|
89
92
|
span.setAttribute(AttributeNames_1.AttributeNames.HTTP_ERROR_MESSAGE, message);
|
|
90
93
|
}
|
|
91
|
-
if (
|
|
92
|
-
1 /* SemconvStability.STABLE */) {
|
|
94
|
+
if (semconvStability & instrumentation_1.SemconvStability.STABLE) {
|
|
93
95
|
span.setAttribute(semantic_conventions_1.ATTR_ERROR_TYPE, error.name);
|
|
94
96
|
}
|
|
95
97
|
span.setStatus({ code: api_1.SpanStatusCode.ERROR, message });
|
|
@@ -106,10 +108,10 @@ const setRequestContentLengthAttribute = (request, attributes) => {
|
|
|
106
108
|
if (length === null)
|
|
107
109
|
return;
|
|
108
110
|
if ((0, exports.isCompressed)(request.headers)) {
|
|
109
|
-
attributes[
|
|
111
|
+
attributes[semconv_1.ATTR_HTTP_REQUEST_CONTENT_LENGTH] = length;
|
|
110
112
|
}
|
|
111
113
|
else {
|
|
112
|
-
attributes[
|
|
114
|
+
attributes[semconv_1.ATTR_HTTP_REQUEST_CONTENT_LENGTH_UNCOMPRESSED] = length;
|
|
113
115
|
}
|
|
114
116
|
};
|
|
115
117
|
exports.setRequestContentLengthAttribute = setRequestContentLengthAttribute;
|
|
@@ -125,10 +127,10 @@ const setResponseContentLengthAttribute = (response, attributes) => {
|
|
|
125
127
|
if (length === null)
|
|
126
128
|
return;
|
|
127
129
|
if ((0, exports.isCompressed)(response.headers)) {
|
|
128
|
-
attributes[
|
|
130
|
+
attributes[semconv_1.ATTR_HTTP_RESPONSE_CONTENT_LENGTH] = length;
|
|
129
131
|
}
|
|
130
132
|
else {
|
|
131
|
-
attributes[
|
|
133
|
+
attributes[semconv_1.ATTR_HTTP_RESPONSE_CONTENT_LENGTH_UNCOMPRESSED] = length;
|
|
132
134
|
}
|
|
133
135
|
};
|
|
134
136
|
exports.setResponseContentLengthAttribute = setResponseContentLengthAttribute;
|
|
@@ -294,7 +296,7 @@ exports.extractHostnameAndPort = extractHostnameAndPort;
|
|
|
294
296
|
* @param {{ component: string, hostname: string, hookAttributes?: Attributes }} options used to pass data needed to create attributes
|
|
295
297
|
* @param {SemconvStability} semconvStability determines which semconv version to use
|
|
296
298
|
*/
|
|
297
|
-
const getOutgoingRequestAttributes = (requestOptions, options, semconvStability) => {
|
|
299
|
+
const getOutgoingRequestAttributes = (requestOptions, options, semconvStability, enableSyntheticSourceDetection) => {
|
|
298
300
|
const hostname = options.hostname;
|
|
299
301
|
const port = options.port;
|
|
300
302
|
const method = requestOptions.method ?? 'GET';
|
|
@@ -303,11 +305,11 @@ const getOutgoingRequestAttributes = (requestOptions, options, semconvStability)
|
|
|
303
305
|
const userAgent = headers['user-agent'];
|
|
304
306
|
const urlFull = (0, exports.getAbsoluteUrl)(requestOptions, headers, `${options.component}:`);
|
|
305
307
|
const oldAttributes = {
|
|
306
|
-
[
|
|
307
|
-
[
|
|
308
|
-
[
|
|
309
|
-
[
|
|
310
|
-
[
|
|
308
|
+
[semconv_1.ATTR_HTTP_URL]: urlFull,
|
|
309
|
+
[semconv_1.ATTR_HTTP_METHOD]: method,
|
|
310
|
+
[semconv_1.ATTR_HTTP_TARGET]: requestOptions.path || '/',
|
|
311
|
+
[semconv_1.ATTR_NET_PEER_NAME]: hostname,
|
|
312
|
+
[semconv_1.ATTR_HTTP_HOST]: headers.host ?? `${hostname}:${port}`,
|
|
311
313
|
};
|
|
312
314
|
const newAttributes = {
|
|
313
315
|
// Required attributes
|
|
@@ -315,6 +317,7 @@ const getOutgoingRequestAttributes = (requestOptions, options, semconvStability)
|
|
|
315
317
|
[semantic_conventions_1.ATTR_SERVER_ADDRESS]: hostname,
|
|
316
318
|
[semantic_conventions_1.ATTR_SERVER_PORT]: Number(port),
|
|
317
319
|
[semantic_conventions_1.ATTR_URL_FULL]: urlFull,
|
|
320
|
+
[semantic_conventions_1.ATTR_USER_AGENT_ORIGINAL]: userAgent,
|
|
318
321
|
// leaving out protocol version, it is not yet negotiated
|
|
319
322
|
// leaving out protocol name, it is only required when protocol version is set
|
|
320
323
|
// retries and redirects not supported
|
|
@@ -324,13 +327,16 @@ const getOutgoingRequestAttributes = (requestOptions, options, semconvStability)
|
|
|
324
327
|
if (method !== normalizedMethod) {
|
|
325
328
|
newAttributes[semantic_conventions_1.ATTR_HTTP_REQUEST_METHOD_ORIGINAL] = method;
|
|
326
329
|
}
|
|
330
|
+
if (enableSyntheticSourceDetection && userAgent) {
|
|
331
|
+
newAttributes[semconv_1.ATTR_USER_AGENT_SYNTHETIC_TYPE] = getSyntheticType(userAgent);
|
|
332
|
+
}
|
|
327
333
|
if (userAgent !== undefined) {
|
|
328
|
-
oldAttributes[
|
|
334
|
+
oldAttributes[semconv_1.ATTR_HTTP_USER_AGENT] = userAgent;
|
|
329
335
|
}
|
|
330
336
|
switch (semconvStability) {
|
|
331
|
-
case
|
|
337
|
+
case instrumentation_1.SemconvStability.STABLE:
|
|
332
338
|
return Object.assign(newAttributes, options.hookAttributes);
|
|
333
|
-
case
|
|
339
|
+
case instrumentation_1.SemconvStability.OLD:
|
|
334
340
|
return Object.assign(oldAttributes, options.hookAttributes);
|
|
335
341
|
}
|
|
336
342
|
return Object.assign(oldAttributes, newAttributes, options.hookAttributes);
|
|
@@ -342,9 +348,8 @@ exports.getOutgoingRequestAttributes = getOutgoingRequestAttributes;
|
|
|
342
348
|
*/
|
|
343
349
|
const getOutgoingRequestMetricAttributes = (spanAttributes) => {
|
|
344
350
|
const metricAttributes = {};
|
|
345
|
-
metricAttributes[
|
|
346
|
-
metricAttributes[
|
|
347
|
-
spanAttributes[semantic_conventions_1.SEMATTRS_NET_PEER_NAME];
|
|
351
|
+
metricAttributes[semconv_1.ATTR_HTTP_METHOD] = spanAttributes[semconv_1.ATTR_HTTP_METHOD];
|
|
352
|
+
metricAttributes[semconv_1.ATTR_NET_PEER_NAME] = spanAttributes[semconv_1.ATTR_NET_PEER_NAME];
|
|
348
353
|
//TODO: http.url attribute, it should substitute any parameters to avoid high cardinality.
|
|
349
354
|
return metricAttributes;
|
|
350
355
|
};
|
|
@@ -355,16 +360,34 @@ exports.getOutgoingRequestMetricAttributes = getOutgoingRequestMetricAttributes;
|
|
|
355
360
|
*/
|
|
356
361
|
const setAttributesFromHttpKind = (kind, attributes) => {
|
|
357
362
|
if (kind) {
|
|
358
|
-
attributes[
|
|
363
|
+
attributes[semconv_1.ATTR_HTTP_FLAVOR] = kind;
|
|
359
364
|
if (kind.toUpperCase() !== 'QUIC') {
|
|
360
|
-
attributes[
|
|
365
|
+
attributes[semconv_1.ATTR_NET_TRANSPORT] = semconv_1.NET_TRANSPORT_VALUE_IP_TCP;
|
|
361
366
|
}
|
|
362
367
|
else {
|
|
363
|
-
attributes[
|
|
368
|
+
attributes[semconv_1.ATTR_NET_TRANSPORT] = semconv_1.NET_TRANSPORT_VALUE_IP_UDP;
|
|
364
369
|
}
|
|
365
370
|
}
|
|
366
371
|
};
|
|
367
372
|
exports.setAttributesFromHttpKind = setAttributesFromHttpKind;
|
|
373
|
+
/**
|
|
374
|
+
* Returns the type of synthetic source based on the user agent
|
|
375
|
+
* @param {OutgoingHttpHeader} userAgent the user agent string
|
|
376
|
+
*/
|
|
377
|
+
const getSyntheticType = (userAgent) => {
|
|
378
|
+
const userAgentString = String(userAgent).toLowerCase();
|
|
379
|
+
for (const name of internal_types_1.SYNTHETIC_TEST_NAMES) {
|
|
380
|
+
if (userAgentString.includes(name)) {
|
|
381
|
+
return semconv_1.USER_AGENT_SYNTHETIC_TYPE_VALUE_TEST;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
for (const name of internal_types_1.SYNTHETIC_BOT_NAMES) {
|
|
385
|
+
if (userAgentString.includes(name)) {
|
|
386
|
+
return semconv_1.USER_AGENT_SYNTHETIC_TYPE_VALUE_BOT;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
return;
|
|
390
|
+
};
|
|
368
391
|
/**
|
|
369
392
|
* Returns outgoing request attributes scoped to the response data
|
|
370
393
|
* @param {IncomingMessage} response the response object
|
|
@@ -379,8 +402,8 @@ const getOutgoingRequestAttributesOnResponse = (response, semconvStability) => {
|
|
|
379
402
|
}
|
|
380
403
|
if (socket) {
|
|
381
404
|
const { remoteAddress, remotePort } = socket;
|
|
382
|
-
oldAttributes[
|
|
383
|
-
oldAttributes[
|
|
405
|
+
oldAttributes[semconv_1.ATTR_NET_PEER_IP] = remoteAddress;
|
|
406
|
+
oldAttributes[semconv_1.ATTR_NET_PEER_PORT] = remotePort;
|
|
384
407
|
// Recommended
|
|
385
408
|
stableAttributes[semantic_conventions_1.ATTR_NETWORK_PEER_ADDRESS] = remoteAddress;
|
|
386
409
|
stableAttributes[semantic_conventions_1.ATTR_NETWORK_PEER_PORT] = remotePort;
|
|
@@ -388,14 +411,14 @@ const getOutgoingRequestAttributesOnResponse = (response, semconvStability) => {
|
|
|
388
411
|
}
|
|
389
412
|
(0, exports.setResponseContentLengthAttribute)(response, oldAttributes);
|
|
390
413
|
if (statusCode) {
|
|
391
|
-
oldAttributes[
|
|
414
|
+
oldAttributes[semconv_1.ATTR_HTTP_STATUS_CODE] = statusCode;
|
|
392
415
|
oldAttributes[AttributeNames_1.AttributeNames.HTTP_STATUS_TEXT] = (statusMessage || '').toUpperCase();
|
|
393
416
|
}
|
|
394
417
|
(0, exports.setAttributesFromHttpKind)(httpVersion, oldAttributes);
|
|
395
418
|
switch (semconvStability) {
|
|
396
|
-
case
|
|
419
|
+
case instrumentation_1.SemconvStability.STABLE:
|
|
397
420
|
return stableAttributes;
|
|
398
|
-
case
|
|
421
|
+
case instrumentation_1.SemconvStability.OLD:
|
|
399
422
|
return oldAttributes;
|
|
400
423
|
}
|
|
401
424
|
return Object.assign(oldAttributes, stableAttributes);
|
|
@@ -407,14 +430,26 @@ exports.getOutgoingRequestAttributesOnResponse = getOutgoingRequestAttributesOnR
|
|
|
407
430
|
*/
|
|
408
431
|
const getOutgoingRequestMetricAttributesOnResponse = (spanAttributes) => {
|
|
409
432
|
const metricAttributes = {};
|
|
410
|
-
metricAttributes[
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
metricAttributes[semantic_conventions_1.SEMATTRS_HTTP_FLAVOR] = spanAttributes[semantic_conventions_1.SEMATTRS_HTTP_FLAVOR];
|
|
433
|
+
metricAttributes[semconv_1.ATTR_NET_PEER_PORT] = spanAttributes[semconv_1.ATTR_NET_PEER_PORT];
|
|
434
|
+
metricAttributes[semconv_1.ATTR_HTTP_STATUS_CODE] =
|
|
435
|
+
spanAttributes[semconv_1.ATTR_HTTP_STATUS_CODE];
|
|
436
|
+
metricAttributes[semconv_1.ATTR_HTTP_FLAVOR] = spanAttributes[semconv_1.ATTR_HTTP_FLAVOR];
|
|
415
437
|
return metricAttributes;
|
|
416
438
|
};
|
|
417
439
|
exports.getOutgoingRequestMetricAttributesOnResponse = getOutgoingRequestMetricAttributesOnResponse;
|
|
440
|
+
const getOutgoingStableRequestMetricAttributesOnResponse = (spanAttributes) => {
|
|
441
|
+
const metricAttributes = {};
|
|
442
|
+
if (spanAttributes[semantic_conventions_1.ATTR_NETWORK_PROTOCOL_VERSION]) {
|
|
443
|
+
metricAttributes[semantic_conventions_1.ATTR_NETWORK_PROTOCOL_VERSION] =
|
|
444
|
+
spanAttributes[semantic_conventions_1.ATTR_NETWORK_PROTOCOL_VERSION];
|
|
445
|
+
}
|
|
446
|
+
if (spanAttributes[semantic_conventions_1.ATTR_HTTP_RESPONSE_STATUS_CODE]) {
|
|
447
|
+
metricAttributes[semantic_conventions_1.ATTR_HTTP_RESPONSE_STATUS_CODE] =
|
|
448
|
+
spanAttributes[semantic_conventions_1.ATTR_HTTP_RESPONSE_STATUS_CODE];
|
|
449
|
+
}
|
|
450
|
+
return metricAttributes;
|
|
451
|
+
};
|
|
452
|
+
exports.getOutgoingStableRequestMetricAttributesOnResponse = getOutgoingStableRequestMetricAttributesOnResponse;
|
|
418
453
|
function parseHostHeader(hostHeader, proto) {
|
|
419
454
|
const parts = hostHeader.split(':');
|
|
420
455
|
// no semicolon implies ipv4 dotted syntax or host name without port
|
|
@@ -586,8 +621,12 @@ const getIncomingRequestAttributes = (request, options, logger) => {
|
|
|
586
621
|
if (parsedUrl?.pathname != null) {
|
|
587
622
|
newAttributes[semantic_conventions_1.ATTR_URL_PATH] = parsedUrl.pathname;
|
|
588
623
|
}
|
|
624
|
+
if (parsedUrl.search) {
|
|
625
|
+
// Remove leading '?' from URL search (https://developer.mozilla.org/en-US/docs/Web/API/URL/search).
|
|
626
|
+
newAttributes[semantic_conventions_1.ATTR_URL_QUERY] = parsedUrl.search.slice(1);
|
|
627
|
+
}
|
|
589
628
|
if (remoteClientAddress != null) {
|
|
590
|
-
newAttributes[semantic_conventions_1.ATTR_CLIENT_ADDRESS] = remoteClientAddress;
|
|
629
|
+
newAttributes[semantic_conventions_1.ATTR_CLIENT_ADDRESS] = remoteClientAddress.split(',')[0];
|
|
591
630
|
}
|
|
592
631
|
if (serverAddress?.port != null) {
|
|
593
632
|
newAttributes[semantic_conventions_1.ATTR_SERVER_PORT] = Number(serverAddress.port);
|
|
@@ -596,32 +635,35 @@ const getIncomingRequestAttributes = (request, options, logger) => {
|
|
|
596
635
|
if (method !== normalizedMethod) {
|
|
597
636
|
newAttributes[semantic_conventions_1.ATTR_HTTP_REQUEST_METHOD_ORIGINAL] = method;
|
|
598
637
|
}
|
|
638
|
+
if (options.enableSyntheticSourceDetection && userAgent) {
|
|
639
|
+
newAttributes[semconv_1.ATTR_USER_AGENT_SYNTHETIC_TYPE] = getSyntheticType(userAgent);
|
|
640
|
+
}
|
|
599
641
|
const oldAttributes = {
|
|
600
|
-
[
|
|
601
|
-
[
|
|
602
|
-
[
|
|
603
|
-
[
|
|
604
|
-
[
|
|
642
|
+
[semconv_1.ATTR_HTTP_URL]: parsedUrl.toString(),
|
|
643
|
+
[semconv_1.ATTR_HTTP_HOST]: host,
|
|
644
|
+
[semconv_1.ATTR_NET_HOST_NAME]: hostname,
|
|
645
|
+
[semconv_1.ATTR_HTTP_METHOD]: method,
|
|
646
|
+
[semconv_1.ATTR_HTTP_SCHEME]: options.component,
|
|
605
647
|
};
|
|
606
648
|
if (typeof ips === 'string') {
|
|
607
|
-
oldAttributes[
|
|
649
|
+
oldAttributes[semconv_1.ATTR_HTTP_CLIENT_IP] = ips.split(',')[0];
|
|
608
650
|
}
|
|
609
651
|
if (typeof serverName === 'string') {
|
|
610
|
-
oldAttributes[
|
|
652
|
+
oldAttributes[semconv_1.ATTR_HTTP_SERVER_NAME] = serverName;
|
|
611
653
|
}
|
|
612
654
|
if (parsedUrl?.pathname) {
|
|
613
|
-
oldAttributes[
|
|
655
|
+
oldAttributes[semconv_1.ATTR_HTTP_TARGET] =
|
|
614
656
|
parsedUrl?.pathname + parsedUrl?.search || '/';
|
|
615
657
|
}
|
|
616
658
|
if (userAgent !== undefined) {
|
|
617
|
-
oldAttributes[
|
|
659
|
+
oldAttributes[semconv_1.ATTR_HTTP_USER_AGENT] = userAgent;
|
|
618
660
|
}
|
|
619
661
|
(0, exports.setRequestContentLengthAttribute)(request, oldAttributes);
|
|
620
662
|
(0, exports.setAttributesFromHttpKind)(httpVersion, oldAttributes);
|
|
621
663
|
switch (options.semconvStability) {
|
|
622
|
-
case
|
|
664
|
+
case instrumentation_1.SemconvStability.STABLE:
|
|
623
665
|
return Object.assign(newAttributes, options.hookAttributes);
|
|
624
|
-
case
|
|
666
|
+
case instrumentation_1.SemconvStability.OLD:
|
|
625
667
|
return Object.assign(oldAttributes, options.hookAttributes);
|
|
626
668
|
}
|
|
627
669
|
return Object.assign(oldAttributes, newAttributes, options.hookAttributes);
|
|
@@ -634,11 +676,10 @@ exports.getIncomingRequestAttributes = getIncomingRequestAttributes;
|
|
|
634
676
|
*/
|
|
635
677
|
const getIncomingRequestMetricAttributes = (spanAttributes) => {
|
|
636
678
|
const metricAttributes = {};
|
|
637
|
-
metricAttributes[
|
|
638
|
-
metricAttributes[
|
|
639
|
-
metricAttributes[
|
|
640
|
-
|
|
641
|
-
metricAttributes[semantic_conventions_1.SEMATTRS_HTTP_FLAVOR] = spanAttributes[semantic_conventions_1.SEMATTRS_HTTP_FLAVOR];
|
|
679
|
+
metricAttributes[semconv_1.ATTR_HTTP_SCHEME] = spanAttributes[semconv_1.ATTR_HTTP_SCHEME];
|
|
680
|
+
metricAttributes[semconv_1.ATTR_HTTP_METHOD] = spanAttributes[semconv_1.ATTR_HTTP_METHOD];
|
|
681
|
+
metricAttributes[semconv_1.ATTR_NET_HOST_NAME] = spanAttributes[semconv_1.ATTR_NET_HOST_NAME];
|
|
682
|
+
metricAttributes[semconv_1.ATTR_HTTP_FLAVOR] = spanAttributes[semconv_1.ATTR_HTTP_FLAVOR];
|
|
642
683
|
//TODO: http.target attribute, it should substitute any parameters to avoid high cardinality.
|
|
643
684
|
return metricAttributes;
|
|
644
685
|
};
|
|
@@ -659,21 +700,21 @@ const getIncomingRequestAttributesOnResponse = (request, response, semconvStabil
|
|
|
659
700
|
const oldAttributes = {};
|
|
660
701
|
if (socket) {
|
|
661
702
|
const { localAddress, localPort, remoteAddress, remotePort } = socket;
|
|
662
|
-
oldAttributes[
|
|
663
|
-
oldAttributes[
|
|
664
|
-
oldAttributes[
|
|
665
|
-
oldAttributes[
|
|
703
|
+
oldAttributes[semconv_1.ATTR_NET_HOST_IP] = localAddress;
|
|
704
|
+
oldAttributes[semconv_1.ATTR_NET_HOST_PORT] = localPort;
|
|
705
|
+
oldAttributes[semconv_1.ATTR_NET_PEER_IP] = remoteAddress;
|
|
706
|
+
oldAttributes[semconv_1.ATTR_NET_PEER_PORT] = remotePort;
|
|
666
707
|
}
|
|
667
|
-
oldAttributes[
|
|
708
|
+
oldAttributes[semconv_1.ATTR_HTTP_STATUS_CODE] = statusCode;
|
|
668
709
|
oldAttributes[AttributeNames_1.AttributeNames.HTTP_STATUS_TEXT] = (statusMessage || '').toUpperCase();
|
|
669
710
|
if (rpcMetadata?.type === core_1.RPCType.HTTP && rpcMetadata.route !== undefined) {
|
|
670
|
-
oldAttributes[semantic_conventions_1.
|
|
711
|
+
oldAttributes[semantic_conventions_1.ATTR_HTTP_ROUTE] = rpcMetadata.route;
|
|
671
712
|
newAttributes[semantic_conventions_1.ATTR_HTTP_ROUTE] = rpcMetadata.route;
|
|
672
713
|
}
|
|
673
714
|
switch (semconvStability) {
|
|
674
|
-
case
|
|
715
|
+
case instrumentation_1.SemconvStability.STABLE:
|
|
675
716
|
return newAttributes;
|
|
676
|
-
case
|
|
717
|
+
case instrumentation_1.SemconvStability.OLD:
|
|
677
718
|
return oldAttributes;
|
|
678
719
|
}
|
|
679
720
|
return Object.assign(oldAttributes, newAttributes);
|
|
@@ -685,20 +726,23 @@ exports.getIncomingRequestAttributesOnResponse = getIncomingRequestAttributesOnR
|
|
|
685
726
|
*/
|
|
686
727
|
const getIncomingRequestMetricAttributesOnResponse = (spanAttributes) => {
|
|
687
728
|
const metricAttributes = {};
|
|
688
|
-
metricAttributes[
|
|
689
|
-
spanAttributes[
|
|
690
|
-
metricAttributes[
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
metricAttributes[semantic_conventions_1.SEMATTRS_HTTP_ROUTE] = spanAttributes[semantic_conventions_1.SEMATTRS_HTTP_ROUTE];
|
|
729
|
+
metricAttributes[semconv_1.ATTR_HTTP_STATUS_CODE] =
|
|
730
|
+
spanAttributes[semconv_1.ATTR_HTTP_STATUS_CODE];
|
|
731
|
+
metricAttributes[semconv_1.ATTR_NET_HOST_PORT] = spanAttributes[semconv_1.ATTR_NET_HOST_PORT];
|
|
732
|
+
if (spanAttributes[semantic_conventions_1.ATTR_HTTP_ROUTE] !== undefined) {
|
|
733
|
+
metricAttributes[semantic_conventions_1.ATTR_HTTP_ROUTE] = spanAttributes[semantic_conventions_1.ATTR_HTTP_ROUTE];
|
|
694
734
|
}
|
|
695
735
|
return metricAttributes;
|
|
696
736
|
};
|
|
697
737
|
exports.getIncomingRequestMetricAttributesOnResponse = getIncomingRequestMetricAttributesOnResponse;
|
|
738
|
+
/**
|
|
739
|
+
* Returns incoming stable request Metric attributes scoped to the request data
|
|
740
|
+
* @param {Attributes} spanAttributes the span attributes
|
|
741
|
+
*/
|
|
698
742
|
const getIncomingStableRequestMetricAttributesOnResponse = (spanAttributes) => {
|
|
699
743
|
const metricAttributes = {};
|
|
700
744
|
if (spanAttributes[semantic_conventions_1.ATTR_HTTP_ROUTE] !== undefined) {
|
|
701
|
-
metricAttributes[semantic_conventions_1.ATTR_HTTP_ROUTE] = spanAttributes[semantic_conventions_1.
|
|
745
|
+
metricAttributes[semantic_conventions_1.ATTR_HTTP_ROUTE] = spanAttributes[semantic_conventions_1.ATTR_HTTP_ROUTE];
|
|
702
746
|
}
|
|
703
747
|
// required if and only if one was sent, same as span requirement
|
|
704
748
|
if (spanAttributes[semantic_conventions_1.ATTR_HTTP_RESPONSE_STATUS_CODE]) {
|