@opentelemetry/instrumentation-fetch 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 +29 -11
- package/build/esm/enums/AttributeNames.d.ts +0 -1
- package/build/esm/enums/AttributeNames.js +0 -1
- package/build/esm/enums/AttributeNames.js.map +1 -1
- package/build/esm/fetch.d.ts +3 -0
- package/build/esm/fetch.js +69 -23
- package/build/esm/fetch.js.map +1 -1
- package/build/esm/semconv.d.ts +93 -0
- package/build/esm/semconv.js +113 -0
- package/build/esm/semconv.js.map +1 -0
- package/build/esm/utils.d.ts +7 -0
- package/build/esm/utils.js +56 -0
- package/build/esm/utils.js.map +1 -1
- package/build/esm/version.d.ts +1 -1
- package/build/esm/version.js +1 -1
- package/build/esm/version.js.map +1 -1
- package/build/esnext/enums/AttributeNames.d.ts +0 -1
- package/build/esnext/enums/AttributeNames.js +0 -1
- package/build/esnext/enums/AttributeNames.js.map +1 -1
- package/build/esnext/fetch.d.ts +3 -0
- package/build/esnext/fetch.js +69 -23
- package/build/esnext/fetch.js.map +1 -1
- package/build/esnext/semconv.d.ts +93 -0
- package/build/esnext/semconv.js +113 -0
- package/build/esnext/semconv.js.map +1 -0
- package/build/esnext/utils.d.ts +7 -0
- package/build/esnext/utils.js +56 -0
- package/build/esnext/utils.js.map +1 -1
- package/build/esnext/version.d.ts +1 -1
- package/build/esnext/version.js +1 -1
- package/build/esnext/version.js.map +1 -1
- package/build/src/enums/AttributeNames.d.ts +0 -1
- package/build/src/enums/AttributeNames.js +0 -1
- package/build/src/enums/AttributeNames.js.map +1 -1
- package/build/src/fetch.d.ts +3 -0
- package/build/src/fetch.js +66 -20
- package/build/src/fetch.js.map +1 -1
- package/build/src/semconv.d.ts +93 -0
- package/build/src/semconv.js +116 -0
- package/build/src/semconv.js.map +1 -0
- package/build/src/utils.d.ts +7 -0
- package/build/src/utils.js +59 -1
- 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
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deprecated, use one of `server.address`, `client.address` or `http.request.header.host` instead, depending on the usage.
|
|
3
|
+
*
|
|
4
|
+
* @example www.example.org
|
|
5
|
+
*
|
|
6
|
+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
7
|
+
*
|
|
8
|
+
* @deprecated Replaced by one of `server.address`, `client.address` or `http.request.header.host`, depending on the usage.
|
|
9
|
+
*/
|
|
10
|
+
export declare const ATTR_HTTP_HOST: "http.host";
|
|
11
|
+
/**
|
|
12
|
+
* Deprecated, use `http.request.method` instead.
|
|
13
|
+
*
|
|
14
|
+
* @example GET
|
|
15
|
+
* @example POST
|
|
16
|
+
* @example HEAD
|
|
17
|
+
*
|
|
18
|
+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
19
|
+
*
|
|
20
|
+
* @deprecated Replaced by `http.request.method`.
|
|
21
|
+
*/
|
|
22
|
+
export declare const ATTR_HTTP_METHOD: "http.method";
|
|
23
|
+
/**
|
|
24
|
+
* The size of the request payload body in bytes. This is the number of bytes transferred excluding headers and is often, but not always, present as the [Content-Length](https://www.rfc-editor.org/rfc/rfc9110.html#field.content-length) header. For requests using transport encoding, this should be the compressed size.
|
|
25
|
+
*
|
|
26
|
+
* @example 3495
|
|
27
|
+
*
|
|
28
|
+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
29
|
+
*/
|
|
30
|
+
export declare const ATTR_HTTP_REQUEST_BODY_SIZE: "http.request.body.size";
|
|
31
|
+
/**
|
|
32
|
+
* Deprecated, use `http.request.body.size` instead.
|
|
33
|
+
*
|
|
34
|
+
* @example 5493
|
|
35
|
+
*
|
|
36
|
+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
37
|
+
*
|
|
38
|
+
* @deprecated Replaced by `http.request.body.size`.
|
|
39
|
+
*/
|
|
40
|
+
export declare const ATTR_HTTP_REQUEST_CONTENT_LENGTH_UNCOMPRESSED: "http.request_content_length_uncompressed";
|
|
41
|
+
/**
|
|
42
|
+
* Deprecated, use `http.response.header.<key>` instead.
|
|
43
|
+
*
|
|
44
|
+
* @example 3495
|
|
45
|
+
*
|
|
46
|
+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
47
|
+
*
|
|
48
|
+
* @deprecated Replaced by `http.response.header.<key>`.
|
|
49
|
+
*/
|
|
50
|
+
export declare const ATTR_HTTP_RESPONSE_CONTENT_LENGTH: "http.response_content_length";
|
|
51
|
+
/**
|
|
52
|
+
* Deprecated, use `url.scheme` instead.
|
|
53
|
+
*
|
|
54
|
+
* @example http
|
|
55
|
+
* @example https
|
|
56
|
+
*
|
|
57
|
+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
58
|
+
*
|
|
59
|
+
* @deprecated Replaced by `url.scheme` instead.
|
|
60
|
+
*/
|
|
61
|
+
export declare const ATTR_HTTP_SCHEME: "http.scheme";
|
|
62
|
+
/**
|
|
63
|
+
* Deprecated, use `http.response.status_code` instead.
|
|
64
|
+
*
|
|
65
|
+
* @example 200
|
|
66
|
+
*
|
|
67
|
+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
68
|
+
*
|
|
69
|
+
* @deprecated Replaced by `http.response.status_code`.
|
|
70
|
+
*/
|
|
71
|
+
export declare const ATTR_HTTP_STATUS_CODE: "http.status_code";
|
|
72
|
+
/**
|
|
73
|
+
* Deprecated, use `url.full` instead.
|
|
74
|
+
*
|
|
75
|
+
* @example https://www.foo.bar/search?q=OpenTelemetry#SemConv
|
|
76
|
+
*
|
|
77
|
+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
78
|
+
*
|
|
79
|
+
* @deprecated Replaced by `url.full`.
|
|
80
|
+
*/
|
|
81
|
+
export declare const ATTR_HTTP_URL: "http.url";
|
|
82
|
+
/**
|
|
83
|
+
* Deprecated, use `user_agent.original` instead.
|
|
84
|
+
*
|
|
85
|
+
* @example CERN-LineMode/2.15 libwww/2.17b3
|
|
86
|
+
* @example Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Mobile/15E148 Safari/604.1
|
|
87
|
+
*
|
|
88
|
+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
89
|
+
*
|
|
90
|
+
* @deprecated Replaced by `user_agent.original`.
|
|
91
|
+
*/
|
|
92
|
+
export declare const ATTR_HTTP_USER_AGENT: "http.user_agent";
|
|
93
|
+
//# sourceMappingURL=semconv.d.ts.map
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright The OpenTelemetry Authors
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.ATTR_HTTP_USER_AGENT = exports.ATTR_HTTP_URL = exports.ATTR_HTTP_STATUS_CODE = exports.ATTR_HTTP_SCHEME = exports.ATTR_HTTP_RESPONSE_CONTENT_LENGTH = exports.ATTR_HTTP_REQUEST_CONTENT_LENGTH_UNCOMPRESSED = exports.ATTR_HTTP_REQUEST_BODY_SIZE = exports.ATTR_HTTP_METHOD = exports.ATTR_HTTP_HOST = void 0;
|
|
19
|
+
/*
|
|
20
|
+
* This file contains a copy of unstable semantic convention definitions
|
|
21
|
+
* used by this package.
|
|
22
|
+
* @see https://github.com/open-telemetry/opentelemetry-js/tree/main/semantic-conventions#unstable-semconv
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* Deprecated, use one of `server.address`, `client.address` or `http.request.header.host` instead, depending on the usage.
|
|
26
|
+
*
|
|
27
|
+
* @example www.example.org
|
|
28
|
+
*
|
|
29
|
+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
30
|
+
*
|
|
31
|
+
* @deprecated Replaced by one of `server.address`, `client.address` or `http.request.header.host`, depending on the usage.
|
|
32
|
+
*/
|
|
33
|
+
exports.ATTR_HTTP_HOST = 'http.host';
|
|
34
|
+
/**
|
|
35
|
+
* Deprecated, use `http.request.method` instead.
|
|
36
|
+
*
|
|
37
|
+
* @example GET
|
|
38
|
+
* @example POST
|
|
39
|
+
* @example HEAD
|
|
40
|
+
*
|
|
41
|
+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
42
|
+
*
|
|
43
|
+
* @deprecated Replaced by `http.request.method`.
|
|
44
|
+
*/
|
|
45
|
+
exports.ATTR_HTTP_METHOD = 'http.method';
|
|
46
|
+
/**
|
|
47
|
+
* The size of the request payload body in bytes. This is the number of bytes transferred excluding headers and is often, but not always, present as the [Content-Length](https://www.rfc-editor.org/rfc/rfc9110.html#field.content-length) header. For requests using transport encoding, this should be the compressed size.
|
|
48
|
+
*
|
|
49
|
+
* @example 3495
|
|
50
|
+
*
|
|
51
|
+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
52
|
+
*/
|
|
53
|
+
exports.ATTR_HTTP_REQUEST_BODY_SIZE = 'http.request.body.size';
|
|
54
|
+
/**
|
|
55
|
+
* Deprecated, use `http.request.body.size` instead.
|
|
56
|
+
*
|
|
57
|
+
* @example 5493
|
|
58
|
+
*
|
|
59
|
+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
60
|
+
*
|
|
61
|
+
* @deprecated Replaced by `http.request.body.size`.
|
|
62
|
+
*/
|
|
63
|
+
exports.ATTR_HTTP_REQUEST_CONTENT_LENGTH_UNCOMPRESSED = 'http.request_content_length_uncompressed';
|
|
64
|
+
/**
|
|
65
|
+
* Deprecated, use `http.response.header.<key>` instead.
|
|
66
|
+
*
|
|
67
|
+
* @example 3495
|
|
68
|
+
*
|
|
69
|
+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
70
|
+
*
|
|
71
|
+
* @deprecated Replaced by `http.response.header.<key>`.
|
|
72
|
+
*/
|
|
73
|
+
exports.ATTR_HTTP_RESPONSE_CONTENT_LENGTH = 'http.response_content_length';
|
|
74
|
+
/**
|
|
75
|
+
* Deprecated, use `url.scheme` instead.
|
|
76
|
+
*
|
|
77
|
+
* @example http
|
|
78
|
+
* @example https
|
|
79
|
+
*
|
|
80
|
+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
81
|
+
*
|
|
82
|
+
* @deprecated Replaced by `url.scheme` instead.
|
|
83
|
+
*/
|
|
84
|
+
exports.ATTR_HTTP_SCHEME = 'http.scheme';
|
|
85
|
+
/**
|
|
86
|
+
* Deprecated, use `http.response.status_code` instead.
|
|
87
|
+
*
|
|
88
|
+
* @example 200
|
|
89
|
+
*
|
|
90
|
+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
91
|
+
*
|
|
92
|
+
* @deprecated Replaced by `http.response.status_code`.
|
|
93
|
+
*/
|
|
94
|
+
exports.ATTR_HTTP_STATUS_CODE = 'http.status_code';
|
|
95
|
+
/**
|
|
96
|
+
* Deprecated, use `url.full` instead.
|
|
97
|
+
*
|
|
98
|
+
* @example https://www.foo.bar/search?q=OpenTelemetry#SemConv
|
|
99
|
+
*
|
|
100
|
+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
101
|
+
*
|
|
102
|
+
* @deprecated Replaced by `url.full`.
|
|
103
|
+
*/
|
|
104
|
+
exports.ATTR_HTTP_URL = 'http.url';
|
|
105
|
+
/**
|
|
106
|
+
* Deprecated, use `user_agent.original` instead.
|
|
107
|
+
*
|
|
108
|
+
* @example CERN-LineMode/2.15 libwww/2.17b3
|
|
109
|
+
* @example Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Mobile/15E148 Safari/604.1
|
|
110
|
+
*
|
|
111
|
+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
112
|
+
*
|
|
113
|
+
* @deprecated Replaced by `user_agent.original`.
|
|
114
|
+
*/
|
|
115
|
+
exports.ATTR_HTTP_USER_AGENT = 'http.user_agent';
|
|
116
|
+
//# sourceMappingURL=semconv.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"semconv.js","sourceRoot":"","sources":["../../src/semconv.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH;;;;GAIG;AAEH;;;;;;;;GAQG;AACU,QAAA,cAAc,GAAG,WAAoB,CAAC;AAEnD;;;;;;;;;;GAUG;AACU,QAAA,gBAAgB,GAAG,aAAsB,CAAC;AAEvD;;;;;;GAMG;AACU,QAAA,2BAA2B,GAAG,wBAAiC,CAAC;AAE7E;;;;;;;;GAQG;AACU,QAAA,6CAA6C,GACxD,0CAAmD,CAAC;AAEtD;;;;;;;;GAQG;AACU,QAAA,iCAAiC,GAC5C,8BAAuC,CAAC;AAE1C;;;;;;;;;GASG;AACU,QAAA,gBAAgB,GAAG,aAAsB,CAAC;AAEvD;;;;;;;;GAQG;AACU,QAAA,qBAAqB,GAAG,kBAA2B,CAAC;AAEjE;;;;;;;;GAQG;AACU,QAAA,aAAa,GAAG,UAAmB,CAAC;AAEjD;;;;;;;;;GASG;AACU,QAAA,oBAAoB,GAAG,iBAA0B,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/*\n * This file contains a copy of unstable semantic convention definitions\n * used by this package.\n * @see https://github.com/open-telemetry/opentelemetry-js/tree/main/semantic-conventions#unstable-semconv\n */\n\n/**\n * Deprecated, use one of `server.address`, `client.address` or `http.request.header.host` instead, depending on the usage.\n *\n * @example www.example.org\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n *\n * @deprecated Replaced by one of `server.address`, `client.address` or `http.request.header.host`, depending on the usage.\n */\nexport const ATTR_HTTP_HOST = 'http.host' as const;\n\n/**\n * Deprecated, use `http.request.method` instead.\n *\n * @example GET\n * @example POST\n * @example HEAD\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n *\n * @deprecated Replaced by `http.request.method`.\n */\nexport const ATTR_HTTP_METHOD = 'http.method' as const;\n\n/**\n * The size of the request payload body in bytes. This is the number of bytes transferred excluding headers and is often, but not always, present as the [Content-Length](https://www.rfc-editor.org/rfc/rfc9110.html#field.content-length) header. For requests using transport encoding, this should be the compressed size.\n *\n * @example 3495\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const ATTR_HTTP_REQUEST_BODY_SIZE = 'http.request.body.size' as const;\n\n/**\n * Deprecated, use `http.request.body.size` instead.\n *\n * @example 5493\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n *\n * @deprecated Replaced by `http.request.body.size`.\n */\nexport const ATTR_HTTP_REQUEST_CONTENT_LENGTH_UNCOMPRESSED =\n 'http.request_content_length_uncompressed' as const;\n\n/**\n * Deprecated, use `http.response.header.<key>` instead.\n *\n * @example 3495\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n *\n * @deprecated Replaced by `http.response.header.<key>`.\n */\nexport const ATTR_HTTP_RESPONSE_CONTENT_LENGTH =\n 'http.response_content_length' as const;\n\n/**\n * Deprecated, use `url.scheme` instead.\n *\n * @example http\n * @example https\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n *\n * @deprecated Replaced by `url.scheme` instead.\n */\nexport const ATTR_HTTP_SCHEME = 'http.scheme' as const;\n\n/**\n * Deprecated, use `http.response.status_code` instead.\n *\n * @example 200\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n *\n * @deprecated Replaced by `http.response.status_code`.\n */\nexport const ATTR_HTTP_STATUS_CODE = 'http.status_code' as const;\n\n/**\n * Deprecated, use `url.full` instead.\n *\n * @example https://www.foo.bar/search?q=OpenTelemetry#SemConv\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n *\n * @deprecated Replaced by `url.full`.\n */\nexport const ATTR_HTTP_URL = 'http.url' as const;\n\n/**\n * Deprecated, use `user_agent.original` instead.\n *\n * @example CERN-LineMode/2.15 libwww/2.17b3\n * @example Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Mobile/15E148 Safari/604.1\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n *\n * @deprecated Replaced by `user_agent.original`.\n */\nexport const ATTR_HTTP_USER_AGENT = 'http.user_agent' as const;\n"]}
|
package/build/src/utils.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { URLLike } from '@opentelemetry/sdk-trace-web';
|
|
1
2
|
/**
|
|
2
3
|
* Helper function to determine payload content length for fetch requests
|
|
3
4
|
*
|
|
@@ -33,4 +34,10 @@ export declare function getFetchBodyLength(...args: Parameters<typeof fetch>): P
|
|
|
33
34
|
* @returns content length
|
|
34
35
|
*/
|
|
35
36
|
export declare function getXHRBodyLength(body: Document | XMLHttpRequestBodyInit): number | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Normalize an HTTP request method string per `http.request.method` spec
|
|
39
|
+
* https://github.com/open-telemetry/semantic-conventions/blob/main/docs/http/http-spans.md#http-client-span
|
|
40
|
+
*/
|
|
41
|
+
export declare function normalizeHttpRequestMethod(method: string): string;
|
|
42
|
+
export declare function serverPortFromUrl(url: URLLike): number | undefined;
|
|
36
43
|
//# sourceMappingURL=utils.d.ts.map
|
package/build/src/utils.js
CHANGED
|
@@ -15,10 +15,11 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.getXHRBodyLength = exports.getFetchBodyLength = void 0;
|
|
18
|
+
exports.serverPortFromUrl = exports.normalizeHttpRequestMethod = exports.getXHRBodyLength = exports.getFetchBodyLength = void 0;
|
|
19
19
|
// Much of the logic here overlaps with the same utils file in opentelemetry-instrumentation-xml-http-request
|
|
20
20
|
// These may be unified in the future.
|
|
21
21
|
const api = require("@opentelemetry/api");
|
|
22
|
+
const core_1 = require("@opentelemetry/core");
|
|
22
23
|
const DIAG_LOGGER = api.diag.createComponentLogger({
|
|
23
24
|
namespace: '@opentelemetry/opentelemetry-instrumentation-fetch/utils',
|
|
24
25
|
});
|
|
@@ -160,4 +161,61 @@ function getFormDataSize(formData) {
|
|
|
160
161
|
}
|
|
161
162
|
return size;
|
|
162
163
|
}
|
|
164
|
+
/**
|
|
165
|
+
* Normalize an HTTP request method string per `http.request.method` spec
|
|
166
|
+
* https://github.com/open-telemetry/semantic-conventions/blob/main/docs/http/http-spans.md#http-client-span
|
|
167
|
+
*/
|
|
168
|
+
function normalizeHttpRequestMethod(method) {
|
|
169
|
+
const knownMethods = getKnownMethods();
|
|
170
|
+
const methUpper = method.toUpperCase();
|
|
171
|
+
if (methUpper in knownMethods) {
|
|
172
|
+
return methUpper;
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
return '_OTHER';
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
exports.normalizeHttpRequestMethod = normalizeHttpRequestMethod;
|
|
179
|
+
const DEFAULT_KNOWN_METHODS = {
|
|
180
|
+
CONNECT: true,
|
|
181
|
+
DELETE: true,
|
|
182
|
+
GET: true,
|
|
183
|
+
HEAD: true,
|
|
184
|
+
OPTIONS: true,
|
|
185
|
+
PATCH: true,
|
|
186
|
+
POST: true,
|
|
187
|
+
PUT: true,
|
|
188
|
+
TRACE: true,
|
|
189
|
+
};
|
|
190
|
+
let knownMethods;
|
|
191
|
+
function getKnownMethods() {
|
|
192
|
+
if (knownMethods === undefined) {
|
|
193
|
+
const cfgMethods = (0, core_1.getStringListFromEnv)('OTEL_INSTRUMENTATION_HTTP_KNOWN_METHODS');
|
|
194
|
+
if (cfgMethods && cfgMethods.length > 0) {
|
|
195
|
+
knownMethods = {};
|
|
196
|
+
cfgMethods.forEach(m => {
|
|
197
|
+
knownMethods[m] = true;
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
knownMethods = DEFAULT_KNOWN_METHODS;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return knownMethods;
|
|
205
|
+
}
|
|
206
|
+
const HTTP_PORT_FROM_PROTOCOL = {
|
|
207
|
+
'https:': '443',
|
|
208
|
+
'http:': '80',
|
|
209
|
+
};
|
|
210
|
+
function serverPortFromUrl(url) {
|
|
211
|
+
const serverPort = Number(url.port || HTTP_PORT_FROM_PROTOCOL[url.protocol]);
|
|
212
|
+
// Guard with `if (serverPort)` because `Number('') === 0`.
|
|
213
|
+
if (serverPort && !isNaN(serverPort)) {
|
|
214
|
+
return serverPort;
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
return undefined;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
exports.serverPortFromUrl = serverPortFromUrl;
|
|
163
221
|
//# sourceMappingURL=utils.js.map
|
package/build/src/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,6GAA6G;AAC7G,sCAAsC;AAEtC,0CAA0C;AAE1C,MAAM,WAAW,GAAG,GAAG,CAAC,IAAI,CAAC,qBAAqB,CAAC;IACjD,SAAS,EAAE,0DAA0D;CACtE,CAAC,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,SAAgB,kBAAkB,CAAC,GAAG,IAA8B;IAClE,IAAI,IAAI,CAAC,CAAC,CAAC,YAAY,GAAG,IAAI,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ,EAAE;QACzD,MAAM,WAAW,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAC5B,IAAI,CAAC,WAAW,EAAE,IAAI,EAAE;YACtB,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;SAC1B;QACD,IAAI,WAAW,CAAC,IAAI,YAAY,cAAc,EAAE;YA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AM,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC;AAC3C,CAAC;AAED,SAAS,eAAe,CAAC,QAAkB;IACzC,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,QAAQ,CAAC,OAAO,EAAE,EAAE;QAC7C,IAAI,IAAI,GAAG,CAAC,MAAM,CAAC;QACnB,IAAI,KAAK,YAAY,IAAI,EAAE;YACzB,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC;SACpB;aAAM;YACL,IAAI,IAAI,KAAK,CAAC,MAAM,CAAC;SACtB;KACF;IACD,OAAO,IAAI,CAAC;AACd,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// Much of the logic here overlaps with the same utils file in opentelemetry-instrumentation-xml-http-request\n// These may be unified in the future.\n\nimport * as api from '@opentelemetry/api';\n\nconst DIAG_LOGGER = api.diag.createComponentLogger({\n namespace: '@opentelemetry/opentelemetry-instrumentation-fetch/utils',\n});\n\n/**\n * Helper function to determine payload content length for fetch requests\n *\n * The fetch API is kinda messy: there are a couple of ways the body can be passed in.\n *\n * In all cases, the body param can be some variation of ReadableStream,\n * and ReadableStreams can only be read once! We want to avoid consuming the body here,\n * because that would mean that the body never gets sent with the actual fetch request.\n *\n * Either the first arg is a Request object, which can be cloned\n * so we can clone that object and read the body of the clone\n * without disturbing the original argument\n * However, reading the body here can only be done async; the body() method returns a promise\n * this means this entire function has to return a promise\n *\n * OR the first arg is a url/string\n * in which case the second arg has type RequestInit\n * RequestInit is NOT cloneable, but RequestInit.body is writable\n * so we can chain it into ReadableStream.pipeThrough()\n *\n * ReadableStream.pipeThrough() lets us process a stream and returns a new stream\n * So we can measure the body length as it passes through the pie, but need to attach\n * the new stream to the original request\n * so that the browser still has access to the body.\n *\n * @param body\n * @returns promise that resolves to the content length of the body\n */\nexport function getFetchBodyLength(...args: Parameters<typeof fetch>) {\n if (args[0] instanceof URL || typeof args[0] === 'string') {\n const requestInit = args[1];\n if (!requestInit?.body) {\n return Promise.resolve();\n }\n if (requestInit.body instanceof ReadableStream) {\n const { body, length } = _getBodyNonDestructively(requestInit.body);\n requestInit.body = body;\n\n return length;\n } else {\n return Promise.resolve(getXHRBodyLength(requestInit.body));\n }\n } else {\n const info = args[0];\n if (!info?.body) {\n return Promise.resolve();\n }\n\n return info\n .clone()\n .text()\n .then(t => getByteLength(t));\n }\n}\n\nfunction _getBodyNonDestructively(body: ReadableStream) {\n // can't read a ReadableStream without destroying it\n // but we CAN pipe it through and return a new ReadableStream\n\n // some (older) platforms don't expose the pipeThrough method and in that scenario, we're out of luck;\n // there's no way to read the stream without consuming it.\n if (!body.pipeThrough) {\n DIAG_LOGGER.warn('Platform has ReadableStream but not pipeThrough!');\n return {\n body,\n length: Promise.resolve(undefined),\n };\n }\n\n let length = 0;\n let resolveLength: (l: number) => void;\n const lengthPromise = new Promise<number>(resolve => {\n resolveLength = resolve;\n });\n\n const transform = new TransformStream({\n start() {},\n async transform(chunk, controller) {\n const bytearray = (await chunk) as Uint8Array;\n length += bytearray.byteLength;\n\n controller.enqueue(chunk);\n },\n flush() {\n resolveLength(length);\n },\n });\n\n return {\n body: body.pipeThrough(transform),\n length: lengthPromise,\n };\n}\n\nfunction isDocument(value: unknown): value is Document {\n return typeof Document !== 'undefined' && value instanceof Document;\n}\n\n/**\n * Helper function to determine payload content length for XHR requests\n * @param body\n * @returns content length\n */\nexport function getXHRBodyLength(\n body: Document | XMLHttpRequestBodyInit\n): number | undefined {\n if (isDocument(body)) {\n return new XMLSerializer().serializeToString(document).length;\n }\n\n // XMLHttpRequestBodyInit expands to the following:\n if (typeof body === 'string') {\n return getByteLength(body);\n }\n\n if (body instanceof Blob) {\n return body.size;\n }\n\n if (body instanceof FormData) {\n return getFormDataSize(body);\n }\n\n if (body instanceof URLSearchParams) {\n return getByteLength(body.toString());\n }\n\n // ArrayBuffer | ArrayBufferView\n if (body.byteLength !== undefined) {\n return body.byteLength;\n }\n\n DIAG_LOGGER.warn('unknown body type');\n return undefined;\n}\n\nconst TEXT_ENCODER = new TextEncoder();\nfunction getByteLength(s: string): number {\n return TEXT_ENCODER.encode(s).byteLength;\n}\n\nfunction getFormDataSize(formData: FormData): number {\n let size = 0;\n for (const [key, value] of formData.entries()) {\n size += key.length;\n if (value instanceof Blob) {\n size += value.size;\n } else {\n size += value.length;\n }\n }\n return size;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,6GAA6G;AAC7G,sCAAsC;AAEtC,0CAA0C;AAC1C,8CAA2D;AAG3D,MAAM,WAAW,GAAG,GAAG,CAAC,IAAI,CAAC,qBAAqB,CAAC;IACjD,SAAS,EAAE,0DAA0D;CACtE,CAAC,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,SAAgB,kBAAkB,CAAC,GAAG,IAA8B;IAClE,IAAI,IAAI,CAAC,CAAC,CAAC,YAAY,GAAG,IAAI,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ,EAAE;QACzD,MAAM,WAAW,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAC5B,IAAI,CAAC,WAAW,EAAE,IAAI,EAAE;YACtB,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;SAC1B;QACD,IAAI,WAAW,CAAC,IAAI,YAAY,cAAc,EAAE;YAC9C,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,wBAAwB,CAAC,WA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ACJ;aAAM;YACL,YAAY,GAAG,qBAAqB,CAAC;SACtC;KACF;IACD,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,MAAM,uBAAuB,GAA8B;IACzD,QAAQ,EAAE,KAAK;IACf,OAAO,EAAE,IAAI;CACd,CAAC;AACF,SAAgB,iBAAiB,CAAC,GAAY;IAC5C,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,IAAI,uBAAuB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC7E,2DAA2D;IAC3D,IAAI,UAAU,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE;QACpC,OAAO,UAAU,CAAC;KACnB;SAAM;QACL,OAAO,SAAS,CAAC;KAClB;AACH,CAAC;AARD,8CAQC","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// Much of the logic here overlaps with the same utils file in opentelemetry-instrumentation-xml-http-request\n// These may be unified in the future.\n\nimport * as api from '@opentelemetry/api';\nimport { getStringListFromEnv } from '@opentelemetry/core';\nimport { URLLike } from '@opentelemetry/sdk-trace-web';\n\nconst DIAG_LOGGER = api.diag.createComponentLogger({\n namespace: '@opentelemetry/opentelemetry-instrumentation-fetch/utils',\n});\n\n/**\n * Helper function to determine payload content length for fetch requests\n *\n * The fetch API is kinda messy: there are a couple of ways the body can be passed in.\n *\n * In all cases, the body param can be some variation of ReadableStream,\n * and ReadableStreams can only be read once! We want to avoid consuming the body here,\n * because that would mean that the body never gets sent with the actual fetch request.\n *\n * Either the first arg is a Request object, which can be cloned\n * so we can clone that object and read the body of the clone\n * without disturbing the original argument\n * However, reading the body here can only be done async; the body() method returns a promise\n * this means this entire function has to return a promise\n *\n * OR the first arg is a url/string\n * in which case the second arg has type RequestInit\n * RequestInit is NOT cloneable, but RequestInit.body is writable\n * so we can chain it into ReadableStream.pipeThrough()\n *\n * ReadableStream.pipeThrough() lets us process a stream and returns a new stream\n * So we can measure the body length as it passes through the pie, but need to attach\n * the new stream to the original request\n * so that the browser still has access to the body.\n *\n * @param body\n * @returns promise that resolves to the content length of the body\n */\nexport function getFetchBodyLength(...args: Parameters<typeof fetch>) {\n if (args[0] instanceof URL || typeof args[0] === 'string') {\n const requestInit = args[1];\n if (!requestInit?.body) {\n return Promise.resolve();\n }\n if (requestInit.body instanceof ReadableStream) {\n const { body, length } = _getBodyNonDestructively(requestInit.body);\n requestInit.body = body;\n\n return length;\n } else {\n return Promise.resolve(getXHRBodyLength(requestInit.body));\n }\n } else {\n const info = args[0];\n if (!info?.body) {\n return Promise.resolve();\n }\n\n return info\n .clone()\n .text()\n .then(t => getByteLength(t));\n }\n}\n\nfunction _getBodyNonDestructively(body: ReadableStream) {\n // can't read a ReadableStream without destroying it\n // but we CAN pipe it through and return a new ReadableStream\n\n // some (older) platforms don't expose the pipeThrough method and in that scenario, we're out of luck;\n // there's no way to read the stream without consuming it.\n if (!body.pipeThrough) {\n DIAG_LOGGER.warn('Platform has ReadableStream but not pipeThrough!');\n return {\n body,\n length: Promise.resolve(undefined),\n };\n }\n\n let length = 0;\n let resolveLength: (l: number) => void;\n const lengthPromise = new Promise<number>(resolve => {\n resolveLength = resolve;\n });\n\n const transform = new TransformStream({\n start() {},\n async transform(chunk, controller) {\n const bytearray = (await chunk) as Uint8Array;\n length += bytearray.byteLength;\n\n controller.enqueue(chunk);\n },\n flush() {\n resolveLength(length);\n },\n });\n\n return {\n body: body.pipeThrough(transform),\n length: lengthPromise,\n };\n}\n\nfunction isDocument(value: unknown): value is Document {\n return typeof Document !== 'undefined' && value instanceof Document;\n}\n\n/**\n * Helper function to determine payload content length for XHR requests\n * @param body\n * @returns content length\n */\nexport function getXHRBodyLength(\n body: Document | XMLHttpRequestBodyInit\n): number | undefined {\n if (isDocument(body)) {\n return new XMLSerializer().serializeToString(document).length;\n }\n\n // XMLHttpRequestBodyInit expands to the following:\n if (typeof body === 'string') {\n return getByteLength(body);\n }\n\n if (body instanceof Blob) {\n return body.size;\n }\n\n if (body instanceof FormData) {\n return getFormDataSize(body);\n }\n\n if (body instanceof URLSearchParams) {\n return getByteLength(body.toString());\n }\n\n // ArrayBuffer | ArrayBufferView\n if (body.byteLength !== undefined) {\n return body.byteLength;\n }\n\n DIAG_LOGGER.warn('unknown body type');\n return undefined;\n}\n\nconst TEXT_ENCODER = new TextEncoder();\nfunction getByteLength(s: string): number {\n return TEXT_ENCODER.encode(s).byteLength;\n}\n\nfunction getFormDataSize(formData: FormData): number {\n let size = 0;\n for (const [key, value] of formData.entries()) {\n size += key.length;\n if (value instanceof Blob) {\n size += value.size;\n } else {\n size += value.length;\n }\n }\n return size;\n}\n\n/**\n * Normalize an HTTP request method string per `http.request.method` spec\n * https://github.com/open-telemetry/semantic-conventions/blob/main/docs/http/http-spans.md#http-client-span\n */\nexport function normalizeHttpRequestMethod(method: string): string {\n const knownMethods = getKnownMethods();\n const methUpper = method.toUpperCase();\n if (methUpper in knownMethods) {\n return methUpper;\n } else {\n return '_OTHER';\n }\n}\n\nconst DEFAULT_KNOWN_METHODS = {\n CONNECT: true,\n DELETE: true,\n GET: true,\n HEAD: true,\n OPTIONS: true,\n PATCH: true,\n POST: true,\n PUT: true,\n TRACE: true,\n};\nlet knownMethods: { [key: string]: boolean };\nfunction getKnownMethods() {\n if (knownMethods === undefined) {\n const cfgMethods = getStringListFromEnv(\n 'OTEL_INSTRUMENTATION_HTTP_KNOWN_METHODS'\n );\n if (cfgMethods && cfgMethods.length > 0) {\n knownMethods = {};\n cfgMethods.forEach(m => {\n knownMethods[m] = true;\n });\n } else {\n knownMethods = DEFAULT_KNOWN_METHODS;\n }\n }\n return knownMethods;\n}\n\nconst HTTP_PORT_FROM_PROTOCOL: { [key: string]: string } = {\n 'https:': '443',\n 'http:': '80',\n};\nexport function serverPortFromUrl(url: URLLike): number | undefined {\n const serverPort = Number(url.port || HTTP_PORT_FROM_PROTOCOL[url.protocol]);\n // Guard with `if (serverPort)` because `Number('') === 0`.\n if (serverPort && !isNaN(serverPort)) {\n return serverPort;\n } else {\n return undefined;\n }\n}\n"]}
|
package/build/src/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.201.1";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/build/src/version.js
CHANGED
package/build/src/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4DAA4D;AAC/C,QAAA,OAAO,GAAG,SAAS,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.
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4DAA4D;AAC/C,QAAA,OAAO,GAAG,SAAS,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.201.1';\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opentelemetry/instrumentation-fetch",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.201.1",
|
|
4
4
|
"description": "OpenTelemetry instrumentation for fetch http client in web browsers",
|
|
5
5
|
"main": "build/src/index.js",
|
|
6
6
|
"module": "build/esm/index.js",
|
|
@@ -54,12 +54,12 @@
|
|
|
54
54
|
"access": "public"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@babel/core": "7.26.
|
|
57
|
+
"@babel/core": "7.26.10",
|
|
58
58
|
"@babel/preset-env": "7.26.9",
|
|
59
59
|
"@opentelemetry/api": "1.9.0",
|
|
60
|
-
"@opentelemetry/context-zone": "2.0.
|
|
61
|
-
"@opentelemetry/propagator-b3": "2.0.
|
|
62
|
-
"@opentelemetry/sdk-trace-base": "2.0.
|
|
60
|
+
"@opentelemetry/context-zone": "2.0.1",
|
|
61
|
+
"@opentelemetry/propagator-b3": "2.0.1",
|
|
62
|
+
"@opentelemetry/sdk-trace-base": "2.0.1",
|
|
63
63
|
"@types/mocha": "10.0.10",
|
|
64
64
|
"@types/node": "18.6.5",
|
|
65
65
|
"@types/sinon": "17.0.4",
|
|
@@ -80,16 +80,16 @@
|
|
|
80
80
|
"sinon": "15.1.2",
|
|
81
81
|
"ts-loader": "9.5.2",
|
|
82
82
|
"typescript": "5.0.4",
|
|
83
|
-
"webpack": "5.
|
|
83
|
+
"webpack": "5.99.8",
|
|
84
84
|
"webpack-cli": "6.0.1"
|
|
85
85
|
},
|
|
86
86
|
"peerDependencies": {
|
|
87
87
|
"@opentelemetry/api": "^1.3.0"
|
|
88
88
|
},
|
|
89
89
|
"dependencies": {
|
|
90
|
-
"@opentelemetry/core": "2.0.
|
|
91
|
-
"@opentelemetry/instrumentation": "0.
|
|
92
|
-
"@opentelemetry/sdk-trace-web": "2.0.
|
|
90
|
+
"@opentelemetry/core": "2.0.1",
|
|
91
|
+
"@opentelemetry/instrumentation": "0.201.1",
|
|
92
|
+
"@opentelemetry/sdk-trace-web": "2.0.1",
|
|
93
93
|
"@opentelemetry/semantic-conventions": "^1.29.0"
|
|
94
94
|
},
|
|
95
95
|
"homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/opentelemetry-instrumentation-fetch",
|
|
@@ -99,5 +99,5 @@
|
|
|
99
99
|
"test"
|
|
100
100
|
]
|
|
101
101
|
},
|
|
102
|
-
"gitHead": "
|
|
102
|
+
"gitHead": "9dbd1e446be0ecc7c22b00051c5cfb2612d9b0f2"
|
|
103
103
|
}
|