@jaak.ai/stamps 2.2.0-dev.5 → 2.2.0-dev.9
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/dist/cjs/jaak-stamps.cjs.entry.js +592 -3098
- package/dist/cjs/jaak-stamps.cjs.entry.js.map +1 -1
- package/dist/cjs/jaak-stamps.entry.cjs.js.map +1 -1
- package/dist/collection/components/my-component/my-component.js +17 -4
- package/dist/collection/components/my-component/my-component.js.map +1 -1
- package/dist/collection/services/LicenseValidationService.js +2 -2
- package/dist/collection/services/LicenseValidationService.js.map +1 -1
- package/dist/collection/services/TracingService.js +130 -78
- package/dist/collection/services/TracingService.js.map +1 -1
- package/dist/collection/services/interfaces/ITracingService.js.map +1 -1
- package/dist/components/jaak-stamps.js +592 -3098
- package/dist/components/jaak-stamps.js.map +1 -1
- package/dist/esm/jaak-stamps.entry.js +592 -3098
- package/dist/esm/jaak-stamps.entry.js.map +1 -1
- package/dist/jaak-stamps-webcomponent/jaak-stamps-webcomponent.esm.js +1 -1
- package/dist/jaak-stamps-webcomponent/jaak-stamps.entry.esm.js.map +1 -1
- package/dist/jaak-stamps-webcomponent/p-dfecb452.entry.js +7 -0
- package/dist/jaak-stamps-webcomponent/p-dfecb452.entry.js.map +1 -0
- package/dist/types/services/TracingService.d.ts +6 -1
- package/dist/types/services/interfaces/ITracingService.d.ts +5 -0
- package/package.json +1 -1
- package/dist/jaak-stamps-webcomponent/p-8c49893d.entry.js +0 -7
- package/dist/jaak-stamps-webcomponent/p-8c49893d.entry.js.map +0 -1
|
@@ -1178,7 +1178,7 @@ class DetectionService {
|
|
|
1178
1178
|
*/
|
|
1179
1179
|
/** only globals that common to node and browsers are allowed */
|
|
1180
1180
|
// eslint-disable-next-line node/no-unsupported-features/es-builtins, no-undef
|
|
1181
|
-
var _globalThis$
|
|
1181
|
+
var _globalThis$1 = typeof globalThis === 'object'
|
|
1182
1182
|
? globalThis
|
|
1183
1183
|
: typeof self === 'object'
|
|
1184
1184
|
? self
|
|
@@ -1204,7 +1204,7 @@ var _globalThis$2 = typeof globalThis === 'object'
|
|
|
1204
1204
|
* limitations under the License.
|
|
1205
1205
|
*/
|
|
1206
1206
|
// this is autogenerated file, see scripts/version-update.js
|
|
1207
|
-
var VERSION$
|
|
1207
|
+
var VERSION$2 = '1.9.0';
|
|
1208
1208
|
|
|
1209
1209
|
/*
|
|
1210
1210
|
* Copyright The OpenTelemetry Authors
|
|
@@ -1321,7 +1321,7 @@ function _makeCompatibilityCheck(ownVersion) {
|
|
|
1321
1321
|
*
|
|
1322
1322
|
* @param version version of the API requesting an instance of the global API
|
|
1323
1323
|
*/
|
|
1324
|
-
var isCompatible = _makeCompatibilityCheck(VERSION$
|
|
1324
|
+
var isCompatible = _makeCompatibilityCheck(VERSION$2);
|
|
1325
1325
|
|
|
1326
1326
|
/*
|
|
1327
1327
|
* Copyright The OpenTelemetry Authors
|
|
@@ -1338,14 +1338,14 @@ var isCompatible = _makeCompatibilityCheck(VERSION$4);
|
|
|
1338
1338
|
* See the License for the specific language governing permissions and
|
|
1339
1339
|
* limitations under the License.
|
|
1340
1340
|
*/
|
|
1341
|
-
var major = VERSION$
|
|
1341
|
+
var major = VERSION$2.split('.')[0];
|
|
1342
1342
|
var GLOBAL_OPENTELEMETRY_API_KEY = Symbol.for("opentelemetry.js.api." + major);
|
|
1343
|
-
var _global$1 = _globalThis$
|
|
1343
|
+
var _global$1 = _globalThis$1;
|
|
1344
1344
|
function registerGlobal(type, instance, diag, allowOverride) {
|
|
1345
1345
|
var _a;
|
|
1346
1346
|
if (allowOverride === void 0) { allowOverride = false; }
|
|
1347
1347
|
var api = (_global$1[GLOBAL_OPENTELEMETRY_API_KEY] = (_a = _global$1[GLOBAL_OPENTELEMETRY_API_KEY]) !== null && _a !== void 0 ? _a : {
|
|
1348
|
-
version: VERSION$
|
|
1348
|
+
version: VERSION$2,
|
|
1349
1349
|
});
|
|
1350
1350
|
if (!allowOverride && api[type]) {
|
|
1351
1351
|
// already registered an API of this type
|
|
@@ -1353,14 +1353,14 @@ function registerGlobal(type, instance, diag, allowOverride) {
|
|
|
1353
1353
|
diag.error(err.stack || err.message);
|
|
1354
1354
|
return false;
|
|
1355
1355
|
}
|
|
1356
|
-
if (api.version !== VERSION$
|
|
1356
|
+
if (api.version !== VERSION$2) {
|
|
1357
1357
|
// All registered APIs must be of the same version exactly
|
|
1358
|
-
var err = new Error("@opentelemetry/api: Registration of version v" + api.version + " for " + type + " does not match previously registered API v" + VERSION$
|
|
1358
|
+
var err = new Error("@opentelemetry/api: Registration of version v" + api.version + " for " + type + " does not match previously registered API v" + VERSION$2);
|
|
1359
1359
|
diag.error(err.stack || err.message);
|
|
1360
1360
|
return false;
|
|
1361
1361
|
}
|
|
1362
1362
|
api[type] = instance;
|
|
1363
|
-
diag.debug("@opentelemetry/api: Registered a global for " + type + " v" + VERSION$
|
|
1363
|
+
diag.debug("@opentelemetry/api: Registered a global for " + type + " v" + VERSION$2 + ".");
|
|
1364
1364
|
return true;
|
|
1365
1365
|
}
|
|
1366
1366
|
function getGlobal(type) {
|
|
@@ -1372,7 +1372,7 @@ function getGlobal(type) {
|
|
|
1372
1372
|
return (_b = _global$1[GLOBAL_OPENTELEMETRY_API_KEY]) === null || _b === void 0 ? void 0 : _b[type];
|
|
1373
1373
|
}
|
|
1374
1374
|
function unregisterGlobal(type, diag) {
|
|
1375
|
-
diag.debug("@opentelemetry/api: Unregistering a global for " + type + " v" + VERSION$
|
|
1375
|
+
diag.debug("@opentelemetry/api: Unregistering a global for " + type + " v" + VERSION$2 + ".");
|
|
1376
1376
|
var api = _global$1[GLOBAL_OPENTELEMETRY_API_KEY];
|
|
1377
1377
|
if (api) {
|
|
1378
1378
|
delete api[type];
|
|
@@ -3608,41 +3608,6 @@ function getNumberFromEnv(_) {
|
|
|
3608
3608
|
return undefined;
|
|
3609
3609
|
}
|
|
3610
3610
|
|
|
3611
|
-
/*
|
|
3612
|
-
* Copyright The OpenTelemetry Authors
|
|
3613
|
-
*
|
|
3614
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
3615
|
-
* you may not use this file except in compliance with the License.
|
|
3616
|
-
* You may obtain a copy of the License at
|
|
3617
|
-
*
|
|
3618
|
-
* https://www.apache.org/licenses/LICENSE-2.0
|
|
3619
|
-
*
|
|
3620
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
3621
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
3622
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
3623
|
-
* See the License for the specific language governing permissions and
|
|
3624
|
-
* limitations under the License.
|
|
3625
|
-
*/
|
|
3626
|
-
// Updates to this file should also be replicated to @opentelemetry/api too.
|
|
3627
|
-
/**
|
|
3628
|
-
* - globalThis (New standard)
|
|
3629
|
-
* - self (Will return the current window instance for supported browsers)
|
|
3630
|
-
* - window (fallback for older browser implementations)
|
|
3631
|
-
* - global (NodeJS implementation)
|
|
3632
|
-
* - <object> (When all else fails)
|
|
3633
|
-
*/
|
|
3634
|
-
/** only globals that common to node and browsers are allowed */
|
|
3635
|
-
// eslint-disable-next-line n/no-unsupported-features/es-builtins, no-undef
|
|
3636
|
-
const _globalThis$1 = typeof globalThis === 'object'
|
|
3637
|
-
? globalThis
|
|
3638
|
-
: typeof self === 'object'
|
|
3639
|
-
? self
|
|
3640
|
-
: typeof window === 'object'
|
|
3641
|
-
? window
|
|
3642
|
-
: typeof global === 'object'
|
|
3643
|
-
? global
|
|
3644
|
-
: {};
|
|
3645
|
-
|
|
3646
3611
|
/*
|
|
3647
3612
|
* Copyright The OpenTelemetry Authors
|
|
3648
3613
|
*
|
|
@@ -3676,7 +3641,7 @@ const otperformance = performance;
|
|
|
3676
3641
|
* limitations under the License.
|
|
3677
3642
|
*/
|
|
3678
3643
|
// this is autogenerated file, see scripts/version-update.js
|
|
3679
|
-
const VERSION$
|
|
3644
|
+
const VERSION$1 = '2.2.0';
|
|
3680
3645
|
|
|
3681
3646
|
/*
|
|
3682
3647
|
* Copyright The OpenTelemetry Authors
|
|
@@ -3702,35 +3667,6 @@ const VERSION$3 = '2.2.0';
|
|
|
3702
3667
|
* @example handled
|
|
3703
3668
|
* @example unhandled
|
|
3704
3669
|
*/
|
|
3705
|
-
/**
|
|
3706
|
-
* Describes a class of error the operation ended with.
|
|
3707
|
-
*
|
|
3708
|
-
* @example timeout
|
|
3709
|
-
* @example java.net.UnknownHostException
|
|
3710
|
-
* @example server_certificate_invalid
|
|
3711
|
-
* @example 500
|
|
3712
|
-
*
|
|
3713
|
-
* @note The `error.type` **SHOULD** be predictable, and **SHOULD** have low cardinality.
|
|
3714
|
-
*
|
|
3715
|
-
* When `error.type` is set to a type (e.g., an exception type), its
|
|
3716
|
-
* canonical class name identifying the type within the artifact **SHOULD** be used.
|
|
3717
|
-
*
|
|
3718
|
-
* Instrumentations **SHOULD** document the list of errors they report.
|
|
3719
|
-
*
|
|
3720
|
-
* The cardinality of `error.type` within one instrumentation library **SHOULD** be low.
|
|
3721
|
-
* Telemetry consumers that aggregate data from multiple instrumentation libraries and applications
|
|
3722
|
-
* should be prepared for `error.type` to have high cardinality at query time when no
|
|
3723
|
-
* additional filters are applied.
|
|
3724
|
-
*
|
|
3725
|
-
* If the operation has completed successfully, instrumentations **SHOULD NOT** set `error.type`.
|
|
3726
|
-
*
|
|
3727
|
-
* If a specific domain defines its own set of error identifiers (such as HTTP or gRPC status codes),
|
|
3728
|
-
* it's **RECOMMENDED** to:
|
|
3729
|
-
*
|
|
3730
|
-
* - Use a domain-specific attribute
|
|
3731
|
-
* - Set `error.type` to capture all errors, regardless of whether they are defined within the domain-specific set or not.
|
|
3732
|
-
*/
|
|
3733
|
-
const ATTR_ERROR_TYPE = 'error.type';
|
|
3734
3670
|
/**
|
|
3735
3671
|
* The exception message.
|
|
3736
3672
|
*
|
|
@@ -3751,64 +3687,6 @@ const ATTR_EXCEPTION_STACKTRACE = 'exception.stacktrace';
|
|
|
3751
3687
|
* @example OSError
|
|
3752
3688
|
*/
|
|
3753
3689
|
const ATTR_EXCEPTION_TYPE = 'exception.type';
|
|
3754
|
-
/**
|
|
3755
|
-
* HTTP request method.
|
|
3756
|
-
*
|
|
3757
|
-
* @example GET
|
|
3758
|
-
* @example POST
|
|
3759
|
-
* @example HEAD
|
|
3760
|
-
*
|
|
3761
|
-
* @note HTTP request method value **SHOULD** be "known" to the instrumentation.
|
|
3762
|
-
* By default, this convention defines "known" methods as the ones listed in [RFC9110](https://www.rfc-editor.org/rfc/rfc9110.html#name-methods),
|
|
3763
|
-
* the PATCH method defined in [RFC5789](https://www.rfc-editor.org/rfc/rfc5789.html)
|
|
3764
|
-
* and the QUERY method defined in [httpbis-safe-method-w-body](https://datatracker.ietf.org/doc/draft-ietf-httpbis-safe-method-w-body/?include_text=1).
|
|
3765
|
-
*
|
|
3766
|
-
* If the HTTP request method is not known to instrumentation, it **MUST** set the `http.request.method` attribute to `_OTHER`.
|
|
3767
|
-
*
|
|
3768
|
-
* If the HTTP instrumentation could end up converting valid HTTP request methods to `_OTHER`, then it **MUST** provide a way to override
|
|
3769
|
-
* the list of known HTTP methods. If this override is done via environment variable, then the environment variable **MUST** be named
|
|
3770
|
-
* OTEL_INSTRUMENTATION_HTTP_KNOWN_METHODS and support a comma-separated list of case-sensitive known HTTP methods
|
|
3771
|
-
* (this list **MUST** be a full override of the default known method, it is not a list of known methods in addition to the defaults).
|
|
3772
|
-
*
|
|
3773
|
-
* HTTP method names are case-sensitive and `http.request.method` attribute value **MUST** match a known HTTP method name exactly.
|
|
3774
|
-
* Instrumentations for specific web frameworks that consider HTTP methods to be case insensitive, **SHOULD** populate a canonical equivalent.
|
|
3775
|
-
* Tracing instrumentations that do so, **MUST** also set `http.request.method_original` to the original value.
|
|
3776
|
-
*/
|
|
3777
|
-
const ATTR_HTTP_REQUEST_METHOD = 'http.request.method';
|
|
3778
|
-
/**
|
|
3779
|
-
* Original HTTP method sent by the client in the request line.
|
|
3780
|
-
*
|
|
3781
|
-
* @example GeT
|
|
3782
|
-
* @example ACL
|
|
3783
|
-
* @example foo
|
|
3784
|
-
*/
|
|
3785
|
-
const ATTR_HTTP_REQUEST_METHOD_ORIGINAL = 'http.request.method_original';
|
|
3786
|
-
/**
|
|
3787
|
-
* [HTTP response status code](https://tools.ietf.org/html/rfc7231#section-6).
|
|
3788
|
-
*
|
|
3789
|
-
* @example 200
|
|
3790
|
-
*/
|
|
3791
|
-
const ATTR_HTTP_RESPONSE_STATUS_CODE = 'http.response.status_code';
|
|
3792
|
-
/**
|
|
3793
|
-
* Server domain name if available without reverse DNS lookup; otherwise, IP address or Unix domain socket name.
|
|
3794
|
-
*
|
|
3795
|
-
* @example example.com
|
|
3796
|
-
* @example 10.1.2.80
|
|
3797
|
-
* @example /tmp/my.sock
|
|
3798
|
-
*
|
|
3799
|
-
* @note When observed from the client side, and when communicating through an intermediary, `server.address` **SHOULD** represent the server address behind any intermediaries, for example proxies, if it's available.
|
|
3800
|
-
*/
|
|
3801
|
-
const ATTR_SERVER_ADDRESS = 'server.address';
|
|
3802
|
-
/**
|
|
3803
|
-
* Server port number.
|
|
3804
|
-
*
|
|
3805
|
-
* @example 80
|
|
3806
|
-
* @example 8080
|
|
3807
|
-
* @example 443
|
|
3808
|
-
*
|
|
3809
|
-
* @note When observed from the client side, and when communicating through an intermediary, `server.port` **SHOULD** represent the server port behind any intermediaries, for example proxies, if it's available.
|
|
3810
|
-
*/
|
|
3811
|
-
const ATTR_SERVER_PORT = 'server.port';
|
|
3812
3690
|
/**
|
|
3813
3691
|
* Logical name of the service.
|
|
3814
3692
|
*
|
|
@@ -3844,45 +3722,6 @@ const ATTR_TELEMETRY_SDK_NAME = 'telemetry.sdk.name';
|
|
|
3844
3722
|
* @example 1.2.3
|
|
3845
3723
|
*/
|
|
3846
3724
|
const ATTR_TELEMETRY_SDK_VERSION = 'telemetry.sdk.version';
|
|
3847
|
-
/**
|
|
3848
|
-
* Absolute URL describing a network resource according to [RFC3986](https://www.rfc-editor.org/rfc/rfc3986)
|
|
3849
|
-
*
|
|
3850
|
-
* @example https://www.foo.bar/search?q=OpenTelemetry#SemConv
|
|
3851
|
-
* @example //localhost
|
|
3852
|
-
*
|
|
3853
|
-
* @note For network calls, URL usually has `scheme://host[:port][path][?query][#fragment]` format, where the fragment
|
|
3854
|
-
* is not transmitted over HTTP, but if it is known, it **SHOULD** be included nevertheless.
|
|
3855
|
-
*
|
|
3856
|
-
* `url.full` **MUST NOT** contain credentials passed via URL in form of `https://username:password@www.example.com/`.
|
|
3857
|
-
* In such case username and password **SHOULD** be redacted and attribute's value **SHOULD** be `https://REDACTED:REDACTED@www.example.com/`.
|
|
3858
|
-
*
|
|
3859
|
-
* `url.full` **SHOULD** capture the absolute URL when it is available (or can be reconstructed).
|
|
3860
|
-
*
|
|
3861
|
-
* Sensitive content provided in `url.full` **SHOULD** be scrubbed when instrumentations can identify it.
|
|
3862
|
-
*
|
|
3863
|
-
*
|
|
3864
|
-
* Query string values for the following keys **SHOULD** be redacted by default and replaced by the
|
|
3865
|
-
* value `REDACTED`:
|
|
3866
|
-
*
|
|
3867
|
-
* - [`AWSAccessKeyId`](https://docs.aws.amazon.com/AmazonS3/latest/userguide/RESTAuthentication.html#RESTAuthenticationQueryStringAuth)
|
|
3868
|
-
* - [`Signature`](https://docs.aws.amazon.com/AmazonS3/latest/userguide/RESTAuthentication.html#RESTAuthenticationQueryStringAuth)
|
|
3869
|
-
* - [`sig`](https://learn.microsoft.com/azure/storage/common/storage-sas-overview#sas-token)
|
|
3870
|
-
* - [`X-Goog-Signature`](https://cloud.google.com/storage/docs/access-control/signed-urls)
|
|
3871
|
-
*
|
|
3872
|
-
* This list is subject to change over time.
|
|
3873
|
-
*
|
|
3874
|
-
* When a query string value is redacted, the query string key **SHOULD** still be preserved, e.g.
|
|
3875
|
-
* `https://www.example.com/path?color=blue&sig=REDACTED`.
|
|
3876
|
-
*/
|
|
3877
|
-
const ATTR_URL_FULL = 'url.full';
|
|
3878
|
-
/**
|
|
3879
|
-
* Value of the [HTTP User-Agent](https://www.rfc-editor.org/rfc/rfc9110.html#field.user-agent) header sent by the client.
|
|
3880
|
-
*
|
|
3881
|
-
* @example CERN-LineMode/2.15 libwww/2.17b3
|
|
3882
|
-
* @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
|
|
3883
|
-
* @example YourApp/1.0.0 grpc-java-okhttp/1.27.2
|
|
3884
|
-
*/
|
|
3885
|
-
const ATTR_USER_AGENT_ORIGINAL = 'user_agent.original';
|
|
3886
3725
|
|
|
3887
3726
|
/*
|
|
3888
3727
|
* Copyright The OpenTelemetry Authors
|
|
@@ -3933,7 +3772,7 @@ const SDK_INFO = {
|
|
|
3933
3772
|
[ATTR_TELEMETRY_SDK_NAME]: 'opentelemetry',
|
|
3934
3773
|
[ATTR_PROCESS_RUNTIME_NAME]: 'browser',
|
|
3935
3774
|
[ATTR_TELEMETRY_SDK_LANGUAGE]: TELEMETRY_SDK_LANGUAGE_VALUE_WEBJS,
|
|
3936
|
-
[ATTR_TELEMETRY_SDK_VERSION]: VERSION$
|
|
3775
|
+
[ATTR_TELEMETRY_SDK_VERSION]: VERSION$1,
|
|
3937
3776
|
};
|
|
3938
3777
|
|
|
3939
3778
|
/*
|
|
@@ -3984,33 +3823,6 @@ function hrTime(performanceNow) {
|
|
|
3984
3823
|
const now = millisToHrTime(typeof performanceNow === 'number' ? performanceNow : otperformance.now());
|
|
3985
3824
|
return addHrTimes(timeOrigin, now);
|
|
3986
3825
|
}
|
|
3987
|
-
/**
|
|
3988
|
-
*
|
|
3989
|
-
* Converts a TimeInput to an HrTime, defaults to _hrtime().
|
|
3990
|
-
* @param time
|
|
3991
|
-
*/
|
|
3992
|
-
function timeInputToHrTime(time) {
|
|
3993
|
-
// process.hrtime
|
|
3994
|
-
if (isTimeInputHrTime(time)) {
|
|
3995
|
-
return time;
|
|
3996
|
-
}
|
|
3997
|
-
else if (typeof time === 'number') {
|
|
3998
|
-
// Must be a performance.now() if it's smaller than process start time.
|
|
3999
|
-
if (time < getTimeOrigin()) {
|
|
4000
|
-
return hrTime(time);
|
|
4001
|
-
}
|
|
4002
|
-
else {
|
|
4003
|
-
// epoch milliseconds or performance.timeOrigin
|
|
4004
|
-
return millisToHrTime(time);
|
|
4005
|
-
}
|
|
4006
|
-
}
|
|
4007
|
-
else if (time instanceof Date) {
|
|
4008
|
-
return millisToHrTime(time.getTime());
|
|
4009
|
-
}
|
|
4010
|
-
else {
|
|
4011
|
-
throw TypeError('Invalid input type');
|
|
4012
|
-
}
|
|
4013
|
-
}
|
|
4014
3826
|
/**
|
|
4015
3827
|
* Returns a duration of two hrTime.
|
|
4016
3828
|
* @param startTime
|
|
@@ -4323,7 +4135,7 @@ class TraceState {
|
|
|
4323
4135
|
*/
|
|
4324
4136
|
const TRACE_PARENT_HEADER = 'traceparent';
|
|
4325
4137
|
const TRACE_STATE_HEADER = 'tracestate';
|
|
4326
|
-
const VERSION
|
|
4138
|
+
const VERSION = '00';
|
|
4327
4139
|
const VERSION_PART = '(?!ff)[\\da-f]{2}';
|
|
4328
4140
|
const TRACE_ID_PART = '(?![0]{32})[\\da-f]{32}';
|
|
4329
4141
|
const PARENT_ID_PART = '(?![0]{16})[\\da-f]{16}';
|
|
@@ -4367,7 +4179,7 @@ class W3CTraceContextPropagator {
|
|
|
4367
4179
|
isTracingSuppressed(context) ||
|
|
4368
4180
|
!isSpanContextValid(spanContext))
|
|
4369
4181
|
return;
|
|
4370
|
-
const traceParent = `${VERSION
|
|
4182
|
+
const traceParent = `${VERSION}-${spanContext.traceId}-${spanContext.spanId}-0${Number(spanContext.traceFlags || TraceFlags.NONE).toString(16)}`;
|
|
4371
4183
|
setter.set(carrier, TRACE_PARENT_HEADER, traceParent);
|
|
4372
4184
|
if (spanContext.traceState) {
|
|
4373
4185
|
setter.set(carrier, TRACE_STATE_HEADER, spanContext.traceState.serialize());
|
|
@@ -4712,46 +4524,6 @@ function shouldMerge(one, two) {
|
|
|
4712
4524
|
return true;
|
|
4713
4525
|
}
|
|
4714
4526
|
|
|
4715
|
-
/*
|
|
4716
|
-
* Copyright The OpenTelemetry Authors
|
|
4717
|
-
*
|
|
4718
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4719
|
-
* you may not use this file except in compliance with the License.
|
|
4720
|
-
* You may obtain a copy of the License at
|
|
4721
|
-
*
|
|
4722
|
-
* https://www.apache.org/licenses/LICENSE-2.0
|
|
4723
|
-
*
|
|
4724
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
4725
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
4726
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
4727
|
-
* See the License for the specific language governing permissions and
|
|
4728
|
-
* limitations under the License.
|
|
4729
|
-
*/
|
|
4730
|
-
function urlMatches(url, urlToMatch) {
|
|
4731
|
-
if (typeof urlToMatch === 'string') {
|
|
4732
|
-
return url === urlToMatch;
|
|
4733
|
-
}
|
|
4734
|
-
else {
|
|
4735
|
-
return !!url.match(urlToMatch);
|
|
4736
|
-
}
|
|
4737
|
-
}
|
|
4738
|
-
/**
|
|
4739
|
-
* Check if {@param url} should be ignored when comparing against {@param ignoredUrls}
|
|
4740
|
-
* @param url
|
|
4741
|
-
* @param ignoredUrls
|
|
4742
|
-
*/
|
|
4743
|
-
function isUrlIgnored(url, ignoredUrls) {
|
|
4744
|
-
if (!ignoredUrls) {
|
|
4745
|
-
return false;
|
|
4746
|
-
}
|
|
4747
|
-
for (const ignoreUrl of ignoredUrls) {
|
|
4748
|
-
if (urlMatches(url, ignoreUrl)) {
|
|
4749
|
-
return true;
|
|
4750
|
-
}
|
|
4751
|
-
}
|
|
4752
|
-
return false;
|
|
4753
|
-
}
|
|
4754
|
-
|
|
4755
4527
|
/*
|
|
4756
4528
|
* Copyright The OpenTelemetry Authors
|
|
4757
4529
|
*
|
|
@@ -6555,288 +6327,6 @@ class WebTracerProvider extends BasicTracerProvider {
|
|
|
6555
6327
|
* See the License for the specific language governing permissions and
|
|
6556
6328
|
* limitations under the License.
|
|
6557
6329
|
*/
|
|
6558
|
-
var PerformanceTimingNames;
|
|
6559
|
-
(function (PerformanceTimingNames) {
|
|
6560
|
-
PerformanceTimingNames["CONNECT_END"] = "connectEnd";
|
|
6561
|
-
PerformanceTimingNames["CONNECT_START"] = "connectStart";
|
|
6562
|
-
PerformanceTimingNames["DECODED_BODY_SIZE"] = "decodedBodySize";
|
|
6563
|
-
PerformanceTimingNames["DOM_COMPLETE"] = "domComplete";
|
|
6564
|
-
PerformanceTimingNames["DOM_CONTENT_LOADED_EVENT_END"] = "domContentLoadedEventEnd";
|
|
6565
|
-
PerformanceTimingNames["DOM_CONTENT_LOADED_EVENT_START"] = "domContentLoadedEventStart";
|
|
6566
|
-
PerformanceTimingNames["DOM_INTERACTIVE"] = "domInteractive";
|
|
6567
|
-
PerformanceTimingNames["DOMAIN_LOOKUP_END"] = "domainLookupEnd";
|
|
6568
|
-
PerformanceTimingNames["DOMAIN_LOOKUP_START"] = "domainLookupStart";
|
|
6569
|
-
PerformanceTimingNames["ENCODED_BODY_SIZE"] = "encodedBodySize";
|
|
6570
|
-
PerformanceTimingNames["FETCH_START"] = "fetchStart";
|
|
6571
|
-
PerformanceTimingNames["LOAD_EVENT_END"] = "loadEventEnd";
|
|
6572
|
-
PerformanceTimingNames["LOAD_EVENT_START"] = "loadEventStart";
|
|
6573
|
-
PerformanceTimingNames["NAVIGATION_START"] = "navigationStart";
|
|
6574
|
-
PerformanceTimingNames["REDIRECT_END"] = "redirectEnd";
|
|
6575
|
-
PerformanceTimingNames["REDIRECT_START"] = "redirectStart";
|
|
6576
|
-
PerformanceTimingNames["REQUEST_START"] = "requestStart";
|
|
6577
|
-
PerformanceTimingNames["RESPONSE_END"] = "responseEnd";
|
|
6578
|
-
PerformanceTimingNames["RESPONSE_START"] = "responseStart";
|
|
6579
|
-
PerformanceTimingNames["SECURE_CONNECTION_START"] = "secureConnectionStart";
|
|
6580
|
-
PerformanceTimingNames["START_TIME"] = "startTime";
|
|
6581
|
-
PerformanceTimingNames["UNLOAD_EVENT_END"] = "unloadEventEnd";
|
|
6582
|
-
PerformanceTimingNames["UNLOAD_EVENT_START"] = "unloadEventStart";
|
|
6583
|
-
})(PerformanceTimingNames || (PerformanceTimingNames = {}));
|
|
6584
|
-
|
|
6585
|
-
/*
|
|
6586
|
-
* Copyright The OpenTelemetry Authors
|
|
6587
|
-
*
|
|
6588
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6589
|
-
* you may not use this file except in compliance with the License.
|
|
6590
|
-
* You may obtain a copy of the License at
|
|
6591
|
-
*
|
|
6592
|
-
* https://www.apache.org/licenses/LICENSE-2.0
|
|
6593
|
-
*
|
|
6594
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
6595
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
6596
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
6597
|
-
* See the License for the specific language governing permissions and
|
|
6598
|
-
* limitations under the License.
|
|
6599
|
-
*/
|
|
6600
|
-
/*
|
|
6601
|
-
* This file contains a copy of unstable semantic convention definitions
|
|
6602
|
-
* used by this package.
|
|
6603
|
-
* @see https://github.com/open-telemetry/opentelemetry-js/tree/main/semantic-conventions#unstable-semconv
|
|
6604
|
-
*/
|
|
6605
|
-
/**
|
|
6606
|
-
* Deprecated, use `http.response.header.<key>` instead.
|
|
6607
|
-
*
|
|
6608
|
-
* @example 3495
|
|
6609
|
-
*
|
|
6610
|
-
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
6611
|
-
*
|
|
6612
|
-
* @deprecated Replaced by `http.response.header.<key>`.
|
|
6613
|
-
*/
|
|
6614
|
-
const ATTR_HTTP_RESPONSE_CONTENT_LENGTH = 'http.response_content_length';
|
|
6615
|
-
/**
|
|
6616
|
-
* Deprecated, use `http.response.body.size` instead.
|
|
6617
|
-
*
|
|
6618
|
-
* @example 5493
|
|
6619
|
-
*
|
|
6620
|
-
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
6621
|
-
*
|
|
6622
|
-
* @deprecated Replace by `http.response.body.size`.
|
|
6623
|
-
*/
|
|
6624
|
-
const ATTR_HTTP_RESPONSE_CONTENT_LENGTH_UNCOMPRESSED = 'http.response_content_length_uncompressed';
|
|
6625
|
-
|
|
6626
|
-
/*
|
|
6627
|
-
* Copyright The OpenTelemetry Authors
|
|
6628
|
-
*
|
|
6629
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6630
|
-
* you may not use this file except in compliance with the License.
|
|
6631
|
-
* You may obtain a copy of the License at
|
|
6632
|
-
*
|
|
6633
|
-
* https://www.apache.org/licenses/LICENSE-2.0
|
|
6634
|
-
*
|
|
6635
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
6636
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
6637
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
6638
|
-
* See the License for the specific language governing permissions and
|
|
6639
|
-
* limitations under the License.
|
|
6640
|
-
*/
|
|
6641
|
-
// Used to normalize relative URLs
|
|
6642
|
-
let urlNormalizingAnchor;
|
|
6643
|
-
function getUrlNormalizingAnchor() {
|
|
6644
|
-
if (!urlNormalizingAnchor) {
|
|
6645
|
-
urlNormalizingAnchor = document.createElement('a');
|
|
6646
|
-
}
|
|
6647
|
-
return urlNormalizingAnchor;
|
|
6648
|
-
}
|
|
6649
|
-
/**
|
|
6650
|
-
* Helper function to be able to use enum as typed key in type and in interface when using forEach
|
|
6651
|
-
* @param obj
|
|
6652
|
-
* @param key
|
|
6653
|
-
*/
|
|
6654
|
-
function hasKey(obj, key) {
|
|
6655
|
-
return key in obj;
|
|
6656
|
-
}
|
|
6657
|
-
/**
|
|
6658
|
-
* Helper function for starting an event on span based on {@link PerformanceEntries}
|
|
6659
|
-
* @param span
|
|
6660
|
-
* @param performanceName name of performance entry for time start
|
|
6661
|
-
* @param entries
|
|
6662
|
-
* @param ignoreZeros
|
|
6663
|
-
*/
|
|
6664
|
-
function addSpanNetworkEvent(span, performanceName, entries, ignoreZeros = true) {
|
|
6665
|
-
if (hasKey(entries, performanceName) &&
|
|
6666
|
-
typeof entries[performanceName] === 'number' &&
|
|
6667
|
-
!(ignoreZeros && entries[performanceName] === 0)) {
|
|
6668
|
-
return span.addEvent(performanceName, entries[performanceName]);
|
|
6669
|
-
}
|
|
6670
|
-
return undefined;
|
|
6671
|
-
}
|
|
6672
|
-
/**
|
|
6673
|
-
* Helper function for adding network events and content length attributes.
|
|
6674
|
-
*/
|
|
6675
|
-
function addSpanNetworkEvents(span, resource, ignoreNetworkEvents = false, ignoreZeros, skipOldSemconvContentLengthAttrs) {
|
|
6676
|
-
if (ignoreZeros === undefined) {
|
|
6677
|
-
ignoreZeros = resource[PerformanceTimingNames.START_TIME] !== 0;
|
|
6678
|
-
}
|
|
6679
|
-
if (!ignoreNetworkEvents) {
|
|
6680
|
-
addSpanNetworkEvent(span, PerformanceTimingNames.FETCH_START, resource, ignoreZeros);
|
|
6681
|
-
addSpanNetworkEvent(span, PerformanceTimingNames.DOMAIN_LOOKUP_START, resource, ignoreZeros);
|
|
6682
|
-
addSpanNetworkEvent(span, PerformanceTimingNames.DOMAIN_LOOKUP_END, resource, ignoreZeros);
|
|
6683
|
-
addSpanNetworkEvent(span, PerformanceTimingNames.CONNECT_START, resource, ignoreZeros);
|
|
6684
|
-
addSpanNetworkEvent(span, PerformanceTimingNames.SECURE_CONNECTION_START, resource, ignoreZeros);
|
|
6685
|
-
addSpanNetworkEvent(span, PerformanceTimingNames.CONNECT_END, resource, ignoreZeros);
|
|
6686
|
-
addSpanNetworkEvent(span, PerformanceTimingNames.REQUEST_START, resource, ignoreZeros);
|
|
6687
|
-
addSpanNetworkEvent(span, PerformanceTimingNames.RESPONSE_START, resource, ignoreZeros);
|
|
6688
|
-
addSpanNetworkEvent(span, PerformanceTimingNames.RESPONSE_END, resource, ignoreZeros);
|
|
6689
|
-
}
|
|
6690
|
-
if (!skipOldSemconvContentLengthAttrs) {
|
|
6691
|
-
// This block adds content-length-related span attributes using the
|
|
6692
|
-
// *old* HTTP semconv (v1.7.0).
|
|
6693
|
-
const encodedLength = resource[PerformanceTimingNames.ENCODED_BODY_SIZE];
|
|
6694
|
-
if (encodedLength !== undefined) {
|
|
6695
|
-
span.setAttribute(ATTR_HTTP_RESPONSE_CONTENT_LENGTH, encodedLength);
|
|
6696
|
-
}
|
|
6697
|
-
const decodedLength = resource[PerformanceTimingNames.DECODED_BODY_SIZE];
|
|
6698
|
-
// Spec: Not set if transport encoding not used (in which case encoded and decoded sizes match)
|
|
6699
|
-
if (decodedLength !== undefined && encodedLength !== decodedLength) {
|
|
6700
|
-
span.setAttribute(ATTR_HTTP_RESPONSE_CONTENT_LENGTH_UNCOMPRESSED, decodedLength);
|
|
6701
|
-
}
|
|
6702
|
-
}
|
|
6703
|
-
}
|
|
6704
|
-
/**
|
|
6705
|
-
* sort resources by startTime
|
|
6706
|
-
* @param filteredResources
|
|
6707
|
-
*/
|
|
6708
|
-
function sortResources(filteredResources) {
|
|
6709
|
-
return filteredResources.slice().sort((a, b) => {
|
|
6710
|
-
const valueA = a[PerformanceTimingNames.FETCH_START];
|
|
6711
|
-
const valueB = b[PerformanceTimingNames.FETCH_START];
|
|
6712
|
-
if (valueA > valueB) {
|
|
6713
|
-
return 1;
|
|
6714
|
-
}
|
|
6715
|
-
else if (valueA < valueB) {
|
|
6716
|
-
return -1;
|
|
6717
|
-
}
|
|
6718
|
-
return 0;
|
|
6719
|
-
});
|
|
6720
|
-
}
|
|
6721
|
-
/** Returns the origin if present (if in browser context). */
|
|
6722
|
-
function getOrigin() {
|
|
6723
|
-
return typeof location !== 'undefined' ? location.origin : undefined;
|
|
6724
|
-
}
|
|
6725
|
-
/**
|
|
6726
|
-
* Get closest performance resource ignoring the resources that have been
|
|
6727
|
-
* already used.
|
|
6728
|
-
* @param spanUrl
|
|
6729
|
-
* @param startTimeHR
|
|
6730
|
-
* @param endTimeHR
|
|
6731
|
-
* @param resources
|
|
6732
|
-
* @param ignoredResources
|
|
6733
|
-
* @param initiatorType
|
|
6734
|
-
*/
|
|
6735
|
-
function getResource(spanUrl, startTimeHR, endTimeHR, resources, ignoredResources = new WeakSet(), initiatorType) {
|
|
6736
|
-
// de-relativize the URL before usage (does no harm to absolute URLs)
|
|
6737
|
-
const parsedSpanUrl = parseUrl(spanUrl);
|
|
6738
|
-
spanUrl = parsedSpanUrl.toString();
|
|
6739
|
-
const filteredResources = filterResourcesForSpan(spanUrl, startTimeHR, endTimeHR, resources, ignoredResources, initiatorType);
|
|
6740
|
-
if (filteredResources.length === 0) {
|
|
6741
|
-
return {
|
|
6742
|
-
mainRequest: undefined,
|
|
6743
|
-
};
|
|
6744
|
-
}
|
|
6745
|
-
if (filteredResources.length === 1) {
|
|
6746
|
-
return {
|
|
6747
|
-
mainRequest: filteredResources[0],
|
|
6748
|
-
};
|
|
6749
|
-
}
|
|
6750
|
-
const sorted = sortResources(filteredResources);
|
|
6751
|
-
if (parsedSpanUrl.origin !== getOrigin() && sorted.length > 1) {
|
|
6752
|
-
let corsPreFlightRequest = sorted[0];
|
|
6753
|
-
let mainRequest = findMainRequest(sorted, corsPreFlightRequest[PerformanceTimingNames.RESPONSE_END], endTimeHR);
|
|
6754
|
-
const responseEnd = corsPreFlightRequest[PerformanceTimingNames.RESPONSE_END];
|
|
6755
|
-
const fetchStart = mainRequest[PerformanceTimingNames.FETCH_START];
|
|
6756
|
-
// no corsPreFlightRequest
|
|
6757
|
-
if (fetchStart < responseEnd) {
|
|
6758
|
-
mainRequest = corsPreFlightRequest;
|
|
6759
|
-
corsPreFlightRequest = undefined;
|
|
6760
|
-
}
|
|
6761
|
-
return {
|
|
6762
|
-
corsPreFlightRequest,
|
|
6763
|
-
mainRequest,
|
|
6764
|
-
};
|
|
6765
|
-
}
|
|
6766
|
-
else {
|
|
6767
|
-
return {
|
|
6768
|
-
mainRequest: filteredResources[0],
|
|
6769
|
-
};
|
|
6770
|
-
}
|
|
6771
|
-
}
|
|
6772
|
-
/**
|
|
6773
|
-
* Will find the main request skipping the cors pre flight requests
|
|
6774
|
-
* @param resources
|
|
6775
|
-
* @param corsPreFlightRequestEndTime
|
|
6776
|
-
* @param spanEndTimeHR
|
|
6777
|
-
*/
|
|
6778
|
-
function findMainRequest(resources, corsPreFlightRequestEndTime, spanEndTimeHR) {
|
|
6779
|
-
const spanEndTime = hrTimeToNanoseconds(spanEndTimeHR);
|
|
6780
|
-
const minTime = hrTimeToNanoseconds(timeInputToHrTime(corsPreFlightRequestEndTime));
|
|
6781
|
-
let mainRequest = resources[1];
|
|
6782
|
-
let bestGap;
|
|
6783
|
-
const length = resources.length;
|
|
6784
|
-
for (let i = 1; i < length; i++) {
|
|
6785
|
-
const resource = resources[i];
|
|
6786
|
-
const resourceStartTime = hrTimeToNanoseconds(timeInputToHrTime(resource[PerformanceTimingNames.FETCH_START]));
|
|
6787
|
-
const resourceEndTime = hrTimeToNanoseconds(timeInputToHrTime(resource[PerformanceTimingNames.RESPONSE_END]));
|
|
6788
|
-
const currentGap = spanEndTime - resourceEndTime;
|
|
6789
|
-
if (resourceStartTime >= minTime && (!bestGap || currentGap < bestGap)) {
|
|
6790
|
-
bestGap = currentGap;
|
|
6791
|
-
mainRequest = resource;
|
|
6792
|
-
}
|
|
6793
|
-
}
|
|
6794
|
-
return mainRequest;
|
|
6795
|
-
}
|
|
6796
|
-
/**
|
|
6797
|
-
* Filter all resources that has started and finished according to span start time and end time.
|
|
6798
|
-
* It will return the closest resource to a start time
|
|
6799
|
-
* @param spanUrl
|
|
6800
|
-
* @param startTimeHR
|
|
6801
|
-
* @param endTimeHR
|
|
6802
|
-
* @param resources
|
|
6803
|
-
* @param ignoredResources
|
|
6804
|
-
*/
|
|
6805
|
-
function filterResourcesForSpan(spanUrl, startTimeHR, endTimeHR, resources, ignoredResources, initiatorType) {
|
|
6806
|
-
const startTime = hrTimeToNanoseconds(startTimeHR);
|
|
6807
|
-
const endTime = hrTimeToNanoseconds(endTimeHR);
|
|
6808
|
-
let filteredResources = resources.filter(resource => {
|
|
6809
|
-
const resourceStartTime = hrTimeToNanoseconds(timeInputToHrTime(resource[PerformanceTimingNames.FETCH_START]));
|
|
6810
|
-
const resourceEndTime = hrTimeToNanoseconds(timeInputToHrTime(resource[PerformanceTimingNames.RESPONSE_END]));
|
|
6811
|
-
return (resource.initiatorType.toLowerCase() ===
|
|
6812
|
-
(initiatorType || 'xmlhttprequest') &&
|
|
6813
|
-
resource.name === spanUrl &&
|
|
6814
|
-
resourceStartTime >= startTime &&
|
|
6815
|
-
resourceEndTime <= endTime);
|
|
6816
|
-
});
|
|
6817
|
-
if (filteredResources.length > 0) {
|
|
6818
|
-
filteredResources = filteredResources.filter(resource => {
|
|
6819
|
-
return !ignoredResources.has(resource);
|
|
6820
|
-
});
|
|
6821
|
-
}
|
|
6822
|
-
return filteredResources;
|
|
6823
|
-
}
|
|
6824
|
-
/**
|
|
6825
|
-
* Parses url using URL constructor or fallback to anchor element.
|
|
6826
|
-
* @param url
|
|
6827
|
-
*/
|
|
6828
|
-
function parseUrl(url) {
|
|
6829
|
-
if (typeof URL === 'function') {
|
|
6830
|
-
return new URL(url, typeof document !== 'undefined'
|
|
6831
|
-
? document.baseURI
|
|
6832
|
-
: typeof location !== 'undefined' // Some JS runtimes (e.g. Deno) don't define this
|
|
6833
|
-
? location.href
|
|
6834
|
-
: undefined);
|
|
6835
|
-
}
|
|
6836
|
-
const element = getUrlNormalizingAnchor();
|
|
6837
|
-
element.href = url;
|
|
6838
|
-
return element;
|
|
6839
|
-
}
|
|
6840
6330
|
/**
|
|
6841
6331
|
* Get element XPath
|
|
6842
6332
|
* @param target - target element
|
|
@@ -6915,25 +6405,6 @@ function getNodeValue(target, optimised) {
|
|
|
6915
6405
|
}
|
|
6916
6406
|
return `/${nodeValue}`;
|
|
6917
6407
|
}
|
|
6918
|
-
/**
|
|
6919
|
-
* Checks if trace headers should be propagated
|
|
6920
|
-
* @param spanUrl
|
|
6921
|
-
* @private
|
|
6922
|
-
*/
|
|
6923
|
-
function shouldPropagateTraceHeaders(spanUrl, propagateTraceHeaderCorsUrls) {
|
|
6924
|
-
let propagateTraceHeaderUrls = propagateTraceHeaderCorsUrls || [];
|
|
6925
|
-
if (typeof propagateTraceHeaderUrls === 'string' ||
|
|
6926
|
-
propagateTraceHeaderUrls instanceof RegExp) {
|
|
6927
|
-
propagateTraceHeaderUrls = [propagateTraceHeaderUrls];
|
|
6928
|
-
}
|
|
6929
|
-
const parsedSpanUrl = parseUrl(spanUrl);
|
|
6930
|
-
if (parsedSpanUrl.origin === getOrigin()) {
|
|
6931
|
-
return true;
|
|
6932
|
-
}
|
|
6933
|
-
else {
|
|
6934
|
-
return propagateTraceHeaderUrls.some(propagateTraceHeaderUrl => urlMatches(spanUrl, propagateTraceHeaderUrl));
|
|
6935
|
-
}
|
|
6936
|
-
}
|
|
6937
6408
|
|
|
6938
6409
|
/*
|
|
6939
6410
|
* Copyright The OpenTelemetry Authors
|
|
@@ -16263,21 +15734,6 @@ class InstrumentationBase extends InstrumentationAbstract {
|
|
|
16263
15734
|
* @param execute - function to be executed
|
|
16264
15735
|
* @param onFinish - callback to run when execute finishes
|
|
16265
15736
|
*/
|
|
16266
|
-
function safeExecuteInTheMiddle(execute, onFinish, preventThrowingError) {
|
|
16267
|
-
let error;
|
|
16268
|
-
let result;
|
|
16269
|
-
try {
|
|
16270
|
-
result = execute();
|
|
16271
|
-
}
|
|
16272
|
-
catch (e) {
|
|
16273
|
-
error = e;
|
|
16274
|
-
}
|
|
16275
|
-
finally {
|
|
16276
|
-
onFinish(error, result);
|
|
16277
|
-
// eslint-disable-next-line no-unsafe-finally
|
|
16278
|
-
return result;
|
|
16279
|
-
}
|
|
16280
|
-
}
|
|
16281
15737
|
/**
|
|
16282
15738
|
* Checks if certain function has been already wrapped
|
|
16283
15739
|
* @param func
|
|
@@ -16304,80 +15760,13 @@ function isWrapped(func) {
|
|
|
16304
15760
|
* See the License for the specific language governing permissions and
|
|
16305
15761
|
* limitations under the License.
|
|
16306
15762
|
*/
|
|
16307
|
-
var
|
|
16308
|
-
(function (
|
|
16309
|
-
|
|
16310
|
-
|
|
16311
|
-
|
|
16312
|
-
|
|
16313
|
-
|
|
16314
|
-
SemconvStability[SemconvStability["DUPLICATE"] = 3] = "DUPLICATE";
|
|
16315
|
-
})(SemconvStability || (SemconvStability = {}));
|
|
16316
|
-
/**
|
|
16317
|
-
* Determine the appropriate semconv stability for the given namespace.
|
|
16318
|
-
*
|
|
16319
|
-
* This will parse the given string of comma-separated values (often
|
|
16320
|
-
* `process.env.OTEL_SEMCONV_STABILITY_OPT_IN`) looking for the `${namespace}`
|
|
16321
|
-
* or `${namespace}/dup` tokens. This is a pattern defined by a number of
|
|
16322
|
-
* non-normative semconv documents.
|
|
16323
|
-
*
|
|
16324
|
-
* For example:
|
|
16325
|
-
* - namespace 'http': https://opentelemetry.io/docs/specs/semconv/non-normative/http-migration/
|
|
16326
|
-
* - namespace 'database': https://opentelemetry.io/docs/specs/semconv/non-normative/database-migration/
|
|
16327
|
-
* - namespace 'k8s': https://opentelemetry.io/docs/specs/semconv/non-normative/k8s-migration/
|
|
16328
|
-
*
|
|
16329
|
-
* Usage:
|
|
16330
|
-
*
|
|
16331
|
-
* import {SemconvStability, semconvStabilityFromStr} from '@opentelemetry/instrumentation';
|
|
16332
|
-
*
|
|
16333
|
-
* export class FooInstrumentation extends InstrumentationBase<FooInstrumentationConfig> {
|
|
16334
|
-
* private _semconvStability: SemconvStability;
|
|
16335
|
-
* constructor(config: FooInstrumentationConfig = {}) {
|
|
16336
|
-
* super('@opentelemetry/instrumentation-foo', VERSION, config);
|
|
16337
|
-
*
|
|
16338
|
-
* // When supporting the OTEL_SEMCONV_STABILITY_OPT_IN envvar
|
|
16339
|
-
* this._semconvStability = semconvStabilityFromStr(
|
|
16340
|
-
* 'http',
|
|
16341
|
-
* process.env.OTEL_SEMCONV_STABILITY_OPT_IN
|
|
16342
|
-
* );
|
|
16343
|
-
*
|
|
16344
|
-
* // or when supporting a `semconvStabilityOptIn` config option (e.g. for
|
|
16345
|
-
* // the web where there are no envvars).
|
|
16346
|
-
* this._semconvStability = semconvStabilityFromStr(
|
|
16347
|
-
* 'http',
|
|
16348
|
-
* config?.semconvStabilityOptIn
|
|
16349
|
-
* );
|
|
16350
|
-
* }
|
|
16351
|
-
* }
|
|
16352
|
-
*
|
|
16353
|
-
* // Then, to apply semconv, use the following or similar:
|
|
16354
|
-
* if (this._semconvStability & SemconvStability.OLD) {
|
|
16355
|
-
* // ...
|
|
16356
|
-
* }
|
|
16357
|
-
* if (this._semconvStability & SemconvStability.STABLE) {
|
|
16358
|
-
* // ...
|
|
16359
|
-
* }
|
|
16360
|
-
*
|
|
16361
|
-
*/
|
|
16362
|
-
function semconvStabilityFromStr(namespace, str) {
|
|
16363
|
-
let semconvStability = SemconvStability.OLD;
|
|
16364
|
-
// The same parsing of `str` as `getStringListFromEnv` from the core pkg.
|
|
16365
|
-
const entries = str
|
|
16366
|
-
?.split(',')
|
|
16367
|
-
.map(v => v.trim())
|
|
16368
|
-
.filter(s => s !== '');
|
|
16369
|
-
for (const entry of entries ?? []) {
|
|
16370
|
-
if (entry.toLowerCase() === namespace + '/dup') {
|
|
16371
|
-
// DUPLICATE takes highest precedence.
|
|
16372
|
-
semconvStability = SemconvStability.DUPLICATE;
|
|
16373
|
-
break;
|
|
16374
|
-
}
|
|
16375
|
-
else if (entry.toLowerCase() === namespace) {
|
|
16376
|
-
semconvStability = SemconvStability.STABLE;
|
|
16377
|
-
}
|
|
16378
|
-
}
|
|
16379
|
-
return semconvStability;
|
|
16380
|
-
}
|
|
15763
|
+
var AttributeNames;
|
|
15764
|
+
(function (AttributeNames) {
|
|
15765
|
+
AttributeNames["EVENT_TYPE"] = "event_type";
|
|
15766
|
+
AttributeNames["TARGET_ELEMENT"] = "target_element";
|
|
15767
|
+
AttributeNames["TARGET_XPATH"] = "target_xpath";
|
|
15768
|
+
AttributeNames["HTTP_URL"] = "http.url";
|
|
15769
|
+
})(AttributeNames || (AttributeNames = {}));
|
|
16381
15770
|
|
|
16382
15771
|
/*
|
|
16383
15772
|
* Copyright The OpenTelemetry Authors
|
|
@@ -16394,117 +15783,9 @@ function semconvStabilityFromStr(namespace, str) {
|
|
|
16394
15783
|
* See the License for the specific language governing permissions and
|
|
16395
15784
|
* limitations under the License.
|
|
16396
15785
|
*/
|
|
16397
|
-
|
|
16398
|
-
|
|
16399
|
-
|
|
16400
|
-
var AttributeNames$3;
|
|
16401
|
-
(function (AttributeNames) {
|
|
16402
|
-
AttributeNames["COMPONENT"] = "component";
|
|
16403
|
-
AttributeNames["HTTP_STATUS_TEXT"] = "http.status_text";
|
|
16404
|
-
})(AttributeNames$3 || (AttributeNames$3 = {}));
|
|
16405
|
-
|
|
16406
|
-
/*
|
|
16407
|
-
* Copyright The OpenTelemetry Authors
|
|
16408
|
-
*
|
|
16409
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
16410
|
-
* you may not use this file except in compliance with the License.
|
|
16411
|
-
* You may obtain a copy of the License at
|
|
16412
|
-
*
|
|
16413
|
-
* https://www.apache.org/licenses/LICENSE-2.0
|
|
16414
|
-
*
|
|
16415
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
16416
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
16417
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16418
|
-
* See the License for the specific language governing permissions and
|
|
16419
|
-
* limitations under the License.
|
|
16420
|
-
*/
|
|
16421
|
-
/*
|
|
16422
|
-
* This file contains a copy of unstable semantic convention definitions
|
|
16423
|
-
* used by this package.
|
|
16424
|
-
* @see https://github.com/open-telemetry/opentelemetry-js/tree/main/semantic-conventions#unstable-semconv
|
|
16425
|
-
*/
|
|
16426
|
-
/**
|
|
16427
|
-
* Deprecated, use one of `server.address`, `client.address` or `http.request.header.host` instead, depending on the usage.
|
|
16428
|
-
*
|
|
16429
|
-
* @example www.example.org
|
|
16430
|
-
*
|
|
16431
|
-
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
16432
|
-
*
|
|
16433
|
-
* @deprecated Replaced by one of `server.address`, `client.address` or `http.request.header.host`, depending on the usage.
|
|
16434
|
-
*/
|
|
16435
|
-
const ATTR_HTTP_HOST$1 = 'http.host';
|
|
16436
|
-
/**
|
|
16437
|
-
* Deprecated, use `http.request.method` instead.
|
|
16438
|
-
*
|
|
16439
|
-
* @example GET
|
|
16440
|
-
* @example POST
|
|
16441
|
-
* @example HEAD
|
|
16442
|
-
*
|
|
16443
|
-
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
16444
|
-
*
|
|
16445
|
-
* @deprecated Replaced by `http.request.method`.
|
|
16446
|
-
*/
|
|
16447
|
-
const ATTR_HTTP_METHOD$1 = 'http.method';
|
|
16448
|
-
/**
|
|
16449
|
-
* 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.
|
|
16450
|
-
*
|
|
16451
|
-
* @example 3495
|
|
16452
|
-
*
|
|
16453
|
-
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
16454
|
-
*/
|
|
16455
|
-
const ATTR_HTTP_REQUEST_BODY_SIZE$1 = 'http.request.body.size';
|
|
16456
|
-
/**
|
|
16457
|
-
* Deprecated, use `http.request.body.size` instead.
|
|
16458
|
-
*
|
|
16459
|
-
* @example 5493
|
|
16460
|
-
*
|
|
16461
|
-
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
16462
|
-
*
|
|
16463
|
-
* @deprecated Replaced by `http.request.body.size`.
|
|
16464
|
-
*/
|
|
16465
|
-
const ATTR_HTTP_REQUEST_CONTENT_LENGTH_UNCOMPRESSED$1 = 'http.request_content_length_uncompressed';
|
|
16466
|
-
/**
|
|
16467
|
-
* Deprecated, use `url.scheme` instead.
|
|
16468
|
-
*
|
|
16469
|
-
* @example http
|
|
16470
|
-
* @example https
|
|
16471
|
-
*
|
|
16472
|
-
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
16473
|
-
*
|
|
16474
|
-
* @deprecated Replaced by `url.scheme` instead.
|
|
16475
|
-
*/
|
|
16476
|
-
const ATTR_HTTP_SCHEME$1 = 'http.scheme';
|
|
16477
|
-
/**
|
|
16478
|
-
* Deprecated, use `http.response.status_code` instead.
|
|
16479
|
-
*
|
|
16480
|
-
* @example 200
|
|
16481
|
-
*
|
|
16482
|
-
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
16483
|
-
*
|
|
16484
|
-
* @deprecated Replaced by `http.response.status_code`.
|
|
16485
|
-
*/
|
|
16486
|
-
const ATTR_HTTP_STATUS_CODE$1 = 'http.status_code';
|
|
16487
|
-
/**
|
|
16488
|
-
* Deprecated, use `url.full` instead.
|
|
16489
|
-
*
|
|
16490
|
-
* @example https://www.foo.bar/search?q=OpenTelemetry#SemConv
|
|
16491
|
-
*
|
|
16492
|
-
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
16493
|
-
*
|
|
16494
|
-
* @deprecated Replaced by `url.full`.
|
|
16495
|
-
*/
|
|
16496
|
-
const ATTR_HTTP_URL$2 = 'http.url';
|
|
16497
|
-
/**
|
|
16498
|
-
* Deprecated, use `user_agent.original` instead.
|
|
16499
|
-
*
|
|
16500
|
-
* @example CERN-LineMode/2.15 libwww/2.17b3
|
|
16501
|
-
* @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
|
|
16502
|
-
*
|
|
16503
|
-
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
16504
|
-
*
|
|
16505
|
-
* @deprecated Replaced by `user_agent.original`.
|
|
16506
|
-
*/
|
|
16507
|
-
const ATTR_HTTP_USER_AGENT$2 = 'http.user_agent';
|
|
15786
|
+
// this is autogenerated file, see scripts/version-update.js
|
|
15787
|
+
const PACKAGE_VERSION = '0.53.0';
|
|
15788
|
+
const PACKAGE_NAME = '@opentelemetry/instrumentation-user-interaction';
|
|
16508
15789
|
|
|
16509
15790
|
/*
|
|
16510
15791
|
* Copyright The OpenTelemetry Authors
|
|
@@ -16521,2375 +15802,532 @@ const ATTR_HTTP_USER_AGENT$2 = 'http.user_agent';
|
|
|
16521
15802
|
* See the License for the specific language governing permissions and
|
|
16522
15803
|
* limitations under the License.
|
|
16523
15804
|
*/
|
|
16524
|
-
|
|
16525
|
-
|
|
16526
|
-
const
|
|
16527
|
-
|
|
16528
|
-
|
|
16529
|
-
|
|
16530
|
-
* Helper function to determine payload content length for fetch requests
|
|
16531
|
-
*
|
|
16532
|
-
* The fetch API is kinda messy: there are a couple of ways the body can be passed in.
|
|
16533
|
-
*
|
|
16534
|
-
* In all cases, the body param can be some variation of ReadableStream,
|
|
16535
|
-
* and ReadableStreams can only be read once! We want to avoid consuming the body here,
|
|
16536
|
-
* because that would mean that the body never gets sent with the actual fetch request.
|
|
16537
|
-
*
|
|
16538
|
-
* Either the first arg is a Request object, which can be cloned
|
|
16539
|
-
* so we can clone that object and read the body of the clone
|
|
16540
|
-
* without disturbing the original argument
|
|
16541
|
-
* However, reading the body here can only be done async; the body() method returns a promise
|
|
16542
|
-
* this means this entire function has to return a promise
|
|
16543
|
-
*
|
|
16544
|
-
* OR the first arg is a url/string
|
|
16545
|
-
* in which case the second arg has type RequestInit
|
|
16546
|
-
* RequestInit is NOT cloneable, but RequestInit.body is writable
|
|
16547
|
-
* so we can chain it into ReadableStream.pipeThrough()
|
|
16548
|
-
*
|
|
16549
|
-
* ReadableStream.pipeThrough() lets us process a stream and returns a new stream
|
|
16550
|
-
* So we can measure the body length as it passes through the pie, but need to attach
|
|
16551
|
-
* the new stream to the original request
|
|
16552
|
-
* so that the browser still has access to the body.
|
|
16553
|
-
*
|
|
16554
|
-
* @param body
|
|
16555
|
-
* @returns promise that resolves to the content length of the body
|
|
16556
|
-
*/
|
|
16557
|
-
function getFetchBodyLength(...args) {
|
|
16558
|
-
if (args[0] instanceof URL || typeof args[0] === 'string') {
|
|
16559
|
-
const requestInit = args[1];
|
|
16560
|
-
if (!requestInit?.body) {
|
|
16561
|
-
return Promise.resolve();
|
|
16562
|
-
}
|
|
16563
|
-
if (requestInit.body instanceof ReadableStream) {
|
|
16564
|
-
const { body, length } = _getBodyNonDestructively(requestInit.body);
|
|
16565
|
-
requestInit.body = body;
|
|
16566
|
-
return length;
|
|
16567
|
-
}
|
|
16568
|
-
else {
|
|
16569
|
-
return Promise.resolve(getXHRBodyLength$1(requestInit.body));
|
|
16570
|
-
}
|
|
16571
|
-
}
|
|
16572
|
-
else {
|
|
16573
|
-
const info = args[0];
|
|
16574
|
-
if (!info?.body) {
|
|
16575
|
-
return Promise.resolve();
|
|
16576
|
-
}
|
|
16577
|
-
return info
|
|
16578
|
-
.clone()
|
|
16579
|
-
.text()
|
|
16580
|
-
.then(t => getByteLength$1(t));
|
|
16581
|
-
}
|
|
16582
|
-
}
|
|
16583
|
-
function _getBodyNonDestructively(body) {
|
|
16584
|
-
// can't read a ReadableStream without destroying it
|
|
16585
|
-
// but we CAN pipe it through and return a new ReadableStream
|
|
16586
|
-
// some (older) platforms don't expose the pipeThrough method and in that scenario, we're out of luck;
|
|
16587
|
-
// there's no way to read the stream without consuming it.
|
|
16588
|
-
if (!body.pipeThrough) {
|
|
16589
|
-
DIAG_LOGGER$1.warn('Platform has ReadableStream but not pipeThrough!');
|
|
16590
|
-
return {
|
|
16591
|
-
body,
|
|
16592
|
-
length: Promise.resolve(undefined),
|
|
16593
|
-
};
|
|
16594
|
-
}
|
|
16595
|
-
let length = 0;
|
|
16596
|
-
let resolveLength;
|
|
16597
|
-
const lengthPromise = new Promise(resolve => {
|
|
16598
|
-
resolveLength = resolve;
|
|
16599
|
-
});
|
|
16600
|
-
const transform = new TransformStream({
|
|
16601
|
-
start() { },
|
|
16602
|
-
async transform(chunk, controller) {
|
|
16603
|
-
const bytearray = (await chunk);
|
|
16604
|
-
length += bytearray.byteLength;
|
|
16605
|
-
controller.enqueue(chunk);
|
|
16606
|
-
},
|
|
16607
|
-
flush() {
|
|
16608
|
-
resolveLength(length);
|
|
16609
|
-
},
|
|
16610
|
-
});
|
|
16611
|
-
return {
|
|
16612
|
-
body: body.pipeThrough(transform),
|
|
16613
|
-
length: lengthPromise,
|
|
16614
|
-
};
|
|
16615
|
-
}
|
|
16616
|
-
function isDocument$1(value) {
|
|
16617
|
-
return typeof Document !== 'undefined' && value instanceof Document;
|
|
16618
|
-
}
|
|
16619
|
-
/**
|
|
16620
|
-
* Helper function to determine payload content length for XHR requests
|
|
16621
|
-
* @param body
|
|
16622
|
-
* @returns content length
|
|
16623
|
-
*/
|
|
16624
|
-
function getXHRBodyLength$1(body) {
|
|
16625
|
-
if (isDocument$1(body)) {
|
|
16626
|
-
return new XMLSerializer().serializeToString(document).length;
|
|
16627
|
-
}
|
|
16628
|
-
// XMLHttpRequestBodyInit expands to the following:
|
|
16629
|
-
if (typeof body === 'string') {
|
|
16630
|
-
return getByteLength$1(body);
|
|
16631
|
-
}
|
|
16632
|
-
if (body instanceof Blob) {
|
|
16633
|
-
return body.size;
|
|
16634
|
-
}
|
|
16635
|
-
if (body instanceof FormData) {
|
|
16636
|
-
return getFormDataSize$1(body);
|
|
16637
|
-
}
|
|
16638
|
-
if (body instanceof URLSearchParams) {
|
|
16639
|
-
return getByteLength$1(body.toString());
|
|
16640
|
-
}
|
|
16641
|
-
// ArrayBuffer | ArrayBufferView
|
|
16642
|
-
if (body.byteLength !== undefined) {
|
|
16643
|
-
return body.byteLength;
|
|
16644
|
-
}
|
|
16645
|
-
DIAG_LOGGER$1.warn('unknown body type');
|
|
16646
|
-
return undefined;
|
|
16647
|
-
}
|
|
16648
|
-
const TEXT_ENCODER$1 = new TextEncoder();
|
|
16649
|
-
function getByteLength$1(s) {
|
|
16650
|
-
return TEXT_ENCODER$1.encode(s).byteLength;
|
|
16651
|
-
}
|
|
16652
|
-
function getFormDataSize$1(formData) {
|
|
16653
|
-
let size = 0;
|
|
16654
|
-
for (const [key, value] of formData.entries()) {
|
|
16655
|
-
size += key.length;
|
|
16656
|
-
if (value instanceof Blob) {
|
|
16657
|
-
size += value.size;
|
|
16658
|
-
}
|
|
16659
|
-
else {
|
|
16660
|
-
size += value.length;
|
|
16661
|
-
}
|
|
16662
|
-
}
|
|
16663
|
-
return size;
|
|
15805
|
+
/// <reference types="zone.js" />
|
|
15806
|
+
const ZONE_CONTEXT_KEY = 'OT_ZONE_CONTEXT';
|
|
15807
|
+
const EVENT_NAVIGATION_NAME = 'Navigation:';
|
|
15808
|
+
const DEFAULT_EVENT_NAMES = ['click'];
|
|
15809
|
+
function defaultShouldPreventSpanCreation() {
|
|
15810
|
+
return false;
|
|
16664
15811
|
}
|
|
16665
15812
|
/**
|
|
16666
|
-
*
|
|
16667
|
-
*
|
|
16668
|
-
|
|
16669
|
-
function normalizeHttpRequestMethod$1(method) {
|
|
16670
|
-
const knownMethods = getKnownMethods$1();
|
|
16671
|
-
const methUpper = method.toUpperCase();
|
|
16672
|
-
if (methUpper in knownMethods) {
|
|
16673
|
-
return methUpper;
|
|
16674
|
-
}
|
|
16675
|
-
else {
|
|
16676
|
-
return '_OTHER';
|
|
16677
|
-
}
|
|
16678
|
-
}
|
|
16679
|
-
const DEFAULT_KNOWN_METHODS$1 = {
|
|
16680
|
-
CONNECT: true,
|
|
16681
|
-
DELETE: true,
|
|
16682
|
-
GET: true,
|
|
16683
|
-
HEAD: true,
|
|
16684
|
-
OPTIONS: true,
|
|
16685
|
-
PATCH: true,
|
|
16686
|
-
POST: true,
|
|
16687
|
-
PUT: true,
|
|
16688
|
-
TRACE: true,
|
|
16689
|
-
};
|
|
16690
|
-
let knownMethods$1;
|
|
16691
|
-
function getKnownMethods$1() {
|
|
16692
|
-
if (knownMethods$1 === undefined) {
|
|
16693
|
-
{
|
|
16694
|
-
knownMethods$1 = DEFAULT_KNOWN_METHODS$1;
|
|
16695
|
-
}
|
|
16696
|
-
}
|
|
16697
|
-
return knownMethods$1;
|
|
16698
|
-
}
|
|
16699
|
-
const HTTP_PORT_FROM_PROTOCOL$1 = {
|
|
16700
|
-
'https:': '443',
|
|
16701
|
-
'http:': '80',
|
|
16702
|
-
};
|
|
16703
|
-
function serverPortFromUrl$1(url) {
|
|
16704
|
-
const serverPort = Number(url.port || HTTP_PORT_FROM_PROTOCOL$1[url.protocol]);
|
|
16705
|
-
// Guard with `if (serverPort)` because `Number('') === 0`.
|
|
16706
|
-
if (serverPort && !isNaN(serverPort)) {
|
|
16707
|
-
return serverPort;
|
|
16708
|
-
}
|
|
16709
|
-
else {
|
|
16710
|
-
return undefined;
|
|
16711
|
-
}
|
|
16712
|
-
}
|
|
16713
|
-
|
|
16714
|
-
/*
|
|
16715
|
-
* Copyright The OpenTelemetry Authors
|
|
16716
|
-
*
|
|
16717
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
16718
|
-
* you may not use this file except in compliance with the License.
|
|
16719
|
-
* You may obtain a copy of the License at
|
|
16720
|
-
*
|
|
16721
|
-
* https://www.apache.org/licenses/LICENSE-2.0
|
|
16722
|
-
*
|
|
16723
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
16724
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
16725
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16726
|
-
* See the License for the specific language governing permissions and
|
|
16727
|
-
* limitations under the License.
|
|
16728
|
-
*/
|
|
16729
|
-
// this is autogenerated file, see scripts/version-update.js
|
|
16730
|
-
const VERSION$1 = '0.208.0';
|
|
16731
|
-
|
|
16732
|
-
/*
|
|
16733
|
-
* Copyright The OpenTelemetry Authors
|
|
16734
|
-
*
|
|
16735
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
16736
|
-
* you may not use this file except in compliance with the License.
|
|
16737
|
-
* You may obtain a copy of the License at
|
|
16738
|
-
*
|
|
16739
|
-
* https://www.apache.org/licenses/LICENSE-2.0
|
|
16740
|
-
*
|
|
16741
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
16742
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
16743
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16744
|
-
* See the License for the specific language governing permissions and
|
|
16745
|
-
* limitations under the License.
|
|
15813
|
+
* This class represents a UserInteraction plugin for auto instrumentation.
|
|
15814
|
+
* If zone.js is available then it patches the zone otherwise it patches
|
|
15815
|
+
* addEventListener of HTMLElement
|
|
16746
15816
|
*/
|
|
16747
|
-
|
|
16748
|
-
|
|
16749
|
-
|
|
16750
|
-
|
|
16751
|
-
|
|
16752
|
-
|
|
16753
|
-
|
|
16754
|
-
|
|
16755
|
-
|
|
16756
|
-
|
|
16757
|
-
component = 'fetch';
|
|
16758
|
-
version = VERSION$1;
|
|
16759
|
-
moduleName = this.component;
|
|
16760
|
-
_usedResources = new WeakSet();
|
|
16761
|
-
_tasksCount = 0;
|
|
16762
|
-
_semconvStability;
|
|
15817
|
+
class UserInteractionInstrumentation extends InstrumentationBase {
|
|
15818
|
+
version = PACKAGE_VERSION;
|
|
15819
|
+
moduleName = 'user-interaction';
|
|
15820
|
+
_spansData = new WeakMap();
|
|
15821
|
+
// for addEventListener/removeEventListener state
|
|
15822
|
+
_wrappedListeners = new WeakMap();
|
|
15823
|
+
// for event bubbling
|
|
15824
|
+
_eventsSpanMap = new WeakMap();
|
|
15825
|
+
_eventNames;
|
|
15826
|
+
_shouldPreventSpanCreation;
|
|
16763
15827
|
constructor(config = {}) {
|
|
16764
|
-
super(
|
|
16765
|
-
this.
|
|
15828
|
+
super(PACKAGE_NAME, PACKAGE_VERSION, config);
|
|
15829
|
+
this._eventNames = new Set(config?.eventNames ?? DEFAULT_EVENT_NAMES);
|
|
15830
|
+
this._shouldPreventSpanCreation =
|
|
15831
|
+
typeof config?.shouldPreventSpanCreation === 'function'
|
|
15832
|
+
? config.shouldPreventSpanCreation
|
|
15833
|
+
: defaultShouldPreventSpanCreation;
|
|
16766
15834
|
}
|
|
16767
15835
|
init() { }
|
|
16768
15836
|
/**
|
|
16769
|
-
*
|
|
16770
|
-
*
|
|
16771
|
-
*
|
|
16772
|
-
|
|
16773
|
-
|
|
16774
|
-
const childSpan = this.tracer.startSpan('CORS Preflight', {
|
|
16775
|
-
startTime: corsPreFlightRequest[PerformanceTimingNames.FETCH_START],
|
|
16776
|
-
}, trace.setSpan(context.active(), span));
|
|
16777
|
-
const skipOldSemconvContentLengthAttrs = !(this._semconvStability & SemconvStability.OLD);
|
|
16778
|
-
addSpanNetworkEvents(childSpan, corsPreFlightRequest, this.getConfig().ignoreNetworkEvents, undefined, skipOldSemconvContentLengthAttrs);
|
|
16779
|
-
childSpan.end(corsPreFlightRequest[PerformanceTimingNames.RESPONSE_END]);
|
|
16780
|
-
}
|
|
16781
|
-
/**
|
|
16782
|
-
* Adds more attributes to span just before ending it
|
|
15837
|
+
* This will check if last task was timeout and will save the time to
|
|
15838
|
+
* fix the user interaction when nothing happens
|
|
15839
|
+
* This timeout comes from xhr plugin which is needed to collect information
|
|
15840
|
+
* about last xhr main request from observer
|
|
15841
|
+
* @param task
|
|
16783
15842
|
* @param span
|
|
16784
|
-
* @param response
|
|
16785
15843
|
*/
|
|
16786
|
-
|
|
16787
|
-
const
|
|
16788
|
-
if (
|
|
16789
|
-
|
|
16790
|
-
|
|
16791
|
-
span.setAttribute(AttributeNames$3.HTTP_STATUS_TEXT, response.statusText);
|
|
16792
|
-
}
|
|
16793
|
-
span.setAttribute(ATTR_HTTP_HOST$1, parsedUrl.host);
|
|
16794
|
-
span.setAttribute(ATTR_HTTP_SCHEME$1, parsedUrl.protocol.replace(':', ''));
|
|
16795
|
-
if (typeof navigator !== 'undefined') {
|
|
16796
|
-
span.setAttribute(ATTR_HTTP_USER_AGENT$2, navigator.userAgent);
|
|
15844
|
+
_checkForTimeout(task, span) {
|
|
15845
|
+
const spanData = this._spansData.get(span);
|
|
15846
|
+
if (spanData) {
|
|
15847
|
+
if (task.source === 'setTimeout') {
|
|
15848
|
+
spanData.hrTimeLastTimeout = hrTime();
|
|
16797
15849
|
}
|
|
16798
|
-
|
|
16799
|
-
|
|
16800
|
-
|
|
16801
|
-
// TODO: Set server.{address,port} at span creation for sampling decisions
|
|
16802
|
-
// (a "SHOULD" requirement in semconv).
|
|
16803
|
-
span.setAttribute(ATTR_SERVER_ADDRESS, parsedUrl.hostname);
|
|
16804
|
-
const serverPort = serverPortFromUrl$1(parsedUrl);
|
|
16805
|
-
if (serverPort) {
|
|
16806
|
-
span.setAttribute(ATTR_SERVER_PORT, serverPort);
|
|
15850
|
+
else if (task.source !== 'Promise.then' &&
|
|
15851
|
+
task.source !== 'setTimeout') {
|
|
15852
|
+
spanData.hrTimeLastTimeout = undefined;
|
|
16807
15853
|
}
|
|
16808
15854
|
}
|
|
16809
15855
|
}
|
|
16810
15856
|
/**
|
|
16811
|
-
*
|
|
16812
|
-
* @param options
|
|
16813
|
-
* @param spanUrl
|
|
15857
|
+
* Controls whether or not to create a span, based on the event type.
|
|
16814
15858
|
*/
|
|
16815
|
-
|
|
16816
|
-
|
|
16817
|
-
|
|
16818
|
-
|
|
16819
|
-
|
|
16820
|
-
|
|
16821
|
-
|
|
16822
|
-
|
|
15859
|
+
_allowEventName(eventName) {
|
|
15860
|
+
return this._eventNames.has(eventName);
|
|
15861
|
+
}
|
|
15862
|
+
/**
|
|
15863
|
+
* Creates a new span
|
|
15864
|
+
* @param element
|
|
15865
|
+
* @param eventName
|
|
15866
|
+
* @param parentSpan
|
|
15867
|
+
*/
|
|
15868
|
+
_createSpan(element, eventName, parentSpan) {
|
|
15869
|
+
if (!(element instanceof HTMLElement)) {
|
|
15870
|
+
return undefined;
|
|
16823
15871
|
}
|
|
16824
|
-
if (
|
|
16825
|
-
|
|
16826
|
-
set: (h, k, v) => h.set(k, typeof v === 'string' ? v : String(v)),
|
|
16827
|
-
});
|
|
15872
|
+
if (!element.getAttribute) {
|
|
15873
|
+
return undefined;
|
|
16828
15874
|
}
|
|
16829
|
-
|
|
16830
|
-
|
|
16831
|
-
|
|
16832
|
-
|
|
15875
|
+
if (element.hasAttribute('disabled')) {
|
|
15876
|
+
return undefined;
|
|
15877
|
+
}
|
|
15878
|
+
if (!this._allowEventName(eventName)) {
|
|
15879
|
+
return undefined;
|
|
16833
15880
|
}
|
|
16834
|
-
|
|
16835
|
-
|
|
16836
|
-
|
|
15881
|
+
const xpath = getElementXPath(element, true);
|
|
15882
|
+
try {
|
|
15883
|
+
const span = this.tracer.startSpan(eventName, {
|
|
15884
|
+
attributes: {
|
|
15885
|
+
[AttributeNames.EVENT_TYPE]: eventName,
|
|
15886
|
+
[AttributeNames.TARGET_ELEMENT]: element.tagName,
|
|
15887
|
+
[AttributeNames.TARGET_XPATH]: xpath,
|
|
15888
|
+
[AttributeNames.HTTP_URL]: window.location.href,
|
|
15889
|
+
},
|
|
15890
|
+
}, parentSpan
|
|
15891
|
+
? trace.setSpan(context.active(), parentSpan)
|
|
15892
|
+
: undefined);
|
|
15893
|
+
if (this._shouldPreventSpanCreation(eventName, element, span) === true) {
|
|
15894
|
+
return undefined;
|
|
15895
|
+
}
|
|
15896
|
+
this._spansData.set(span, {
|
|
15897
|
+
taskCount: 0,
|
|
16837
15898
|
});
|
|
15899
|
+
return span;
|
|
16838
15900
|
}
|
|
16839
|
-
|
|
16840
|
-
|
|
16841
|
-
propagation.inject(context.active(), headers);
|
|
16842
|
-
options.headers = Object.assign({}, headers, options.headers || {});
|
|
15901
|
+
catch (e) {
|
|
15902
|
+
this._diag.error('failed to start create new user interaction span', e);
|
|
16843
15903
|
}
|
|
15904
|
+
return undefined;
|
|
16844
15905
|
}
|
|
16845
15906
|
/**
|
|
16846
|
-
*
|
|
16847
|
-
*
|
|
16848
|
-
*
|
|
16849
|
-
* @private
|
|
15907
|
+
* Decrement number of tasks that left in zone,
|
|
15908
|
+
* This is needed to be able to end span when no more tasks left
|
|
15909
|
+
* @param span
|
|
16850
15910
|
*/
|
|
16851
|
-
|
|
16852
|
-
|
|
16853
|
-
|
|
16854
|
-
|
|
16855
|
-
|
|
16856
|
-
|
|
16857
|
-
|
|
16858
|
-
|
|
16859
|
-
|
|
16860
|
-
|
|
15911
|
+
_decrementTask(span) {
|
|
15912
|
+
const spanData = this._spansData.get(span);
|
|
15913
|
+
if (spanData) {
|
|
15914
|
+
spanData.taskCount--;
|
|
15915
|
+
if (spanData.taskCount === 0) {
|
|
15916
|
+
this._tryToEndSpan(span, spanData.hrTimeLastTimeout);
|
|
15917
|
+
}
|
|
15918
|
+
}
|
|
15919
|
+
}
|
|
15920
|
+
/**
|
|
15921
|
+
* Return the current span
|
|
15922
|
+
* @param zone
|
|
15923
|
+
* @private
|
|
16861
15924
|
*/
|
|
16862
|
-
|
|
16863
|
-
|
|
16864
|
-
|
|
16865
|
-
return;
|
|
15925
|
+
_getCurrentSpan(zone) {
|
|
15926
|
+
const context = zone.get(ZONE_CONTEXT_KEY);
|
|
15927
|
+
if (context) {
|
|
15928
|
+
return trace.getSpan(context);
|
|
16866
15929
|
}
|
|
16867
|
-
|
|
16868
|
-
const attributes = {};
|
|
16869
|
-
if (this._semconvStability & SemconvStability.OLD) {
|
|
16870
|
-
const method = (options.method || 'GET').toUpperCase();
|
|
16871
|
-
name = `HTTP ${method}`;
|
|
16872
|
-
attributes[AttributeNames$3.COMPONENT] = this.moduleName;
|
|
16873
|
-
attributes[ATTR_HTTP_METHOD$1] = method;
|
|
16874
|
-
attributes[ATTR_HTTP_URL$2] = url;
|
|
16875
|
-
}
|
|
16876
|
-
if (this._semconvStability & SemconvStability.STABLE) {
|
|
16877
|
-
const origMethod = options.method;
|
|
16878
|
-
const normMethod = normalizeHttpRequestMethod$1(options.method || 'GET');
|
|
16879
|
-
if (!name) {
|
|
16880
|
-
// The "old" span name wins if emitting both old and stable semconv
|
|
16881
|
-
// ('http/dup').
|
|
16882
|
-
name = normMethod;
|
|
16883
|
-
}
|
|
16884
|
-
attributes[ATTR_HTTP_REQUEST_METHOD] = normMethod;
|
|
16885
|
-
if (normMethod !== origMethod) {
|
|
16886
|
-
attributes[ATTR_HTTP_REQUEST_METHOD_ORIGINAL] = origMethod;
|
|
16887
|
-
}
|
|
16888
|
-
attributes[ATTR_URL_FULL] = url;
|
|
16889
|
-
}
|
|
16890
|
-
return this.tracer.startSpan(name, {
|
|
16891
|
-
kind: SpanKind.CLIENT,
|
|
16892
|
-
attributes,
|
|
16893
|
-
});
|
|
15930
|
+
return context;
|
|
16894
15931
|
}
|
|
16895
15932
|
/**
|
|
16896
|
-
*
|
|
15933
|
+
* Increment number of tasks that are run within the same zone.
|
|
15934
|
+
* This is needed to be able to end span when no more tasks left
|
|
16897
15935
|
* @param span
|
|
16898
|
-
* @param resourcesObserver
|
|
16899
|
-
* @param endTime
|
|
16900
15936
|
*/
|
|
16901
|
-
|
|
16902
|
-
|
|
16903
|
-
if (
|
|
16904
|
-
|
|
16905
|
-
return;
|
|
16906
|
-
}
|
|
16907
|
-
// fallback - either Observer is not available or it took longer
|
|
16908
|
-
// then OBSERVER_WAIT_TIME_MS and observer didn't collect enough
|
|
16909
|
-
// information
|
|
16910
|
-
resources = performance.getEntriesByType('resource');
|
|
16911
|
-
}
|
|
16912
|
-
const resource = getResource(resourcesObserver.spanUrl, resourcesObserver.startTime, endTime, resources, this._usedResources, 'fetch');
|
|
16913
|
-
if (resource.mainRequest) {
|
|
16914
|
-
const mainRequest = resource.mainRequest;
|
|
16915
|
-
this._markResourceAsUsed(mainRequest);
|
|
16916
|
-
const corsPreFlightRequest = resource.corsPreFlightRequest;
|
|
16917
|
-
if (corsPreFlightRequest) {
|
|
16918
|
-
this._addChildSpan(span, corsPreFlightRequest);
|
|
16919
|
-
this._markResourceAsUsed(corsPreFlightRequest);
|
|
16920
|
-
}
|
|
16921
|
-
const skipOldSemconvContentLengthAttrs = !(this._semconvStability & SemconvStability.OLD);
|
|
16922
|
-
addSpanNetworkEvents(span, mainRequest, this.getConfig().ignoreNetworkEvents, undefined, skipOldSemconvContentLengthAttrs);
|
|
15937
|
+
_incrementTask(span) {
|
|
15938
|
+
const spanData = this._spansData.get(span);
|
|
15939
|
+
if (spanData) {
|
|
15940
|
+
spanData.taskCount++;
|
|
16923
15941
|
}
|
|
16924
15942
|
}
|
|
16925
15943
|
/**
|
|
16926
|
-
*
|
|
16927
|
-
* from this is used to add events to span.
|
|
16928
|
-
* This is done to avoid reusing the same resource again for next span
|
|
16929
|
-
* @param resource
|
|
15944
|
+
* Returns true iff we should use the patched callback; false if it's already been patched
|
|
16930
15945
|
*/
|
|
16931
|
-
|
|
16932
|
-
this.
|
|
15946
|
+
addPatchedListener(on, type, listener, wrappedListener) {
|
|
15947
|
+
let listener2Type = this._wrappedListeners.get(listener);
|
|
15948
|
+
if (!listener2Type) {
|
|
15949
|
+
listener2Type = new Map();
|
|
15950
|
+
this._wrappedListeners.set(listener, listener2Type);
|
|
15951
|
+
}
|
|
15952
|
+
let element2patched = listener2Type.get(type);
|
|
15953
|
+
if (!element2patched) {
|
|
15954
|
+
element2patched = new Map();
|
|
15955
|
+
listener2Type.set(type, element2patched);
|
|
15956
|
+
}
|
|
15957
|
+
if (element2patched.has(on)) {
|
|
15958
|
+
return false;
|
|
15959
|
+
}
|
|
15960
|
+
element2patched.set(on, wrappedListener);
|
|
15961
|
+
return true;
|
|
16933
15962
|
}
|
|
16934
15963
|
/**
|
|
16935
|
-
*
|
|
16936
|
-
* @param span
|
|
16937
|
-
* @param spanData
|
|
16938
|
-
* @param response
|
|
15964
|
+
* Returns the patched version of the callback (or undefined)
|
|
16939
15965
|
*/
|
|
16940
|
-
|
|
16941
|
-
const
|
|
16942
|
-
|
|
16943
|
-
|
|
16944
|
-
|
|
16945
|
-
|
|
16946
|
-
|
|
16947
|
-
|
|
16948
|
-
|
|
15966
|
+
removePatchedListener(on, type, listener) {
|
|
15967
|
+
const listener2Type = this._wrappedListeners.get(listener);
|
|
15968
|
+
if (!listener2Type) {
|
|
15969
|
+
return undefined;
|
|
15970
|
+
}
|
|
15971
|
+
const element2patched = listener2Type.get(type);
|
|
15972
|
+
if (!element2patched) {
|
|
15973
|
+
return undefined;
|
|
15974
|
+
}
|
|
15975
|
+
const patched = element2patched.get(on);
|
|
15976
|
+
if (patched) {
|
|
15977
|
+
element2patched.delete(on);
|
|
15978
|
+
if (element2patched.size === 0) {
|
|
15979
|
+
listener2Type.delete(type);
|
|
15980
|
+
if (listener2Type.size === 0) {
|
|
15981
|
+
this._wrappedListeners.delete(listener);
|
|
15982
|
+
}
|
|
16949
15983
|
}
|
|
16950
15984
|
}
|
|
16951
|
-
|
|
16952
|
-
|
|
16953
|
-
|
|
16954
|
-
|
|
16955
|
-
|
|
16956
|
-
|
|
16957
|
-
}
|
|
15985
|
+
return patched;
|
|
15986
|
+
}
|
|
15987
|
+
// utility method to deal with the Function|EventListener nature of addEventListener
|
|
15988
|
+
_invokeListener(listener, target, args) {
|
|
15989
|
+
if (typeof listener === 'function') {
|
|
15990
|
+
return listener.apply(target, args);
|
|
15991
|
+
}
|
|
15992
|
+
else {
|
|
15993
|
+
return listener.handleEvent(args[0]);
|
|
15994
|
+
}
|
|
16958
15995
|
}
|
|
16959
15996
|
/**
|
|
16960
|
-
*
|
|
15997
|
+
* This patches the addEventListener of HTMLElement to be able to
|
|
15998
|
+
* auto instrument the click events
|
|
15999
|
+
* This is done when zone is not available
|
|
16961
16000
|
*/
|
|
16962
|
-
|
|
16963
|
-
|
|
16964
|
-
|
|
16965
|
-
return function
|
|
16966
|
-
|
|
16967
|
-
|
|
16968
|
-
|
|
16969
|
-
const createdSpan = plugin._createSpan(url, options);
|
|
16970
|
-
if (!createdSpan) {
|
|
16971
|
-
return original.apply(this, args);
|
|
16972
|
-
}
|
|
16973
|
-
const spanData = plugin._prepareSpanData(url);
|
|
16974
|
-
if (plugin.getConfig().measureRequestSize) {
|
|
16975
|
-
getFetchBodyLength(...args)
|
|
16976
|
-
.then(bodyLength => {
|
|
16977
|
-
if (!bodyLength)
|
|
16978
|
-
return;
|
|
16979
|
-
if (plugin._semconvStability & SemconvStability.OLD) {
|
|
16980
|
-
createdSpan.setAttribute(ATTR_HTTP_REQUEST_CONTENT_LENGTH_UNCOMPRESSED$1, bodyLength);
|
|
16981
|
-
}
|
|
16982
|
-
if (plugin._semconvStability & SemconvStability.STABLE) {
|
|
16983
|
-
createdSpan.setAttribute(ATTR_HTTP_REQUEST_BODY_SIZE$1, bodyLength);
|
|
16984
|
-
}
|
|
16985
|
-
})
|
|
16986
|
-
.catch(error => {
|
|
16987
|
-
plugin._diag.warn('getFetchBodyLength', error);
|
|
16988
|
-
});
|
|
16989
|
-
}
|
|
16990
|
-
function endSpanOnError(span, error) {
|
|
16991
|
-
plugin._applyAttributesAfterFetch(span, options, error);
|
|
16992
|
-
plugin._endSpan(span, spanData, {
|
|
16993
|
-
status: error.status || 0,
|
|
16994
|
-
statusText: error.message,
|
|
16995
|
-
url,
|
|
16996
|
-
});
|
|
16001
|
+
_patchAddEventListener() {
|
|
16002
|
+
const plugin = this;
|
|
16003
|
+
return (original) => {
|
|
16004
|
+
return function addEventListenerPatched(type, listener, useCapture) {
|
|
16005
|
+
// Forward calls with listener = null
|
|
16006
|
+
if (!listener) {
|
|
16007
|
+
return original.call(this, type, listener, useCapture);
|
|
16997
16008
|
}
|
|
16998
|
-
|
|
16999
|
-
|
|
17000
|
-
|
|
17001
|
-
|
|
16009
|
+
// filter out null (typeof null === 'object')
|
|
16010
|
+
const once = useCapture && typeof useCapture === 'object' && useCapture.once;
|
|
16011
|
+
const patchedListener = function (...args) {
|
|
16012
|
+
let parentSpan;
|
|
16013
|
+
const event = args[0];
|
|
16014
|
+
const target = event?.target;
|
|
16015
|
+
if (event) {
|
|
16016
|
+
parentSpan = plugin._eventsSpanMap.get(event);
|
|
17002
16017
|
}
|
|
17003
|
-
|
|
17004
|
-
plugin.
|
|
17005
|
-
status: response.status,
|
|
17006
|
-
statusText: response.statusText,
|
|
17007
|
-
url,
|
|
17008
|
-
});
|
|
16018
|
+
if (once) {
|
|
16019
|
+
plugin.removePatchedListener(this, type, listener);
|
|
17009
16020
|
}
|
|
17010
|
-
|
|
17011
|
-
|
|
17012
|
-
|
|
17013
|
-
|
|
17014
|
-
const reader = body.getReader();
|
|
17015
|
-
return new ReadableStream({
|
|
17016
|
-
async pull(controller) {
|
|
17017
|
-
try {
|
|
17018
|
-
const { value, done } = await reader.read();
|
|
17019
|
-
if (done) {
|
|
17020
|
-
reader.releaseLock();
|
|
17021
|
-
controller.close();
|
|
17022
|
-
}
|
|
17023
|
-
else {
|
|
17024
|
-
controller.enqueue(value);
|
|
17025
|
-
}
|
|
17026
|
-
}
|
|
17027
|
-
catch (err) {
|
|
17028
|
-
controller.error(err);
|
|
17029
|
-
reader.cancel(err).catch(_ => { });
|
|
17030
|
-
try {
|
|
17031
|
-
reader.releaseLock();
|
|
17032
|
-
}
|
|
17033
|
-
catch {
|
|
17034
|
-
// Spec reference:
|
|
17035
|
-
// https://streams.spec.whatwg.org/#default-reader-release-lock
|
|
17036
|
-
//
|
|
17037
|
-
// releaseLock() only throws if called on an invalid reader
|
|
17038
|
-
// (i.e. reader.[[stream]] is undefined, meaning the lock is already released
|
|
17039
|
-
// or the reader was never associated). In normal use this cannot happen.
|
|
17040
|
-
// This catch is defensive only.
|
|
17041
|
-
}
|
|
17042
|
-
}
|
|
17043
|
-
},
|
|
17044
|
-
cancel(reason) {
|
|
17045
|
-
readerClone.cancel(reason).catch(_ => { });
|
|
17046
|
-
return reader.cancel(reason);
|
|
17047
|
-
},
|
|
17048
|
-
});
|
|
17049
|
-
}
|
|
17050
|
-
function onSuccess(span, resolve, response) {
|
|
17051
|
-
let proxiedResponse = null;
|
|
17052
|
-
try {
|
|
17053
|
-
// TODO: Switch to a consumer-driven model and drop `resClone`.
|
|
17054
|
-
// Keeping eager consumption here to preserve current behavior and avoid breaking existing tests.
|
|
17055
|
-
// Context: discussion in PR #5894 → https://github.com/open-telemetry/opentelemetry-js/pull/5894
|
|
17056
|
-
const resClone = response.clone();
|
|
17057
|
-
const body = resClone.body;
|
|
17058
|
-
if (body) {
|
|
17059
|
-
const reader = body.getReader();
|
|
17060
|
-
const isNullBodyStatus =
|
|
17061
|
-
// 101 responses and protocol upgrading is handled internally by the browser
|
|
17062
|
-
response.status === 204 ||
|
|
17063
|
-
response.status === 205 ||
|
|
17064
|
-
response.status === 304;
|
|
17065
|
-
const wrappedBody = isNullBodyStatus
|
|
17066
|
-
? null
|
|
17067
|
-
: withCancelPropagation(response.body, reader);
|
|
17068
|
-
proxiedResponse = new Response(wrappedBody, {
|
|
17069
|
-
status: response.status,
|
|
17070
|
-
statusText: response.statusText,
|
|
17071
|
-
headers: response.headers,
|
|
17072
|
-
});
|
|
17073
|
-
const read = () => {
|
|
17074
|
-
reader.read().then(({ done }) => {
|
|
17075
|
-
if (done) {
|
|
17076
|
-
endSpanOnSuccess(span, response);
|
|
17077
|
-
}
|
|
17078
|
-
else {
|
|
17079
|
-
read();
|
|
17080
|
-
}
|
|
17081
|
-
}, error => {
|
|
17082
|
-
endSpanOnError(span, error);
|
|
17083
|
-
});
|
|
17084
|
-
};
|
|
17085
|
-
read();
|
|
17086
|
-
}
|
|
17087
|
-
else {
|
|
17088
|
-
// some older browsers don't have .body implemented
|
|
17089
|
-
endSpanOnSuccess(span, response);
|
|
16021
|
+
const span = plugin._createSpan(target, type, parentSpan);
|
|
16022
|
+
if (span) {
|
|
16023
|
+
if (event) {
|
|
16024
|
+
plugin._eventsSpanMap.set(event, span);
|
|
17090
16025
|
}
|
|
16026
|
+
return context.with(trace.setSpan(context.active(), span), () => {
|
|
16027
|
+
const result = plugin._invokeListener(listener, this, args);
|
|
16028
|
+
// no zone so end span immediately
|
|
16029
|
+
span.end();
|
|
16030
|
+
return result;
|
|
16031
|
+
});
|
|
17091
16032
|
}
|
|
17092
|
-
|
|
17093
|
-
|
|
17094
|
-
}
|
|
17095
|
-
}
|
|
17096
|
-
function onError(span, reject, error) {
|
|
17097
|
-
try {
|
|
17098
|
-
endSpanOnError(span, error);
|
|
17099
|
-
}
|
|
17100
|
-
finally {
|
|
17101
|
-
reject(error);
|
|
16033
|
+
else {
|
|
16034
|
+
return plugin._invokeListener(listener, this, args);
|
|
17102
16035
|
}
|
|
16036
|
+
};
|
|
16037
|
+
if (plugin.addPatchedListener(this, type, listener, patchedListener)) {
|
|
16038
|
+
return original.call(this, type, patchedListener, useCapture);
|
|
17103
16039
|
}
|
|
17104
|
-
return new Promise((resolve, reject) => {
|
|
17105
|
-
return context.with(trace.setSpan(context.active(), createdSpan), () => {
|
|
17106
|
-
plugin._addHeaders(options, url);
|
|
17107
|
-
plugin._callRequestHook(createdSpan, options);
|
|
17108
|
-
plugin._tasksCount++;
|
|
17109
|
-
return original
|
|
17110
|
-
.apply(self, options instanceof Request ? [options] : [url, options])
|
|
17111
|
-
.then(onSuccess.bind(self, createdSpan, resolve), onError.bind(self, createdSpan, reject));
|
|
17112
|
-
});
|
|
17113
|
-
});
|
|
17114
16040
|
};
|
|
17115
16041
|
};
|
|
17116
16042
|
}
|
|
17117
|
-
|
|
17118
|
-
|
|
17119
|
-
|
|
17120
|
-
|
|
17121
|
-
|
|
17122
|
-
|
|
16043
|
+
/**
|
|
16044
|
+
* This patches the removeEventListener of HTMLElement to handle the fact that
|
|
16045
|
+
* we patched the original callbacks
|
|
16046
|
+
* This is done when zone is not available
|
|
16047
|
+
*/
|
|
16048
|
+
_patchRemoveEventListener() {
|
|
16049
|
+
const plugin = this;
|
|
16050
|
+
return (original) => {
|
|
16051
|
+
return function removeEventListenerPatched(type, listener, useCapture) {
|
|
16052
|
+
const wrappedListener = plugin.removePatchedListener(this, type, listener);
|
|
16053
|
+
if (wrappedListener) {
|
|
16054
|
+
return original.call(this, type, wrappedListener, useCapture);
|
|
17123
16055
|
}
|
|
17124
|
-
|
|
17125
|
-
|
|
17126
|
-
}
|
|
17127
|
-
}
|
|
17128
|
-
_callRequestHook(span, request) {
|
|
17129
|
-
const requestHook = this.getConfig().requestHook;
|
|
17130
|
-
if (requestHook) {
|
|
17131
|
-
safeExecuteInTheMiddle(() => requestHook(span, request), error => {
|
|
17132
|
-
if (!error) {
|
|
17133
|
-
return;
|
|
16056
|
+
else {
|
|
16057
|
+
return original.call(this, type, listener, useCapture);
|
|
17134
16058
|
}
|
|
17135
|
-
|
|
17136
|
-
|
|
17137
|
-
|
|
16059
|
+
};
|
|
16060
|
+
};
|
|
16061
|
+
}
|
|
16062
|
+
/**
|
|
16063
|
+
* Most browser provide event listener api via EventTarget in prototype chain.
|
|
16064
|
+
* Exception to this is IE 11 which has it on the prototypes closest to EventTarget:
|
|
16065
|
+
*
|
|
16066
|
+
* * - has addEventListener in IE
|
|
16067
|
+
* ** - has addEventListener in all other browsers
|
|
16068
|
+
* ! - missing in IE
|
|
16069
|
+
*
|
|
16070
|
+
* HTMLElement -> Element -> Node * -> EventTarget **! -> Object
|
|
16071
|
+
* Document -> Node * -> EventTarget **! -> Object
|
|
16072
|
+
* Window * -> WindowProperties ! -> EventTarget **! -> Object
|
|
16073
|
+
*/
|
|
16074
|
+
_getPatchableEventTargets() {
|
|
16075
|
+
return window.EventTarget
|
|
16076
|
+
? [EventTarget.prototype]
|
|
16077
|
+
: [Node.prototype, Window.prototype];
|
|
16078
|
+
}
|
|
16079
|
+
/**
|
|
16080
|
+
* Patches the history api
|
|
16081
|
+
*/
|
|
16082
|
+
_patchHistoryApi() {
|
|
16083
|
+
this._unpatchHistoryApi();
|
|
16084
|
+
this._wrap(history, 'replaceState', this._patchHistoryMethod());
|
|
16085
|
+
this._wrap(history, 'pushState', this._patchHistoryMethod());
|
|
16086
|
+
this._wrap(history, 'back', this._patchHistoryMethod());
|
|
16087
|
+
this._wrap(history, 'forward', this._patchHistoryMethod());
|
|
16088
|
+
this._wrap(history, 'go', this._patchHistoryMethod());
|
|
17138
16089
|
}
|
|
17139
16090
|
/**
|
|
17140
|
-
*
|
|
17141
|
-
* resources
|
|
17142
|
-
* @param spanUrl
|
|
16091
|
+
* Patches the certain history api method
|
|
17143
16092
|
*/
|
|
17144
|
-
|
|
17145
|
-
const
|
|
17146
|
-
|
|
17147
|
-
|
|
17148
|
-
|
|
17149
|
-
|
|
17150
|
-
|
|
17151
|
-
|
|
17152
|
-
|
|
17153
|
-
if (entry.initiatorType === 'fetch' && entry.name === spanUrl) {
|
|
17154
|
-
entries.push(entry);
|
|
16093
|
+
_patchHistoryMethod() {
|
|
16094
|
+
const plugin = this;
|
|
16095
|
+
return (original) => {
|
|
16096
|
+
return function patchHistoryMethod(...args) {
|
|
16097
|
+
const url = `${location.pathname}${location.hash}${location.search}`;
|
|
16098
|
+
const result = original.apply(this, args);
|
|
16099
|
+
const urlAfter = `${location.pathname}${location.hash}${location.search}`;
|
|
16100
|
+
if (url !== urlAfter) {
|
|
16101
|
+
plugin._updateInteractionName(urlAfter);
|
|
17155
16102
|
}
|
|
17156
|
-
|
|
17157
|
-
|
|
17158
|
-
|
|
17159
|
-
entryTypes: ['resource'],
|
|
17160
|
-
});
|
|
17161
|
-
return { entries, observer, startTime, spanUrl };
|
|
16103
|
+
return result;
|
|
16104
|
+
};
|
|
16105
|
+
};
|
|
17162
16106
|
}
|
|
17163
16107
|
/**
|
|
17164
|
-
*
|
|
16108
|
+
* unpatch the history api methods
|
|
17165
16109
|
*/
|
|
17166
|
-
|
|
17167
|
-
if (
|
|
17168
|
-
|
|
17169
|
-
|
|
17170
|
-
this.
|
|
17171
|
-
|
|
17172
|
-
|
|
17173
|
-
if (isWrapped(
|
|
17174
|
-
this._unwrap(
|
|
17175
|
-
|
|
17176
|
-
|
|
17177
|
-
this._wrap(_globalThis$1, 'fetch', this._patchConstructor());
|
|
16110
|
+
_unpatchHistoryApi() {
|
|
16111
|
+
if (isWrapped(history.replaceState))
|
|
16112
|
+
this._unwrap(history, 'replaceState');
|
|
16113
|
+
if (isWrapped(history.pushState))
|
|
16114
|
+
this._unwrap(history, 'pushState');
|
|
16115
|
+
if (isWrapped(history.back))
|
|
16116
|
+
this._unwrap(history, 'back');
|
|
16117
|
+
if (isWrapped(history.forward))
|
|
16118
|
+
this._unwrap(history, 'forward');
|
|
16119
|
+
if (isWrapped(history.go))
|
|
16120
|
+
this._unwrap(history, 'go');
|
|
17178
16121
|
}
|
|
17179
16122
|
/**
|
|
17180
|
-
*
|
|
16123
|
+
* Updates interaction span name
|
|
16124
|
+
* @param url
|
|
17181
16125
|
*/
|
|
17182
|
-
|
|
17183
|
-
|
|
17184
|
-
|
|
17185
|
-
|
|
17186
|
-
this._unwrap(_globalThis$1, 'fetch');
|
|
17187
|
-
this._usedResources = new WeakSet();
|
|
17188
|
-
}
|
|
17189
|
-
}
|
|
17190
|
-
|
|
17191
|
-
/*
|
|
17192
|
-
* Copyright The OpenTelemetry Authors
|
|
17193
|
-
*
|
|
17194
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
17195
|
-
* you may not use this file except in compliance with the License.
|
|
17196
|
-
* You may obtain a copy of the License at
|
|
17197
|
-
*
|
|
17198
|
-
* https://www.apache.org/licenses/LICENSE-2.0
|
|
17199
|
-
*
|
|
17200
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
17201
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
17202
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17203
|
-
* See the License for the specific language governing permissions and
|
|
17204
|
-
* limitations under the License.
|
|
17205
|
-
*/
|
|
17206
|
-
/*
|
|
17207
|
-
* This file contains a copy of unstable semantic convention definitions
|
|
17208
|
-
* used by this package.
|
|
17209
|
-
* @see https://github.com/open-telemetry/opentelemetry-js/tree/main/semantic-conventions#unstable-semconv
|
|
17210
|
-
*/
|
|
17211
|
-
/**
|
|
17212
|
-
* Deprecated, use one of `server.address`, `client.address` or `http.request.header.host` instead, depending on the usage.
|
|
17213
|
-
*
|
|
17214
|
-
* @example www.example.org
|
|
17215
|
-
*
|
|
17216
|
-
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
17217
|
-
*
|
|
17218
|
-
* @deprecated Replaced by one of `server.address`, `client.address` or `http.request.header.host`, depending on the usage.
|
|
17219
|
-
*/
|
|
17220
|
-
const ATTR_HTTP_HOST = 'http.host';
|
|
17221
|
-
/**
|
|
17222
|
-
* Deprecated, use `http.request.method` instead.
|
|
17223
|
-
*
|
|
17224
|
-
* @example GET
|
|
17225
|
-
* @example POST
|
|
17226
|
-
* @example HEAD
|
|
17227
|
-
*
|
|
17228
|
-
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
17229
|
-
*
|
|
17230
|
-
* @deprecated Replaced by `http.request.method`.
|
|
17231
|
-
*/
|
|
17232
|
-
const ATTR_HTTP_METHOD = 'http.method';
|
|
17233
|
-
/**
|
|
17234
|
-
* 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.
|
|
17235
|
-
*
|
|
17236
|
-
* @example 3495
|
|
17237
|
-
*
|
|
17238
|
-
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
17239
|
-
*/
|
|
17240
|
-
const ATTR_HTTP_REQUEST_BODY_SIZE = 'http.request.body.size';
|
|
17241
|
-
/**
|
|
17242
|
-
* Deprecated, use `http.request.body.size` instead.
|
|
17243
|
-
*
|
|
17244
|
-
* @example 5493
|
|
17245
|
-
*
|
|
17246
|
-
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
17247
|
-
*
|
|
17248
|
-
* @deprecated Replaced by `http.request.body.size`.
|
|
17249
|
-
*/
|
|
17250
|
-
const ATTR_HTTP_REQUEST_CONTENT_LENGTH_UNCOMPRESSED = 'http.request_content_length_uncompressed';
|
|
17251
|
-
/**
|
|
17252
|
-
* Deprecated, use `url.scheme` instead.
|
|
17253
|
-
*
|
|
17254
|
-
* @example http
|
|
17255
|
-
* @example https
|
|
17256
|
-
*
|
|
17257
|
-
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
17258
|
-
*
|
|
17259
|
-
* @deprecated Replaced by `url.scheme` instead.
|
|
17260
|
-
*/
|
|
17261
|
-
const ATTR_HTTP_SCHEME = 'http.scheme';
|
|
17262
|
-
/**
|
|
17263
|
-
* Deprecated, use `http.response.status_code` instead.
|
|
17264
|
-
*
|
|
17265
|
-
* @example 200
|
|
17266
|
-
*
|
|
17267
|
-
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
17268
|
-
*
|
|
17269
|
-
* @deprecated Replaced by `http.response.status_code`.
|
|
17270
|
-
*/
|
|
17271
|
-
const ATTR_HTTP_STATUS_CODE = 'http.status_code';
|
|
17272
|
-
/**
|
|
17273
|
-
* Deprecated, use `url.full` instead.
|
|
17274
|
-
*
|
|
17275
|
-
* @example https://www.foo.bar/search?q=OpenTelemetry#SemConv
|
|
17276
|
-
*
|
|
17277
|
-
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
17278
|
-
*
|
|
17279
|
-
* @deprecated Replaced by `url.full`.
|
|
17280
|
-
*/
|
|
17281
|
-
const ATTR_HTTP_URL$1 = 'http.url';
|
|
17282
|
-
/**
|
|
17283
|
-
* Deprecated, use `user_agent.original` instead.
|
|
17284
|
-
*
|
|
17285
|
-
* @example CERN-LineMode/2.15 libwww/2.17b3
|
|
17286
|
-
* @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
|
|
17287
|
-
*
|
|
17288
|
-
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
17289
|
-
*
|
|
17290
|
-
* @deprecated Replaced by `user_agent.original`.
|
|
17291
|
-
*/
|
|
17292
|
-
const ATTR_HTTP_USER_AGENT$1 = 'http.user_agent';
|
|
17293
|
-
|
|
17294
|
-
/*
|
|
17295
|
-
* Copyright The OpenTelemetry Authors
|
|
17296
|
-
*
|
|
17297
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
17298
|
-
* you may not use this file except in compliance with the License.
|
|
17299
|
-
* You may obtain a copy of the License at
|
|
17300
|
-
*
|
|
17301
|
-
* https://www.apache.org/licenses/LICENSE-2.0
|
|
17302
|
-
*
|
|
17303
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
17304
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
17305
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17306
|
-
* See the License for the specific language governing permissions and
|
|
17307
|
-
* limitations under the License.
|
|
17308
|
-
*/
|
|
17309
|
-
var EventNames$1;
|
|
17310
|
-
(function (EventNames) {
|
|
17311
|
-
EventNames["METHOD_OPEN"] = "open";
|
|
17312
|
-
EventNames["METHOD_SEND"] = "send";
|
|
17313
|
-
EventNames["EVENT_ABORT"] = "abort";
|
|
17314
|
-
EventNames["EVENT_ERROR"] = "error";
|
|
17315
|
-
EventNames["EVENT_LOAD"] = "loaded";
|
|
17316
|
-
EventNames["EVENT_TIMEOUT"] = "timeout";
|
|
17317
|
-
})(EventNames$1 || (EventNames$1 = {}));
|
|
17318
|
-
|
|
17319
|
-
/*
|
|
17320
|
-
* Copyright The OpenTelemetry Authors
|
|
17321
|
-
*
|
|
17322
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
17323
|
-
* you may not use this file except in compliance with the License.
|
|
17324
|
-
* You may obtain a copy of the License at
|
|
17325
|
-
*
|
|
17326
|
-
* https://www.apache.org/licenses/LICENSE-2.0
|
|
17327
|
-
*
|
|
17328
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
17329
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
17330
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17331
|
-
* See the License for the specific language governing permissions and
|
|
17332
|
-
* limitations under the License.
|
|
17333
|
-
*/
|
|
17334
|
-
// Much of the logic here overlaps with the same utils file in opentelemetry-instrumentation-fetch
|
|
17335
|
-
// These may be unified in the future.
|
|
17336
|
-
const DIAG_LOGGER = diag.createComponentLogger({
|
|
17337
|
-
namespace: '@opentelemetry/opentelemetry-instrumentation-xml-http-request/utils',
|
|
17338
|
-
});
|
|
17339
|
-
function isDocument(value) {
|
|
17340
|
-
return typeof Document !== 'undefined' && value instanceof Document;
|
|
17341
|
-
}
|
|
17342
|
-
/**
|
|
17343
|
-
* Helper function to determine payload content length for XHR requests
|
|
17344
|
-
* @param body
|
|
17345
|
-
* @returns content length
|
|
17346
|
-
*/
|
|
17347
|
-
function getXHRBodyLength(body) {
|
|
17348
|
-
if (isDocument(body)) {
|
|
17349
|
-
return new XMLSerializer().serializeToString(document).length;
|
|
17350
|
-
}
|
|
17351
|
-
// XMLHttpRequestBodyInit expands to the following:
|
|
17352
|
-
if (typeof body === 'string') {
|
|
17353
|
-
return getByteLength(body);
|
|
17354
|
-
}
|
|
17355
|
-
if (body instanceof Blob) {
|
|
17356
|
-
return body.size;
|
|
17357
|
-
}
|
|
17358
|
-
if (body instanceof FormData) {
|
|
17359
|
-
return getFormDataSize(body);
|
|
17360
|
-
}
|
|
17361
|
-
if (body instanceof URLSearchParams) {
|
|
17362
|
-
return getByteLength(body.toString());
|
|
17363
|
-
}
|
|
17364
|
-
// ArrayBuffer | ArrayBufferView
|
|
17365
|
-
if (body.byteLength !== undefined) {
|
|
17366
|
-
return body.byteLength;
|
|
17367
|
-
}
|
|
17368
|
-
DIAG_LOGGER.warn('unknown body type');
|
|
17369
|
-
return undefined;
|
|
17370
|
-
}
|
|
17371
|
-
const TEXT_ENCODER = new TextEncoder();
|
|
17372
|
-
function getByteLength(s) {
|
|
17373
|
-
return TEXT_ENCODER.encode(s).byteLength;
|
|
17374
|
-
}
|
|
17375
|
-
function getFormDataSize(formData) {
|
|
17376
|
-
let size = 0;
|
|
17377
|
-
for (const [key, value] of formData.entries()) {
|
|
17378
|
-
size += key.length;
|
|
17379
|
-
if (value instanceof Blob) {
|
|
17380
|
-
size += value.size;
|
|
17381
|
-
}
|
|
17382
|
-
else {
|
|
17383
|
-
size += value.length;
|
|
17384
|
-
}
|
|
17385
|
-
}
|
|
17386
|
-
return size;
|
|
17387
|
-
}
|
|
17388
|
-
/**
|
|
17389
|
-
* Normalize an HTTP request method string per `http.request.method` spec
|
|
17390
|
-
* https://github.com/open-telemetry/semantic-conventions/blob/main/docs/http/http-spans.md#http-client-span
|
|
17391
|
-
*/
|
|
17392
|
-
function normalizeHttpRequestMethod(method) {
|
|
17393
|
-
const knownMethods = getKnownMethods();
|
|
17394
|
-
const methUpper = method.toUpperCase();
|
|
17395
|
-
if (methUpper in knownMethods) {
|
|
17396
|
-
return methUpper;
|
|
17397
|
-
}
|
|
17398
|
-
else {
|
|
17399
|
-
return '_OTHER';
|
|
17400
|
-
}
|
|
17401
|
-
}
|
|
17402
|
-
const DEFAULT_KNOWN_METHODS = {
|
|
17403
|
-
CONNECT: true,
|
|
17404
|
-
DELETE: true,
|
|
17405
|
-
GET: true,
|
|
17406
|
-
HEAD: true,
|
|
17407
|
-
OPTIONS: true,
|
|
17408
|
-
PATCH: true,
|
|
17409
|
-
POST: true,
|
|
17410
|
-
PUT: true,
|
|
17411
|
-
TRACE: true,
|
|
17412
|
-
};
|
|
17413
|
-
let knownMethods;
|
|
17414
|
-
function getKnownMethods() {
|
|
17415
|
-
if (knownMethods === undefined) {
|
|
17416
|
-
{
|
|
17417
|
-
knownMethods = DEFAULT_KNOWN_METHODS;
|
|
17418
|
-
}
|
|
17419
|
-
}
|
|
17420
|
-
return knownMethods;
|
|
17421
|
-
}
|
|
17422
|
-
const HTTP_PORT_FROM_PROTOCOL = {
|
|
17423
|
-
'https:': '443',
|
|
17424
|
-
'http:': '80',
|
|
17425
|
-
};
|
|
17426
|
-
function serverPortFromUrl(url) {
|
|
17427
|
-
const serverPort = Number(url.port || HTTP_PORT_FROM_PROTOCOL[url.protocol]);
|
|
17428
|
-
// Guard with `if (serverPort)` because `Number('') === 0`.
|
|
17429
|
-
if (serverPort && !isNaN(serverPort)) {
|
|
17430
|
-
return serverPort;
|
|
17431
|
-
}
|
|
17432
|
-
else {
|
|
17433
|
-
return undefined;
|
|
17434
|
-
}
|
|
17435
|
-
}
|
|
17436
|
-
|
|
17437
|
-
/*
|
|
17438
|
-
* Copyright The OpenTelemetry Authors
|
|
17439
|
-
*
|
|
17440
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
17441
|
-
* you may not use this file except in compliance with the License.
|
|
17442
|
-
* You may obtain a copy of the License at
|
|
17443
|
-
*
|
|
17444
|
-
* https://www.apache.org/licenses/LICENSE-2.0
|
|
17445
|
-
*
|
|
17446
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
17447
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
17448
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17449
|
-
* See the License for the specific language governing permissions and
|
|
17450
|
-
* limitations under the License.
|
|
17451
|
-
*/
|
|
17452
|
-
// this is autogenerated file, see scripts/version-update.js
|
|
17453
|
-
const VERSION = '0.208.0';
|
|
17454
|
-
|
|
17455
|
-
/*
|
|
17456
|
-
* Copyright The OpenTelemetry Authors
|
|
17457
|
-
*
|
|
17458
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
17459
|
-
* you may not use this file except in compliance with the License.
|
|
17460
|
-
* You may obtain a copy of the License at
|
|
17461
|
-
*
|
|
17462
|
-
* https://www.apache.org/licenses/LICENSE-2.0
|
|
17463
|
-
*
|
|
17464
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
17465
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
17466
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17467
|
-
* See the License for the specific language governing permissions and
|
|
17468
|
-
* limitations under the License.
|
|
17469
|
-
*/
|
|
17470
|
-
/**
|
|
17471
|
-
* https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/http.md
|
|
17472
|
-
*/
|
|
17473
|
-
var AttributeNames$2;
|
|
17474
|
-
(function (AttributeNames) {
|
|
17475
|
-
AttributeNames["HTTP_STATUS_TEXT"] = "http.status_text";
|
|
17476
|
-
})(AttributeNames$2 || (AttributeNames$2 = {}));
|
|
17477
|
-
|
|
17478
|
-
/*
|
|
17479
|
-
* Copyright The OpenTelemetry Authors
|
|
17480
|
-
*
|
|
17481
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
17482
|
-
* you may not use this file except in compliance with the License.
|
|
17483
|
-
* You may obtain a copy of the License at
|
|
17484
|
-
*
|
|
17485
|
-
* https://www.apache.org/licenses/LICENSE-2.0
|
|
17486
|
-
*
|
|
17487
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
17488
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
17489
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17490
|
-
* See the License for the specific language governing permissions and
|
|
17491
|
-
* limitations under the License.
|
|
17492
|
-
*/
|
|
17493
|
-
// how long to wait for observer to collect information about resources
|
|
17494
|
-
// this is needed as event "load" is called before observer
|
|
17495
|
-
// hard to say how long it should really wait, seems like 300ms is
|
|
17496
|
-
// safe enough
|
|
17497
|
-
const OBSERVER_WAIT_TIME_MS = 300;
|
|
17498
|
-
/**
|
|
17499
|
-
* This class represents a XMLHttpRequest plugin for auto instrumentation
|
|
17500
|
-
*/
|
|
17501
|
-
class XMLHttpRequestInstrumentation extends InstrumentationBase {
|
|
17502
|
-
component = 'xml-http-request';
|
|
17503
|
-
version = VERSION;
|
|
17504
|
-
moduleName = this.component;
|
|
17505
|
-
_tasksCount = 0;
|
|
17506
|
-
_xhrMem = new WeakMap();
|
|
17507
|
-
_usedResources = new WeakSet();
|
|
17508
|
-
_semconvStability;
|
|
17509
|
-
constructor(config = {}) {
|
|
17510
|
-
super('@opentelemetry/instrumentation-xml-http-request', VERSION, config);
|
|
17511
|
-
this._semconvStability = semconvStabilityFromStr('http', config?.semconvStabilityOptIn);
|
|
17512
|
-
}
|
|
17513
|
-
init() { }
|
|
17514
|
-
/**
|
|
17515
|
-
* Adds custom headers to XMLHttpRequest
|
|
17516
|
-
* @param xhr
|
|
17517
|
-
* @param spanUrl
|
|
17518
|
-
* @private
|
|
17519
|
-
*/
|
|
17520
|
-
_addHeaders(xhr, spanUrl) {
|
|
17521
|
-
const url = parseUrl(spanUrl).href;
|
|
17522
|
-
if (!shouldPropagateTraceHeaders(url, this.getConfig().propagateTraceHeaderCorsUrls)) {
|
|
17523
|
-
const headers = {};
|
|
17524
|
-
propagation.inject(context.active(), headers);
|
|
17525
|
-
if (Object.keys(headers).length > 0) {
|
|
17526
|
-
this._diag.debug('headers inject skipped due to CORS policy');
|
|
17527
|
-
}
|
|
17528
|
-
return;
|
|
17529
|
-
}
|
|
17530
|
-
const headers = {};
|
|
17531
|
-
propagation.inject(context.active(), headers);
|
|
17532
|
-
Object.keys(headers).forEach(key => {
|
|
17533
|
-
xhr.setRequestHeader(key, String(headers[key]));
|
|
17534
|
-
});
|
|
17535
|
-
}
|
|
17536
|
-
/**
|
|
17537
|
-
* Add cors pre flight child span
|
|
17538
|
-
* @param span
|
|
17539
|
-
* @param corsPreFlightRequest
|
|
17540
|
-
* @private
|
|
17541
|
-
*/
|
|
17542
|
-
_addChildSpan(span, corsPreFlightRequest) {
|
|
17543
|
-
context.with(trace.setSpan(context.active(), span), () => {
|
|
17544
|
-
const childSpan = this.tracer.startSpan('CORS Preflight', {
|
|
17545
|
-
startTime: corsPreFlightRequest[PerformanceTimingNames.FETCH_START],
|
|
17546
|
-
});
|
|
17547
|
-
const skipOldSemconvContentLengthAttrs = !(this._semconvStability & SemconvStability.OLD);
|
|
17548
|
-
addSpanNetworkEvents(childSpan, corsPreFlightRequest, this.getConfig().ignoreNetworkEvents, undefined, skipOldSemconvContentLengthAttrs);
|
|
17549
|
-
childSpan.end(corsPreFlightRequest[PerformanceTimingNames.RESPONSE_END]);
|
|
17550
|
-
});
|
|
17551
|
-
}
|
|
17552
|
-
/**
|
|
17553
|
-
* Add attributes when span is going to end
|
|
17554
|
-
* @param span
|
|
17555
|
-
* @param xhr
|
|
17556
|
-
* @param spanUrl
|
|
17557
|
-
* @private
|
|
17558
|
-
*/
|
|
17559
|
-
_addFinalSpanAttributes(span, xhrMem, spanUrl) {
|
|
17560
|
-
if (this._semconvStability & SemconvStability.OLD) {
|
|
17561
|
-
if (xhrMem.status !== undefined) {
|
|
17562
|
-
span.setAttribute(ATTR_HTTP_STATUS_CODE, xhrMem.status);
|
|
17563
|
-
}
|
|
17564
|
-
if (xhrMem.statusText !== undefined) {
|
|
17565
|
-
span.setAttribute(AttributeNames$2.HTTP_STATUS_TEXT, xhrMem.statusText);
|
|
17566
|
-
}
|
|
17567
|
-
if (typeof spanUrl === 'string') {
|
|
17568
|
-
const parsedUrl = parseUrl(spanUrl);
|
|
17569
|
-
span.setAttribute(ATTR_HTTP_HOST, parsedUrl.host);
|
|
17570
|
-
span.setAttribute(ATTR_HTTP_SCHEME, parsedUrl.protocol.replace(':', ''));
|
|
17571
|
-
}
|
|
17572
|
-
// @TODO do we want to collect this or it will be collected earlier once only or
|
|
17573
|
-
// maybe when parent span is not available ?
|
|
17574
|
-
span.setAttribute(ATTR_HTTP_USER_AGENT$1, navigator.userAgent);
|
|
17575
|
-
}
|
|
17576
|
-
if (this._semconvStability & SemconvStability.STABLE) {
|
|
17577
|
-
if (xhrMem.status) {
|
|
17578
|
-
// Intentionally exclude status=0, because XHR uses 0 for before a
|
|
17579
|
-
// response is received and semconv says to only add the attribute if
|
|
17580
|
-
// received a response.
|
|
17581
|
-
span.setAttribute(ATTR_HTTP_RESPONSE_STATUS_CODE, xhrMem.status);
|
|
17582
|
-
}
|
|
17583
|
-
}
|
|
17584
|
-
}
|
|
17585
|
-
_applyAttributesAfterXHR(span, xhr) {
|
|
17586
|
-
const applyCustomAttributesOnSpan = this.getConfig().applyCustomAttributesOnSpan;
|
|
17587
|
-
if (typeof applyCustomAttributesOnSpan === 'function') {
|
|
17588
|
-
safeExecuteInTheMiddle(() => applyCustomAttributesOnSpan(span, xhr), error => {
|
|
17589
|
-
if (!error) {
|
|
17590
|
-
return;
|
|
17591
|
-
}
|
|
17592
|
-
this._diag.error('applyCustomAttributesOnSpan', error);
|
|
17593
|
-
});
|
|
17594
|
-
}
|
|
17595
|
-
}
|
|
17596
|
-
/**
|
|
17597
|
-
* will collect information about all resources created
|
|
17598
|
-
* between "send" and "end" with additional waiting for main resource
|
|
17599
|
-
* @param xhr
|
|
17600
|
-
* @param spanUrl
|
|
17601
|
-
* @private
|
|
17602
|
-
*/
|
|
17603
|
-
_addResourceObserver(xhr, spanUrl) {
|
|
17604
|
-
const xhrMem = this._xhrMem.get(xhr);
|
|
17605
|
-
if (!xhrMem ||
|
|
17606
|
-
typeof PerformanceObserver !== 'function' ||
|
|
17607
|
-
typeof PerformanceResourceTiming !== 'function') {
|
|
17608
|
-
return;
|
|
17609
|
-
}
|
|
17610
|
-
xhrMem.createdResources = {
|
|
17611
|
-
observer: new PerformanceObserver(list => {
|
|
17612
|
-
const entries = list.getEntries();
|
|
17613
|
-
const parsedUrl = parseUrl(spanUrl);
|
|
17614
|
-
entries.forEach(entry => {
|
|
17615
|
-
if (entry.initiatorType === 'xmlhttprequest' &&
|
|
17616
|
-
entry.name === parsedUrl.href) {
|
|
17617
|
-
if (xhrMem.createdResources) {
|
|
17618
|
-
xhrMem.createdResources.entries.push(entry);
|
|
17619
|
-
}
|
|
17620
|
-
}
|
|
17621
|
-
});
|
|
17622
|
-
}),
|
|
17623
|
-
entries: [],
|
|
17624
|
-
};
|
|
17625
|
-
xhrMem.createdResources.observer.observe({
|
|
17626
|
-
entryTypes: ['resource'],
|
|
17627
|
-
});
|
|
17628
|
-
}
|
|
17629
|
-
/**
|
|
17630
|
-
* Clears the resource timings and all resources assigned with spans
|
|
17631
|
-
* when {@link XMLHttpRequestInstrumentationConfig.clearTimingResources} is
|
|
17632
|
-
* set to true (default false)
|
|
17633
|
-
* @private
|
|
17634
|
-
*/
|
|
17635
|
-
_clearResources() {
|
|
17636
|
-
if (this._tasksCount === 0 && this.getConfig().clearTimingResources) {
|
|
17637
|
-
otperformance.clearResourceTimings();
|
|
17638
|
-
this._xhrMem = new WeakMap();
|
|
17639
|
-
this._usedResources = new WeakSet();
|
|
17640
|
-
}
|
|
17641
|
-
}
|
|
17642
|
-
/**
|
|
17643
|
-
* Finds appropriate resource and add network events to the span
|
|
17644
|
-
* @param span
|
|
17645
|
-
*/
|
|
17646
|
-
_findResourceAndAddNetworkEvents(xhrMem, span, spanUrl, startTime, endTime) {
|
|
17647
|
-
if (!spanUrl || !startTime || !endTime || !xhrMem.createdResources) {
|
|
17648
|
-
return;
|
|
17649
|
-
}
|
|
17650
|
-
let resources = xhrMem.createdResources.entries;
|
|
17651
|
-
if (!resources || !resources.length) {
|
|
17652
|
-
// fallback - either Observer is not available or it took longer
|
|
17653
|
-
// then OBSERVER_WAIT_TIME_MS and observer didn't collect enough
|
|
17654
|
-
// information
|
|
17655
|
-
// ts thinks this is the perf_hooks module, but it is the browser performance api
|
|
17656
|
-
resources = otperformance.getEntriesByType('resource');
|
|
17657
|
-
}
|
|
17658
|
-
const resource = getResource(parseUrl(spanUrl).href, startTime, endTime, resources, this._usedResources);
|
|
17659
|
-
if (resource.mainRequest) {
|
|
17660
|
-
const mainRequest = resource.mainRequest;
|
|
17661
|
-
this._markResourceAsUsed(mainRequest);
|
|
17662
|
-
const corsPreFlightRequest = resource.corsPreFlightRequest;
|
|
17663
|
-
if (corsPreFlightRequest) {
|
|
17664
|
-
this._addChildSpan(span, corsPreFlightRequest);
|
|
17665
|
-
this._markResourceAsUsed(corsPreFlightRequest);
|
|
17666
|
-
}
|
|
17667
|
-
const skipOldSemconvContentLengthAttrs = !(this._semconvStability & SemconvStability.OLD);
|
|
17668
|
-
addSpanNetworkEvents(span, mainRequest, this.getConfig().ignoreNetworkEvents, undefined, skipOldSemconvContentLengthAttrs);
|
|
16126
|
+
_updateInteractionName(url) {
|
|
16127
|
+
const span = trace.getSpan(context.active());
|
|
16128
|
+
if (span && typeof span.updateName === 'function') {
|
|
16129
|
+
span.updateName(`${EVENT_NAVIGATION_NAME} ${url}`);
|
|
17669
16130
|
}
|
|
17670
16131
|
}
|
|
17671
16132
|
/**
|
|
17672
|
-
*
|
|
17673
|
-
*
|
|
17674
|
-
* @param xhr
|
|
17675
|
-
* @private
|
|
17676
|
-
*/
|
|
17677
|
-
_cleanPreviousSpanInformation(xhr) {
|
|
17678
|
-
const xhrMem = this._xhrMem.get(xhr);
|
|
17679
|
-
if (xhrMem) {
|
|
17680
|
-
const callbackToRemoveEvents = xhrMem.callbackToRemoveEvents;
|
|
17681
|
-
if (callbackToRemoveEvents) {
|
|
17682
|
-
callbackToRemoveEvents();
|
|
17683
|
-
}
|
|
17684
|
-
this._xhrMem.delete(xhr);
|
|
17685
|
-
}
|
|
17686
|
-
}
|
|
17687
|
-
/**
|
|
17688
|
-
* Creates a new span when method "open" is called
|
|
17689
|
-
* @param xhr
|
|
17690
|
-
* @param url
|
|
17691
|
-
* @param method
|
|
17692
|
-
* @private
|
|
17693
|
-
*/
|
|
17694
|
-
_createSpan(xhr, url, method) {
|
|
17695
|
-
if (isUrlIgnored(url, this.getConfig().ignoreUrls)) {
|
|
17696
|
-
this._diag.debug('ignoring span as url matches ignored url');
|
|
17697
|
-
return;
|
|
17698
|
-
}
|
|
17699
|
-
let name = '';
|
|
17700
|
-
const parsedUrl = parseUrl(url);
|
|
17701
|
-
const attributes = {};
|
|
17702
|
-
if (this._semconvStability & SemconvStability.OLD) {
|
|
17703
|
-
name = method.toUpperCase();
|
|
17704
|
-
attributes[ATTR_HTTP_METHOD] = method;
|
|
17705
|
-
attributes[ATTR_HTTP_URL$1] = parsedUrl.toString();
|
|
17706
|
-
}
|
|
17707
|
-
if (this._semconvStability & SemconvStability.STABLE) {
|
|
17708
|
-
const origMethod = method;
|
|
17709
|
-
const normMethod = normalizeHttpRequestMethod(method);
|
|
17710
|
-
if (!name) {
|
|
17711
|
-
// The "old" span name wins if emitting both old and stable semconv
|
|
17712
|
-
// ('http/dup').
|
|
17713
|
-
name = normMethod;
|
|
17714
|
-
}
|
|
17715
|
-
attributes[ATTR_HTTP_REQUEST_METHOD] = normMethod;
|
|
17716
|
-
if (normMethod !== origMethod) {
|
|
17717
|
-
attributes[ATTR_HTTP_REQUEST_METHOD_ORIGINAL] = origMethod;
|
|
17718
|
-
}
|
|
17719
|
-
attributes[ATTR_URL_FULL] = parsedUrl.toString();
|
|
17720
|
-
attributes[ATTR_SERVER_ADDRESS] = parsedUrl.hostname;
|
|
17721
|
-
const serverPort = serverPortFromUrl(parsedUrl);
|
|
17722
|
-
if (serverPort) {
|
|
17723
|
-
attributes[ATTR_SERVER_PORT] = serverPort;
|
|
17724
|
-
}
|
|
17725
|
-
}
|
|
17726
|
-
const currentSpan = this.tracer.startSpan(name, {
|
|
17727
|
-
kind: SpanKind.CLIENT,
|
|
17728
|
-
attributes,
|
|
17729
|
-
});
|
|
17730
|
-
currentSpan.addEvent(EventNames$1.METHOD_OPEN);
|
|
17731
|
-
this._cleanPreviousSpanInformation(xhr);
|
|
17732
|
-
this._xhrMem.set(xhr, {
|
|
17733
|
-
span: currentSpan,
|
|
17734
|
-
spanUrl: url,
|
|
17735
|
-
});
|
|
17736
|
-
return currentSpan;
|
|
17737
|
-
}
|
|
17738
|
-
/**
|
|
17739
|
-
* Marks certain [resource]{@link PerformanceResourceTiming} when information
|
|
17740
|
-
* from this is used to add events to span.
|
|
17741
|
-
* This is done to avoid reusing the same resource again for next span
|
|
17742
|
-
* @param resource
|
|
17743
|
-
* @private
|
|
17744
|
-
*/
|
|
17745
|
-
_markResourceAsUsed(resource) {
|
|
17746
|
-
this._usedResources.add(resource);
|
|
17747
|
-
}
|
|
17748
|
-
/**
|
|
17749
|
-
* Patches the method open
|
|
17750
|
-
* @private
|
|
17751
|
-
*/
|
|
17752
|
-
_patchOpen() {
|
|
17753
|
-
return (original) => {
|
|
17754
|
-
const plugin = this;
|
|
17755
|
-
return function patchOpen(...args) {
|
|
17756
|
-
const method = args[0];
|
|
17757
|
-
const url = args[1];
|
|
17758
|
-
plugin._createSpan(this, url, method);
|
|
17759
|
-
return original.apply(this, args);
|
|
17760
|
-
};
|
|
17761
|
-
};
|
|
17762
|
-
}
|
|
17763
|
-
/**
|
|
17764
|
-
* Patches the method send
|
|
17765
|
-
* @private
|
|
16133
|
+
* Patches zone cancel task - this is done to be able to correctly
|
|
16134
|
+
* decrement the number of remaining tasks
|
|
17766
16135
|
*/
|
|
17767
|
-
|
|
16136
|
+
_patchZoneCancelTask() {
|
|
17768
16137
|
const plugin = this;
|
|
17769
|
-
function endSpanTimeout(eventName, xhrMem, performanceEndTime, endTime) {
|
|
17770
|
-
const callbackToRemoveEvents = xhrMem.callbackToRemoveEvents;
|
|
17771
|
-
if (typeof callbackToRemoveEvents === 'function') {
|
|
17772
|
-
callbackToRemoveEvents();
|
|
17773
|
-
}
|
|
17774
|
-
const { span, spanUrl, sendStartTime } = xhrMem;
|
|
17775
|
-
if (span) {
|
|
17776
|
-
plugin._findResourceAndAddNetworkEvents(xhrMem, span, spanUrl, sendStartTime, performanceEndTime);
|
|
17777
|
-
span.addEvent(eventName, endTime);
|
|
17778
|
-
plugin._addFinalSpanAttributes(span, xhrMem, spanUrl);
|
|
17779
|
-
span.end(endTime);
|
|
17780
|
-
plugin._tasksCount--;
|
|
17781
|
-
}
|
|
17782
|
-
plugin._clearResources();
|
|
17783
|
-
}
|
|
17784
|
-
function endSpan(eventName, xhr, isError, errorType) {
|
|
17785
|
-
const xhrMem = plugin._xhrMem.get(xhr);
|
|
17786
|
-
if (!xhrMem) {
|
|
17787
|
-
return;
|
|
17788
|
-
}
|
|
17789
|
-
xhrMem.status = xhr.status;
|
|
17790
|
-
xhrMem.statusText = xhr.statusText;
|
|
17791
|
-
plugin._xhrMem.delete(xhr);
|
|
17792
|
-
if (xhrMem.span) {
|
|
17793
|
-
const span = xhrMem.span;
|
|
17794
|
-
plugin._applyAttributesAfterXHR(span, xhr);
|
|
17795
|
-
if (plugin._semconvStability & SemconvStability.STABLE) {
|
|
17796
|
-
if (isError) {
|
|
17797
|
-
if (errorType) {
|
|
17798
|
-
span.setStatus({
|
|
17799
|
-
code: SpanStatusCode.ERROR,
|
|
17800
|
-
message: errorType,
|
|
17801
|
-
});
|
|
17802
|
-
span.setAttribute(ATTR_ERROR_TYPE, errorType);
|
|
17803
|
-
}
|
|
17804
|
-
}
|
|
17805
|
-
else if (xhrMem.status && xhrMem.status >= 400) {
|
|
17806
|
-
span.setStatus({ code: SpanStatusCode.ERROR });
|
|
17807
|
-
span.setAttribute(ATTR_ERROR_TYPE, String(xhrMem.status));
|
|
17808
|
-
}
|
|
17809
|
-
}
|
|
17810
|
-
}
|
|
17811
|
-
const performanceEndTime = hrTime();
|
|
17812
|
-
const endTime = Date.now();
|
|
17813
|
-
// the timeout is needed as observer doesn't have yet information
|
|
17814
|
-
// when event "load" is called. Also the time may differ depends on
|
|
17815
|
-
// browser and speed of computer
|
|
17816
|
-
setTimeout(() => {
|
|
17817
|
-
endSpanTimeout(eventName, xhrMem, performanceEndTime, endTime);
|
|
17818
|
-
}, OBSERVER_WAIT_TIME_MS);
|
|
17819
|
-
}
|
|
17820
|
-
function onError() {
|
|
17821
|
-
endSpan(EventNames$1.EVENT_ERROR, this, true, 'error');
|
|
17822
|
-
}
|
|
17823
|
-
function onAbort() {
|
|
17824
|
-
endSpan(EventNames$1.EVENT_ABORT, this, false);
|
|
17825
|
-
}
|
|
17826
|
-
function onTimeout() {
|
|
17827
|
-
endSpan(EventNames$1.EVENT_TIMEOUT, this, true, 'timeout');
|
|
17828
|
-
}
|
|
17829
|
-
function onLoad() {
|
|
17830
|
-
if (this.status < 299) {
|
|
17831
|
-
endSpan(EventNames$1.EVENT_LOAD, this, false);
|
|
17832
|
-
}
|
|
17833
|
-
else {
|
|
17834
|
-
endSpan(EventNames$1.EVENT_ERROR, this, false);
|
|
17835
|
-
}
|
|
17836
|
-
}
|
|
17837
|
-
function unregister(xhr) {
|
|
17838
|
-
xhr.removeEventListener('abort', onAbort);
|
|
17839
|
-
xhr.removeEventListener('error', onError);
|
|
17840
|
-
xhr.removeEventListener('load', onLoad);
|
|
17841
|
-
xhr.removeEventListener('timeout', onTimeout);
|
|
17842
|
-
const xhrMem = plugin._xhrMem.get(xhr);
|
|
17843
|
-
if (xhrMem) {
|
|
17844
|
-
xhrMem.callbackToRemoveEvents = undefined;
|
|
17845
|
-
}
|
|
17846
|
-
}
|
|
17847
16138
|
return (original) => {
|
|
17848
|
-
return function
|
|
17849
|
-
const
|
|
17850
|
-
|
|
17851
|
-
|
|
17852
|
-
|
|
17853
|
-
|
|
17854
|
-
|
|
17855
|
-
|
|
17856
|
-
|
|
17857
|
-
const body = args[0];
|
|
17858
|
-
const bodyLength = getXHRBodyLength(body);
|
|
17859
|
-
if (bodyLength !== undefined) {
|
|
17860
|
-
if (plugin._semconvStability & SemconvStability.OLD) {
|
|
17861
|
-
currentSpan.setAttribute(ATTR_HTTP_REQUEST_CONTENT_LENGTH_UNCOMPRESSED, bodyLength);
|
|
17862
|
-
}
|
|
17863
|
-
if (plugin._semconvStability & SemconvStability.STABLE) {
|
|
17864
|
-
currentSpan.setAttribute(ATTR_HTTP_REQUEST_BODY_SIZE, bodyLength);
|
|
17865
|
-
}
|
|
17866
|
-
}
|
|
17867
|
-
}
|
|
17868
|
-
context.with(trace.setSpan(context.active(), currentSpan), () => {
|
|
17869
|
-
plugin._tasksCount++;
|
|
17870
|
-
xhrMem.sendStartTime = hrTime();
|
|
17871
|
-
currentSpan.addEvent(EventNames$1.METHOD_SEND);
|
|
17872
|
-
this.addEventListener('abort', onAbort);
|
|
17873
|
-
this.addEventListener('error', onError);
|
|
17874
|
-
this.addEventListener('load', onLoad);
|
|
17875
|
-
this.addEventListener('timeout', onTimeout);
|
|
17876
|
-
xhrMem.callbackToRemoveEvents = () => {
|
|
17877
|
-
unregister(this);
|
|
17878
|
-
if (xhrMem.createdResources) {
|
|
17879
|
-
xhrMem.createdResources.observer.disconnect();
|
|
17880
|
-
}
|
|
17881
|
-
};
|
|
17882
|
-
plugin._addHeaders(this, spanUrl);
|
|
17883
|
-
plugin._addResourceObserver(this, spanUrl);
|
|
17884
|
-
});
|
|
17885
|
-
}
|
|
17886
|
-
return original.apply(this, args);
|
|
17887
|
-
};
|
|
17888
|
-
};
|
|
17889
|
-
}
|
|
17890
|
-
/**
|
|
17891
|
-
* implements enable function
|
|
17892
|
-
*/
|
|
17893
|
-
enable() {
|
|
17894
|
-
this._diag.debug('applying patch to', this.moduleName, this.version);
|
|
17895
|
-
if (isWrapped(XMLHttpRequest.prototype.open)) {
|
|
17896
|
-
this._unwrap(XMLHttpRequest.prototype, 'open');
|
|
17897
|
-
this._diag.debug('removing previous patch from method open');
|
|
17898
|
-
}
|
|
17899
|
-
if (isWrapped(XMLHttpRequest.prototype.send)) {
|
|
17900
|
-
this._unwrap(XMLHttpRequest.prototype, 'send');
|
|
17901
|
-
this._diag.debug('removing previous patch from method send');
|
|
17902
|
-
}
|
|
17903
|
-
this._wrap(XMLHttpRequest.prototype, 'open', this._patchOpen());
|
|
17904
|
-
this._wrap(XMLHttpRequest.prototype, 'send', this._patchSend());
|
|
17905
|
-
}
|
|
17906
|
-
/**
|
|
17907
|
-
* implements disable function
|
|
17908
|
-
*/
|
|
17909
|
-
disable() {
|
|
17910
|
-
this._diag.debug('removing patch from', this.moduleName, this.version);
|
|
17911
|
-
this._unwrap(XMLHttpRequest.prototype, 'open');
|
|
17912
|
-
this._unwrap(XMLHttpRequest.prototype, 'send');
|
|
17913
|
-
this._tasksCount = 0;
|
|
17914
|
-
this._xhrMem = new WeakMap();
|
|
17915
|
-
this._usedResources = new WeakSet();
|
|
17916
|
-
}
|
|
17917
|
-
}
|
|
17918
|
-
|
|
17919
|
-
/*
|
|
17920
|
-
* Copyright The OpenTelemetry Authors
|
|
17921
|
-
*
|
|
17922
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
17923
|
-
* you may not use this file except in compliance with the License.
|
|
17924
|
-
* You may obtain a copy of the License at
|
|
17925
|
-
*
|
|
17926
|
-
* https://www.apache.org/licenses/LICENSE-2.0
|
|
17927
|
-
*
|
|
17928
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
17929
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
17930
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17931
|
-
* See the License for the specific language governing permissions and
|
|
17932
|
-
* limitations under the License.
|
|
17933
|
-
*/
|
|
17934
|
-
var AttributeNames$1;
|
|
17935
|
-
(function (AttributeNames) {
|
|
17936
|
-
AttributeNames["EVENT_TYPE"] = "event_type";
|
|
17937
|
-
AttributeNames["TARGET_ELEMENT"] = "target_element";
|
|
17938
|
-
AttributeNames["TARGET_XPATH"] = "target_xpath";
|
|
17939
|
-
AttributeNames["HTTP_URL"] = "http.url";
|
|
17940
|
-
})(AttributeNames$1 || (AttributeNames$1 = {}));
|
|
17941
|
-
|
|
17942
|
-
/*
|
|
17943
|
-
* Copyright The OpenTelemetry Authors
|
|
17944
|
-
*
|
|
17945
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
17946
|
-
* you may not use this file except in compliance with the License.
|
|
17947
|
-
* You may obtain a copy of the License at
|
|
17948
|
-
*
|
|
17949
|
-
* https://www.apache.org/licenses/LICENSE-2.0
|
|
17950
|
-
*
|
|
17951
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
17952
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
17953
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17954
|
-
* See the License for the specific language governing permissions and
|
|
17955
|
-
* limitations under the License.
|
|
17956
|
-
*/
|
|
17957
|
-
// this is autogenerated file, see scripts/version-update.js
|
|
17958
|
-
const PACKAGE_VERSION$1 = '0.53.0';
|
|
17959
|
-
const PACKAGE_NAME$1 = '@opentelemetry/instrumentation-user-interaction';
|
|
17960
|
-
|
|
17961
|
-
/*
|
|
17962
|
-
* Copyright The OpenTelemetry Authors
|
|
17963
|
-
*
|
|
17964
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
17965
|
-
* you may not use this file except in compliance with the License.
|
|
17966
|
-
* You may obtain a copy of the License at
|
|
17967
|
-
*
|
|
17968
|
-
* https://www.apache.org/licenses/LICENSE-2.0
|
|
17969
|
-
*
|
|
17970
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
17971
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
17972
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17973
|
-
* See the License for the specific language governing permissions and
|
|
17974
|
-
* limitations under the License.
|
|
17975
|
-
*/
|
|
17976
|
-
/// <reference types="zone.js" />
|
|
17977
|
-
const ZONE_CONTEXT_KEY = 'OT_ZONE_CONTEXT';
|
|
17978
|
-
const EVENT_NAVIGATION_NAME = 'Navigation:';
|
|
17979
|
-
const DEFAULT_EVENT_NAMES = ['click'];
|
|
17980
|
-
function defaultShouldPreventSpanCreation() {
|
|
17981
|
-
return false;
|
|
17982
|
-
}
|
|
17983
|
-
/**
|
|
17984
|
-
* This class represents a UserInteraction plugin for auto instrumentation.
|
|
17985
|
-
* If zone.js is available then it patches the zone otherwise it patches
|
|
17986
|
-
* addEventListener of HTMLElement
|
|
17987
|
-
*/
|
|
17988
|
-
class UserInteractionInstrumentation extends InstrumentationBase {
|
|
17989
|
-
version = PACKAGE_VERSION$1;
|
|
17990
|
-
moduleName = 'user-interaction';
|
|
17991
|
-
_spansData = new WeakMap();
|
|
17992
|
-
// for addEventListener/removeEventListener state
|
|
17993
|
-
_wrappedListeners = new WeakMap();
|
|
17994
|
-
// for event bubbling
|
|
17995
|
-
_eventsSpanMap = new WeakMap();
|
|
17996
|
-
_eventNames;
|
|
17997
|
-
_shouldPreventSpanCreation;
|
|
17998
|
-
constructor(config = {}) {
|
|
17999
|
-
super(PACKAGE_NAME$1, PACKAGE_VERSION$1, config);
|
|
18000
|
-
this._eventNames = new Set(config?.eventNames ?? DEFAULT_EVENT_NAMES);
|
|
18001
|
-
this._shouldPreventSpanCreation =
|
|
18002
|
-
typeof config?.shouldPreventSpanCreation === 'function'
|
|
18003
|
-
? config.shouldPreventSpanCreation
|
|
18004
|
-
: defaultShouldPreventSpanCreation;
|
|
18005
|
-
}
|
|
18006
|
-
init() { }
|
|
18007
|
-
/**
|
|
18008
|
-
* This will check if last task was timeout and will save the time to
|
|
18009
|
-
* fix the user interaction when nothing happens
|
|
18010
|
-
* This timeout comes from xhr plugin which is needed to collect information
|
|
18011
|
-
* about last xhr main request from observer
|
|
18012
|
-
* @param task
|
|
18013
|
-
* @param span
|
|
18014
|
-
*/
|
|
18015
|
-
_checkForTimeout(task, span) {
|
|
18016
|
-
const spanData = this._spansData.get(span);
|
|
18017
|
-
if (spanData) {
|
|
18018
|
-
if (task.source === 'setTimeout') {
|
|
18019
|
-
spanData.hrTimeLastTimeout = hrTime();
|
|
18020
|
-
}
|
|
18021
|
-
else if (task.source !== 'Promise.then' &&
|
|
18022
|
-
task.source !== 'setTimeout') {
|
|
18023
|
-
spanData.hrTimeLastTimeout = undefined;
|
|
18024
|
-
}
|
|
18025
|
-
}
|
|
18026
|
-
}
|
|
18027
|
-
/**
|
|
18028
|
-
* Controls whether or not to create a span, based on the event type.
|
|
18029
|
-
*/
|
|
18030
|
-
_allowEventName(eventName) {
|
|
18031
|
-
return this._eventNames.has(eventName);
|
|
18032
|
-
}
|
|
18033
|
-
/**
|
|
18034
|
-
* Creates a new span
|
|
18035
|
-
* @param element
|
|
18036
|
-
* @param eventName
|
|
18037
|
-
* @param parentSpan
|
|
18038
|
-
*/
|
|
18039
|
-
_createSpan(element, eventName, parentSpan) {
|
|
18040
|
-
if (!(element instanceof HTMLElement)) {
|
|
18041
|
-
return undefined;
|
|
18042
|
-
}
|
|
18043
|
-
if (!element.getAttribute) {
|
|
18044
|
-
return undefined;
|
|
18045
|
-
}
|
|
18046
|
-
if (element.hasAttribute('disabled')) {
|
|
18047
|
-
return undefined;
|
|
18048
|
-
}
|
|
18049
|
-
if (!this._allowEventName(eventName)) {
|
|
18050
|
-
return undefined;
|
|
18051
|
-
}
|
|
18052
|
-
const xpath = getElementXPath(element, true);
|
|
18053
|
-
try {
|
|
18054
|
-
const span = this.tracer.startSpan(eventName, {
|
|
18055
|
-
attributes: {
|
|
18056
|
-
[AttributeNames$1.EVENT_TYPE]: eventName,
|
|
18057
|
-
[AttributeNames$1.TARGET_ELEMENT]: element.tagName,
|
|
18058
|
-
[AttributeNames$1.TARGET_XPATH]: xpath,
|
|
18059
|
-
[AttributeNames$1.HTTP_URL]: window.location.href,
|
|
18060
|
-
},
|
|
18061
|
-
}, parentSpan
|
|
18062
|
-
? trace.setSpan(context.active(), parentSpan)
|
|
18063
|
-
: undefined);
|
|
18064
|
-
if (this._shouldPreventSpanCreation(eventName, element, span) === true) {
|
|
18065
|
-
return undefined;
|
|
18066
|
-
}
|
|
18067
|
-
this._spansData.set(span, {
|
|
18068
|
-
taskCount: 0,
|
|
18069
|
-
});
|
|
18070
|
-
return span;
|
|
18071
|
-
}
|
|
18072
|
-
catch (e) {
|
|
18073
|
-
this._diag.error('failed to start create new user interaction span', e);
|
|
18074
|
-
}
|
|
18075
|
-
return undefined;
|
|
18076
|
-
}
|
|
18077
|
-
/**
|
|
18078
|
-
* Decrement number of tasks that left in zone,
|
|
18079
|
-
* This is needed to be able to end span when no more tasks left
|
|
18080
|
-
* @param span
|
|
18081
|
-
*/
|
|
18082
|
-
_decrementTask(span) {
|
|
18083
|
-
const spanData = this._spansData.get(span);
|
|
18084
|
-
if (spanData) {
|
|
18085
|
-
spanData.taskCount--;
|
|
18086
|
-
if (spanData.taskCount === 0) {
|
|
18087
|
-
this._tryToEndSpan(span, spanData.hrTimeLastTimeout);
|
|
18088
|
-
}
|
|
18089
|
-
}
|
|
18090
|
-
}
|
|
18091
|
-
/**
|
|
18092
|
-
* Return the current span
|
|
18093
|
-
* @param zone
|
|
18094
|
-
* @private
|
|
18095
|
-
*/
|
|
18096
|
-
_getCurrentSpan(zone) {
|
|
18097
|
-
const context = zone.get(ZONE_CONTEXT_KEY);
|
|
18098
|
-
if (context) {
|
|
18099
|
-
return trace.getSpan(context);
|
|
18100
|
-
}
|
|
18101
|
-
return context;
|
|
18102
|
-
}
|
|
18103
|
-
/**
|
|
18104
|
-
* Increment number of tasks that are run within the same zone.
|
|
18105
|
-
* This is needed to be able to end span when no more tasks left
|
|
18106
|
-
* @param span
|
|
18107
|
-
*/
|
|
18108
|
-
_incrementTask(span) {
|
|
18109
|
-
const spanData = this._spansData.get(span);
|
|
18110
|
-
if (spanData) {
|
|
18111
|
-
spanData.taskCount++;
|
|
18112
|
-
}
|
|
18113
|
-
}
|
|
18114
|
-
/**
|
|
18115
|
-
* Returns true iff we should use the patched callback; false if it's already been patched
|
|
18116
|
-
*/
|
|
18117
|
-
addPatchedListener(on, type, listener, wrappedListener) {
|
|
18118
|
-
let listener2Type = this._wrappedListeners.get(listener);
|
|
18119
|
-
if (!listener2Type) {
|
|
18120
|
-
listener2Type = new Map();
|
|
18121
|
-
this._wrappedListeners.set(listener, listener2Type);
|
|
18122
|
-
}
|
|
18123
|
-
let element2patched = listener2Type.get(type);
|
|
18124
|
-
if (!element2patched) {
|
|
18125
|
-
element2patched = new Map();
|
|
18126
|
-
listener2Type.set(type, element2patched);
|
|
18127
|
-
}
|
|
18128
|
-
if (element2patched.has(on)) {
|
|
18129
|
-
return false;
|
|
18130
|
-
}
|
|
18131
|
-
element2patched.set(on, wrappedListener);
|
|
18132
|
-
return true;
|
|
18133
|
-
}
|
|
18134
|
-
/**
|
|
18135
|
-
* Returns the patched version of the callback (or undefined)
|
|
18136
|
-
*/
|
|
18137
|
-
removePatchedListener(on, type, listener) {
|
|
18138
|
-
const listener2Type = this._wrappedListeners.get(listener);
|
|
18139
|
-
if (!listener2Type) {
|
|
18140
|
-
return undefined;
|
|
18141
|
-
}
|
|
18142
|
-
const element2patched = listener2Type.get(type);
|
|
18143
|
-
if (!element2patched) {
|
|
18144
|
-
return undefined;
|
|
18145
|
-
}
|
|
18146
|
-
const patched = element2patched.get(on);
|
|
18147
|
-
if (patched) {
|
|
18148
|
-
element2patched.delete(on);
|
|
18149
|
-
if (element2patched.size === 0) {
|
|
18150
|
-
listener2Type.delete(type);
|
|
18151
|
-
if (listener2Type.size === 0) {
|
|
18152
|
-
this._wrappedListeners.delete(listener);
|
|
18153
|
-
}
|
|
18154
|
-
}
|
|
18155
|
-
}
|
|
18156
|
-
return patched;
|
|
18157
|
-
}
|
|
18158
|
-
// utility method to deal with the Function|EventListener nature of addEventListener
|
|
18159
|
-
_invokeListener(listener, target, args) {
|
|
18160
|
-
if (typeof listener === 'function') {
|
|
18161
|
-
return listener.apply(target, args);
|
|
18162
|
-
}
|
|
18163
|
-
else {
|
|
18164
|
-
return listener.handleEvent(args[0]);
|
|
18165
|
-
}
|
|
18166
|
-
}
|
|
18167
|
-
/**
|
|
18168
|
-
* This patches the addEventListener of HTMLElement to be able to
|
|
18169
|
-
* auto instrument the click events
|
|
18170
|
-
* This is done when zone is not available
|
|
18171
|
-
*/
|
|
18172
|
-
_patchAddEventListener() {
|
|
18173
|
-
const plugin = this;
|
|
18174
|
-
return (original) => {
|
|
18175
|
-
return function addEventListenerPatched(type, listener, useCapture) {
|
|
18176
|
-
// Forward calls with listener = null
|
|
18177
|
-
if (!listener) {
|
|
18178
|
-
return original.call(this, type, listener, useCapture);
|
|
18179
|
-
}
|
|
18180
|
-
// filter out null (typeof null === 'object')
|
|
18181
|
-
const once = useCapture && typeof useCapture === 'object' && useCapture.once;
|
|
18182
|
-
const patchedListener = function (...args) {
|
|
18183
|
-
let parentSpan;
|
|
18184
|
-
const event = args[0];
|
|
18185
|
-
const target = event?.target;
|
|
18186
|
-
if (event) {
|
|
18187
|
-
parentSpan = plugin._eventsSpanMap.get(event);
|
|
18188
|
-
}
|
|
18189
|
-
if (once) {
|
|
18190
|
-
plugin.removePatchedListener(this, type, listener);
|
|
18191
|
-
}
|
|
18192
|
-
const span = plugin._createSpan(target, type, parentSpan);
|
|
18193
|
-
if (span) {
|
|
18194
|
-
if (event) {
|
|
18195
|
-
plugin._eventsSpanMap.set(event, span);
|
|
18196
|
-
}
|
|
18197
|
-
return context.with(trace.setSpan(context.active(), span), () => {
|
|
18198
|
-
const result = plugin._invokeListener(listener, this, args);
|
|
18199
|
-
// no zone so end span immediately
|
|
18200
|
-
span.end();
|
|
18201
|
-
return result;
|
|
18202
|
-
});
|
|
18203
|
-
}
|
|
18204
|
-
else {
|
|
18205
|
-
return plugin._invokeListener(listener, this, args);
|
|
18206
|
-
}
|
|
18207
|
-
};
|
|
18208
|
-
if (plugin.addPatchedListener(this, type, listener, patchedListener)) {
|
|
18209
|
-
return original.call(this, type, patchedListener, useCapture);
|
|
18210
|
-
}
|
|
18211
|
-
};
|
|
18212
|
-
};
|
|
18213
|
-
}
|
|
18214
|
-
/**
|
|
18215
|
-
* This patches the removeEventListener of HTMLElement to handle the fact that
|
|
18216
|
-
* we patched the original callbacks
|
|
18217
|
-
* This is done when zone is not available
|
|
18218
|
-
*/
|
|
18219
|
-
_patchRemoveEventListener() {
|
|
18220
|
-
const plugin = this;
|
|
18221
|
-
return (original) => {
|
|
18222
|
-
return function removeEventListenerPatched(type, listener, useCapture) {
|
|
18223
|
-
const wrappedListener = plugin.removePatchedListener(this, type, listener);
|
|
18224
|
-
if (wrappedListener) {
|
|
18225
|
-
return original.call(this, type, wrappedListener, useCapture);
|
|
18226
|
-
}
|
|
18227
|
-
else {
|
|
18228
|
-
return original.call(this, type, listener, useCapture);
|
|
18229
|
-
}
|
|
18230
|
-
};
|
|
18231
|
-
};
|
|
18232
|
-
}
|
|
18233
|
-
/**
|
|
18234
|
-
* Most browser provide event listener api via EventTarget in prototype chain.
|
|
18235
|
-
* Exception to this is IE 11 which has it on the prototypes closest to EventTarget:
|
|
18236
|
-
*
|
|
18237
|
-
* * - has addEventListener in IE
|
|
18238
|
-
* ** - has addEventListener in all other browsers
|
|
18239
|
-
* ! - missing in IE
|
|
18240
|
-
*
|
|
18241
|
-
* HTMLElement -> Element -> Node * -> EventTarget **! -> Object
|
|
18242
|
-
* Document -> Node * -> EventTarget **! -> Object
|
|
18243
|
-
* Window * -> WindowProperties ! -> EventTarget **! -> Object
|
|
18244
|
-
*/
|
|
18245
|
-
_getPatchableEventTargets() {
|
|
18246
|
-
return window.EventTarget
|
|
18247
|
-
? [EventTarget.prototype]
|
|
18248
|
-
: [Node.prototype, Window.prototype];
|
|
18249
|
-
}
|
|
18250
|
-
/**
|
|
18251
|
-
* Patches the history api
|
|
18252
|
-
*/
|
|
18253
|
-
_patchHistoryApi() {
|
|
18254
|
-
this._unpatchHistoryApi();
|
|
18255
|
-
this._wrap(history, 'replaceState', this._patchHistoryMethod());
|
|
18256
|
-
this._wrap(history, 'pushState', this._patchHistoryMethod());
|
|
18257
|
-
this._wrap(history, 'back', this._patchHistoryMethod());
|
|
18258
|
-
this._wrap(history, 'forward', this._patchHistoryMethod());
|
|
18259
|
-
this._wrap(history, 'go', this._patchHistoryMethod());
|
|
18260
|
-
}
|
|
18261
|
-
/**
|
|
18262
|
-
* Patches the certain history api method
|
|
18263
|
-
*/
|
|
18264
|
-
_patchHistoryMethod() {
|
|
18265
|
-
const plugin = this;
|
|
18266
|
-
return (original) => {
|
|
18267
|
-
return function patchHistoryMethod(...args) {
|
|
18268
|
-
const url = `${location.pathname}${location.hash}${location.search}`;
|
|
18269
|
-
const result = original.apply(this, args);
|
|
18270
|
-
const urlAfter = `${location.pathname}${location.hash}${location.search}`;
|
|
18271
|
-
if (url !== urlAfter) {
|
|
18272
|
-
plugin._updateInteractionName(urlAfter);
|
|
18273
|
-
}
|
|
18274
|
-
return result;
|
|
18275
|
-
};
|
|
18276
|
-
};
|
|
18277
|
-
}
|
|
18278
|
-
/**
|
|
18279
|
-
* unpatch the history api methods
|
|
18280
|
-
*/
|
|
18281
|
-
_unpatchHistoryApi() {
|
|
18282
|
-
if (isWrapped(history.replaceState))
|
|
18283
|
-
this._unwrap(history, 'replaceState');
|
|
18284
|
-
if (isWrapped(history.pushState))
|
|
18285
|
-
this._unwrap(history, 'pushState');
|
|
18286
|
-
if (isWrapped(history.back))
|
|
18287
|
-
this._unwrap(history, 'back');
|
|
18288
|
-
if (isWrapped(history.forward))
|
|
18289
|
-
this._unwrap(history, 'forward');
|
|
18290
|
-
if (isWrapped(history.go))
|
|
18291
|
-
this._unwrap(history, 'go');
|
|
18292
|
-
}
|
|
18293
|
-
/**
|
|
18294
|
-
* Updates interaction span name
|
|
18295
|
-
* @param url
|
|
18296
|
-
*/
|
|
18297
|
-
_updateInteractionName(url) {
|
|
18298
|
-
const span = trace.getSpan(context.active());
|
|
18299
|
-
if (span && typeof span.updateName === 'function') {
|
|
18300
|
-
span.updateName(`${EVENT_NAVIGATION_NAME} ${url}`);
|
|
18301
|
-
}
|
|
18302
|
-
}
|
|
18303
|
-
/**
|
|
18304
|
-
* Patches zone cancel task - this is done to be able to correctly
|
|
18305
|
-
* decrement the number of remaining tasks
|
|
18306
|
-
*/
|
|
18307
|
-
_patchZoneCancelTask() {
|
|
18308
|
-
const plugin = this;
|
|
18309
|
-
return (original) => {
|
|
18310
|
-
return function patchCancelTask(task) {
|
|
18311
|
-
const currentZone = Zone.current;
|
|
18312
|
-
const currentSpan = plugin._getCurrentSpan(currentZone);
|
|
18313
|
-
if (currentSpan && plugin._shouldCountTask(task, currentZone)) {
|
|
18314
|
-
plugin._decrementTask(currentSpan);
|
|
18315
|
-
}
|
|
18316
|
-
return original.call(this, task);
|
|
18317
|
-
};
|
|
18318
|
-
};
|
|
18319
|
-
}
|
|
18320
|
-
/**
|
|
18321
|
-
* Patches zone schedule task - this is done to be able to correctly
|
|
18322
|
-
* increment the number of tasks running within current zone but also to
|
|
18323
|
-
* save time in case of timeout running from xhr plugin when waiting for
|
|
18324
|
-
* main request from PerformanceResourceTiming
|
|
18325
|
-
*/
|
|
18326
|
-
_patchZoneScheduleTask() {
|
|
18327
|
-
const plugin = this;
|
|
18328
|
-
return (original) => {
|
|
18329
|
-
return function patchScheduleTask(task) {
|
|
18330
|
-
const currentZone = Zone.current;
|
|
18331
|
-
const currentSpan = plugin._getCurrentSpan(currentZone);
|
|
18332
|
-
if (currentSpan && plugin._shouldCountTask(task, currentZone)) {
|
|
18333
|
-
plugin._incrementTask(currentSpan);
|
|
18334
|
-
plugin._checkForTimeout(task, currentSpan);
|
|
18335
|
-
}
|
|
18336
|
-
return original.call(this, task);
|
|
18337
|
-
};
|
|
18338
|
-
};
|
|
18339
|
-
}
|
|
18340
|
-
/**
|
|
18341
|
-
* Patches zone run task - this is done to be able to create a span when
|
|
18342
|
-
* user interaction starts
|
|
18343
|
-
* @private
|
|
18344
|
-
*/
|
|
18345
|
-
_patchZoneRunTask() {
|
|
18346
|
-
const plugin = this;
|
|
18347
|
-
return (original) => {
|
|
18348
|
-
return function patchRunTask(task, applyThis, applyArgs) {
|
|
18349
|
-
const event = Array.isArray(applyArgs) && applyArgs[0] instanceof Event
|
|
18350
|
-
? applyArgs[0]
|
|
18351
|
-
: undefined;
|
|
18352
|
-
const target = event?.target;
|
|
18353
|
-
let span;
|
|
18354
|
-
const activeZone = this;
|
|
18355
|
-
if (target) {
|
|
18356
|
-
span = plugin._createSpan(target, task.eventName);
|
|
18357
|
-
if (span) {
|
|
18358
|
-
plugin._incrementTask(span);
|
|
18359
|
-
return activeZone.run(() => {
|
|
18360
|
-
try {
|
|
18361
|
-
return context.with(trace.setSpan(context.active(), span), () => {
|
|
18362
|
-
const currentZone = Zone.current;
|
|
18363
|
-
task._zone = currentZone;
|
|
18364
|
-
return original.call(currentZone, task, applyThis, applyArgs);
|
|
18365
|
-
});
|
|
18366
|
-
}
|
|
18367
|
-
finally {
|
|
18368
|
-
plugin._decrementTask(span);
|
|
18369
|
-
}
|
|
18370
|
-
});
|
|
18371
|
-
}
|
|
18372
|
-
}
|
|
18373
|
-
else {
|
|
18374
|
-
span = plugin._getCurrentSpan(activeZone);
|
|
18375
|
-
}
|
|
18376
|
-
try {
|
|
18377
|
-
return original.call(activeZone, task, applyThis, applyArgs);
|
|
18378
|
-
}
|
|
18379
|
-
finally {
|
|
18380
|
-
if (span && plugin._shouldCountTask(task, activeZone)) {
|
|
18381
|
-
plugin._decrementTask(span);
|
|
18382
|
-
}
|
|
18383
|
-
}
|
|
18384
|
-
};
|
|
18385
|
-
};
|
|
18386
|
-
}
|
|
18387
|
-
/**
|
|
18388
|
-
* Decides if task should be counted.
|
|
18389
|
-
* @param task
|
|
18390
|
-
* @param currentZone
|
|
18391
|
-
* @private
|
|
18392
|
-
*/
|
|
18393
|
-
_shouldCountTask(task, currentZone) {
|
|
18394
|
-
if (task._zone) {
|
|
18395
|
-
currentZone = task._zone;
|
|
18396
|
-
}
|
|
18397
|
-
if (!currentZone || !task.data || task.data.isPeriodic) {
|
|
18398
|
-
return false;
|
|
18399
|
-
}
|
|
18400
|
-
const currentSpan = this._getCurrentSpan(currentZone);
|
|
18401
|
-
if (!currentSpan) {
|
|
18402
|
-
return false;
|
|
18403
|
-
}
|
|
18404
|
-
if (!this._spansData.get(currentSpan)) {
|
|
18405
|
-
return false;
|
|
18406
|
-
}
|
|
18407
|
-
return task.type === 'macroTask' || task.type === 'microTask';
|
|
18408
|
-
}
|
|
18409
|
-
/**
|
|
18410
|
-
* Will try to end span when such span still exists.
|
|
18411
|
-
* @param span
|
|
18412
|
-
* @param endTime
|
|
18413
|
-
* @private
|
|
18414
|
-
*/
|
|
18415
|
-
_tryToEndSpan(span, endTime) {
|
|
18416
|
-
if (span) {
|
|
18417
|
-
const spanData = this._spansData.get(span);
|
|
18418
|
-
if (spanData) {
|
|
18419
|
-
span.end(endTime);
|
|
18420
|
-
this._spansData.delete(span);
|
|
18421
|
-
}
|
|
18422
|
-
}
|
|
18423
|
-
}
|
|
18424
|
-
/**
|
|
18425
|
-
* implements enable function
|
|
18426
|
-
*/
|
|
18427
|
-
enable() {
|
|
18428
|
-
const ZoneWithPrototype = this._getZoneWithPrototype();
|
|
18429
|
-
this._diag.debug('applying patch to', this.moduleName, this.version, 'zone:', !!ZoneWithPrototype);
|
|
18430
|
-
if (ZoneWithPrototype) {
|
|
18431
|
-
if (isWrapped(ZoneWithPrototype.prototype.runTask)) {
|
|
18432
|
-
this._unwrap(ZoneWithPrototype.prototype, 'runTask');
|
|
18433
|
-
this._diag.debug('removing previous patch from method runTask');
|
|
18434
|
-
}
|
|
18435
|
-
if (isWrapped(ZoneWithPrototype.prototype.scheduleTask)) {
|
|
18436
|
-
this._unwrap(ZoneWithPrototype.prototype, 'scheduleTask');
|
|
18437
|
-
this._diag.debug('removing previous patch from method scheduleTask');
|
|
18438
|
-
}
|
|
18439
|
-
if (isWrapped(ZoneWithPrototype.prototype.cancelTask)) {
|
|
18440
|
-
this._unwrap(ZoneWithPrototype.prototype, 'cancelTask');
|
|
18441
|
-
this._diag.debug('removing previous patch from method cancelTask');
|
|
18442
|
-
}
|
|
18443
|
-
this._zonePatched = true;
|
|
18444
|
-
this._wrap(ZoneWithPrototype.prototype, 'runTask', this._patchZoneRunTask());
|
|
18445
|
-
this._wrap(ZoneWithPrototype.prototype, 'scheduleTask', this._patchZoneScheduleTask());
|
|
18446
|
-
this._wrap(ZoneWithPrototype.prototype, 'cancelTask', this._patchZoneCancelTask());
|
|
18447
|
-
}
|
|
18448
|
-
else {
|
|
18449
|
-
this._zonePatched = false;
|
|
18450
|
-
const targets = this._getPatchableEventTargets();
|
|
18451
|
-
targets.forEach(target => {
|
|
18452
|
-
if (isWrapped(target.addEventListener)) {
|
|
18453
|
-
this._unwrap(target, 'addEventListener');
|
|
18454
|
-
this._diag.debug('removing previous patch from method addEventListener');
|
|
18455
|
-
}
|
|
18456
|
-
if (isWrapped(target.removeEventListener)) {
|
|
18457
|
-
this._unwrap(target, 'removeEventListener');
|
|
18458
|
-
this._diag.debug('removing previous patch from method removeEventListener');
|
|
18459
|
-
}
|
|
18460
|
-
this._wrap(target, 'addEventListener', this._patchAddEventListener());
|
|
18461
|
-
this._wrap(target, 'removeEventListener', this._patchRemoveEventListener());
|
|
18462
|
-
});
|
|
18463
|
-
}
|
|
18464
|
-
this._patchHistoryApi();
|
|
18465
|
-
}
|
|
18466
|
-
/**
|
|
18467
|
-
* implements unpatch function
|
|
18468
|
-
*/
|
|
18469
|
-
disable() {
|
|
18470
|
-
const ZoneWithPrototype = this._getZoneWithPrototype();
|
|
18471
|
-
this._diag.debug('removing patch from', this.moduleName, this.version, 'zone:', !!ZoneWithPrototype);
|
|
18472
|
-
if (ZoneWithPrototype && this._zonePatched) {
|
|
18473
|
-
if (isWrapped(ZoneWithPrototype.prototype.runTask)) {
|
|
18474
|
-
this._unwrap(ZoneWithPrototype.prototype, 'runTask');
|
|
18475
|
-
}
|
|
18476
|
-
if (isWrapped(ZoneWithPrototype.prototype.scheduleTask)) {
|
|
18477
|
-
this._unwrap(ZoneWithPrototype.prototype, 'scheduleTask');
|
|
18478
|
-
}
|
|
18479
|
-
if (isWrapped(ZoneWithPrototype.prototype.cancelTask)) {
|
|
18480
|
-
this._unwrap(ZoneWithPrototype.prototype, 'cancelTask');
|
|
18481
|
-
}
|
|
18482
|
-
}
|
|
18483
|
-
else {
|
|
18484
|
-
const targets = this._getPatchableEventTargets();
|
|
18485
|
-
targets.forEach(target => {
|
|
18486
|
-
if (isWrapped(target.addEventListener)) {
|
|
18487
|
-
this._unwrap(target, 'addEventListener');
|
|
18488
|
-
}
|
|
18489
|
-
if (isWrapped(target.removeEventListener)) {
|
|
18490
|
-
this._unwrap(target, 'removeEventListener');
|
|
18491
|
-
}
|
|
18492
|
-
});
|
|
18493
|
-
}
|
|
18494
|
-
this._unpatchHistoryApi();
|
|
18495
|
-
}
|
|
18496
|
-
/**
|
|
18497
|
-
* returns Zone
|
|
18498
|
-
*/
|
|
18499
|
-
_getZoneWithPrototype() {
|
|
18500
|
-
const _window = window;
|
|
18501
|
-
return _window.Zone;
|
|
18502
|
-
}
|
|
18503
|
-
}
|
|
18504
|
-
|
|
18505
|
-
/*
|
|
18506
|
-
* Copyright The OpenTelemetry Authors
|
|
18507
|
-
*
|
|
18508
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
18509
|
-
* you may not use this file except in compliance with the License.
|
|
18510
|
-
* You may obtain a copy of the License at
|
|
18511
|
-
*
|
|
18512
|
-
* https://www.apache.org/licenses/LICENSE-2.0
|
|
18513
|
-
*
|
|
18514
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
18515
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
18516
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18517
|
-
* See the License for the specific language governing permissions and
|
|
18518
|
-
* limitations under the License.
|
|
18519
|
-
*/
|
|
18520
|
-
var AttributeNames;
|
|
18521
|
-
(function (AttributeNames) {
|
|
18522
|
-
AttributeNames["DOCUMENT_LOAD"] = "documentLoad";
|
|
18523
|
-
AttributeNames["DOCUMENT_FETCH"] = "documentFetch";
|
|
18524
|
-
AttributeNames["RESOURCE_FETCH"] = "resourceFetch";
|
|
18525
|
-
})(AttributeNames || (AttributeNames = {}));
|
|
18526
|
-
|
|
18527
|
-
/*
|
|
18528
|
-
* Copyright The OpenTelemetry Authors
|
|
18529
|
-
*
|
|
18530
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
18531
|
-
* you may not use this file except in compliance with the License.
|
|
18532
|
-
* You may obtain a copy of the License at
|
|
18533
|
-
*
|
|
18534
|
-
* https://www.apache.org/licenses/LICENSE-2.0
|
|
18535
|
-
*
|
|
18536
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
18537
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
18538
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18539
|
-
* See the License for the specific language governing permissions and
|
|
18540
|
-
* limitations under the License.
|
|
18541
|
-
*/
|
|
18542
|
-
// this is autogenerated file, see scripts/version-update.js
|
|
18543
|
-
const PACKAGE_VERSION = '0.54.0';
|
|
18544
|
-
const PACKAGE_NAME = '@opentelemetry/instrumentation-document-load';
|
|
18545
|
-
|
|
18546
|
-
/*
|
|
18547
|
-
* Copyright The OpenTelemetry Authors
|
|
18548
|
-
*
|
|
18549
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
18550
|
-
* you may not use this file except in compliance with the License.
|
|
18551
|
-
* You may obtain a copy of the License at
|
|
18552
|
-
*
|
|
18553
|
-
* https://www.apache.org/licenses/LICENSE-2.0
|
|
18554
|
-
*
|
|
18555
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
18556
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
18557
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18558
|
-
* See the License for the specific language governing permissions and
|
|
18559
|
-
* limitations under the License.
|
|
18560
|
-
*/
|
|
18561
|
-
/*
|
|
18562
|
-
* This file contains a copy of unstable semantic convention definitions
|
|
18563
|
-
* used by this package.
|
|
18564
|
-
* @see https://github.com/open-telemetry/opentelemetry-js/tree/main/semantic-conventions#unstable-semconv
|
|
18565
|
-
*/
|
|
18566
|
-
/**
|
|
18567
|
-
* Deprecated, use `http.response.header.content-length` instead.
|
|
18568
|
-
*
|
|
18569
|
-
* @example 3495
|
|
18570
|
-
*
|
|
18571
|
-
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
18572
|
-
*
|
|
18573
|
-
* @deprecated Replaced by `http.response.header.content-length`.
|
|
18574
|
-
*/
|
|
18575
|
-
/**
|
|
18576
|
-
* Deprecated, use `url.full` instead.
|
|
18577
|
-
*
|
|
18578
|
-
* @example https://www.foo.bar/search?q=OpenTelemetry#SemConv
|
|
18579
|
-
*
|
|
18580
|
-
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
18581
|
-
*
|
|
18582
|
-
* @deprecated Replaced by `url.full`.
|
|
18583
|
-
*/
|
|
18584
|
-
const ATTR_HTTP_URL = 'http.url';
|
|
18585
|
-
/**
|
|
18586
|
-
* Deprecated, use `user_agent.original` instead.
|
|
18587
|
-
*
|
|
18588
|
-
* @example CERN-LineMode/2.15 libwww/2.17b3
|
|
18589
|
-
* @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
|
|
18590
|
-
*
|
|
18591
|
-
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
18592
|
-
*
|
|
18593
|
-
* @deprecated Replaced by `user_agent.original`.
|
|
18594
|
-
*/
|
|
18595
|
-
const ATTR_HTTP_USER_AGENT = 'http.user_agent';
|
|
18596
|
-
|
|
18597
|
-
/*
|
|
18598
|
-
* Copyright The OpenTelemetry Authors
|
|
18599
|
-
*
|
|
18600
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
18601
|
-
* you may not use this file except in compliance with the License.
|
|
18602
|
-
* You may obtain a copy of the License at
|
|
18603
|
-
*
|
|
18604
|
-
* https://www.apache.org/licenses/LICENSE-2.0
|
|
18605
|
-
*
|
|
18606
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
18607
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
18608
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18609
|
-
* See the License for the specific language governing permissions and
|
|
18610
|
-
* limitations under the License.
|
|
18611
|
-
*/
|
|
18612
|
-
var EventNames;
|
|
18613
|
-
(function (EventNames) {
|
|
18614
|
-
EventNames["FIRST_PAINT"] = "firstPaint";
|
|
18615
|
-
EventNames["FIRST_CONTENTFUL_PAINT"] = "firstContentfulPaint";
|
|
18616
|
-
})(EventNames || (EventNames = {}));
|
|
18617
|
-
|
|
18618
|
-
/*
|
|
18619
|
-
* Copyright The OpenTelemetry Authors
|
|
18620
|
-
*
|
|
18621
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
18622
|
-
* you may not use this file except in compliance with the License.
|
|
18623
|
-
* You may obtain a copy of the License at
|
|
18624
|
-
*
|
|
18625
|
-
* https://www.apache.org/licenses/LICENSE-2.0
|
|
18626
|
-
*
|
|
18627
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
18628
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
18629
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18630
|
-
* See the License for the specific language governing permissions and
|
|
18631
|
-
* limitations under the License.
|
|
18632
|
-
*/
|
|
18633
|
-
const getPerformanceNavigationEntries = () => {
|
|
18634
|
-
const entries = {};
|
|
18635
|
-
const performanceNavigationTiming = otperformance.getEntriesByType?.('navigation')[0];
|
|
18636
|
-
if (performanceNavigationTiming) {
|
|
18637
|
-
const keys = Object.values(PerformanceTimingNames);
|
|
18638
|
-
keys.forEach((key) => {
|
|
18639
|
-
if (hasKey(performanceNavigationTiming, key)) {
|
|
18640
|
-
const value = performanceNavigationTiming[key];
|
|
18641
|
-
if (typeof value === 'number') {
|
|
18642
|
-
entries[key] = value;
|
|
18643
|
-
}
|
|
18644
|
-
}
|
|
18645
|
-
});
|
|
18646
|
-
}
|
|
18647
|
-
else {
|
|
18648
|
-
// // fallback to previous version
|
|
18649
|
-
const perf = otperformance;
|
|
18650
|
-
const performanceTiming = perf.timing;
|
|
18651
|
-
if (performanceTiming) {
|
|
18652
|
-
const keys = Object.values(PerformanceTimingNames);
|
|
18653
|
-
keys.forEach((key) => {
|
|
18654
|
-
if (hasKey(performanceTiming, key)) {
|
|
18655
|
-
const value = performanceTiming[key];
|
|
18656
|
-
if (typeof value === 'number') {
|
|
18657
|
-
entries[key] = value;
|
|
18658
|
-
}
|
|
18659
|
-
}
|
|
18660
|
-
});
|
|
18661
|
-
}
|
|
18662
|
-
}
|
|
18663
|
-
return entries;
|
|
18664
|
-
};
|
|
18665
|
-
const performancePaintNames = {
|
|
18666
|
-
'first-paint': EventNames.FIRST_PAINT,
|
|
18667
|
-
'first-contentful-paint': EventNames.FIRST_CONTENTFUL_PAINT,
|
|
18668
|
-
};
|
|
18669
|
-
const addSpanPerformancePaintEvents = (span) => {
|
|
18670
|
-
const performancePaintTiming = otperformance.getEntriesByType?.('paint');
|
|
18671
|
-
if (performancePaintTiming) {
|
|
18672
|
-
performancePaintTiming.forEach(({ name, startTime }) => {
|
|
18673
|
-
if (hasKey(performancePaintNames, name)) {
|
|
18674
|
-
span.addEvent(performancePaintNames[name], startTime);
|
|
18675
|
-
}
|
|
18676
|
-
});
|
|
18677
|
-
}
|
|
18678
|
-
};
|
|
18679
|
-
|
|
18680
|
-
/*
|
|
18681
|
-
* Copyright The OpenTelemetry Authors
|
|
18682
|
-
*
|
|
18683
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
18684
|
-
* you may not use this file except in compliance with the License.
|
|
18685
|
-
* You may obtain a copy of the License at
|
|
18686
|
-
*
|
|
18687
|
-
* https://www.apache.org/licenses/LICENSE-2.0
|
|
18688
|
-
*
|
|
18689
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
18690
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
18691
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18692
|
-
* See the License for the specific language governing permissions and
|
|
18693
|
-
* limitations under the License.
|
|
18694
|
-
*/
|
|
18695
|
-
/**
|
|
18696
|
-
* This class represents a document load plugin
|
|
18697
|
-
*/
|
|
18698
|
-
class DocumentLoadInstrumentation extends InstrumentationBase {
|
|
18699
|
-
component = 'document-load';
|
|
18700
|
-
version = '1';
|
|
18701
|
-
moduleName = this.component;
|
|
18702
|
-
_semconvStability;
|
|
18703
|
-
constructor(config = {}) {
|
|
18704
|
-
super(PACKAGE_NAME, PACKAGE_VERSION, config);
|
|
18705
|
-
this._semconvStability = semconvStabilityFromStr('http', config?.semconvStabilityOptIn);
|
|
18706
|
-
}
|
|
18707
|
-
init() { }
|
|
18708
|
-
/**
|
|
18709
|
-
* callback to be executed when page is loaded
|
|
18710
|
-
*/
|
|
18711
|
-
_onDocumentLoaded() {
|
|
18712
|
-
// Timeout is needed as load event doesn't have yet the performance metrics for loadEnd.
|
|
18713
|
-
// Support for event "loadend" is very limited and cannot be used
|
|
18714
|
-
window.setTimeout(() => {
|
|
18715
|
-
this._collectPerformance();
|
|
18716
|
-
});
|
|
16139
|
+
return function patchCancelTask(task) {
|
|
16140
|
+
const currentZone = Zone.current;
|
|
16141
|
+
const currentSpan = plugin._getCurrentSpan(currentZone);
|
|
16142
|
+
if (currentSpan && plugin._shouldCountTask(task, currentZone)) {
|
|
16143
|
+
plugin._decrementTask(currentSpan);
|
|
16144
|
+
}
|
|
16145
|
+
return original.call(this, task);
|
|
16146
|
+
};
|
|
16147
|
+
};
|
|
18717
16148
|
}
|
|
18718
16149
|
/**
|
|
18719
|
-
*
|
|
18720
|
-
*
|
|
16150
|
+
* Patches zone schedule task - this is done to be able to correctly
|
|
16151
|
+
* increment the number of tasks running within current zone but also to
|
|
16152
|
+
* save time in case of timeout running from xhr plugin when waiting for
|
|
16153
|
+
* main request from PerformanceResourceTiming
|
|
18721
16154
|
*/
|
|
18722
|
-
|
|
18723
|
-
const
|
|
18724
|
-
|
|
18725
|
-
|
|
18726
|
-
|
|
18727
|
-
|
|
18728
|
-
|
|
16155
|
+
_patchZoneScheduleTask() {
|
|
16156
|
+
const plugin = this;
|
|
16157
|
+
return (original) => {
|
|
16158
|
+
return function patchScheduleTask(task) {
|
|
16159
|
+
const currentZone = Zone.current;
|
|
16160
|
+
const currentSpan = plugin._getCurrentSpan(currentZone);
|
|
16161
|
+
if (currentSpan && plugin._shouldCountTask(task, currentZone)) {
|
|
16162
|
+
plugin._incrementTask(currentSpan);
|
|
16163
|
+
plugin._checkForTimeout(task, currentSpan);
|
|
16164
|
+
}
|
|
16165
|
+
return original.call(this, task);
|
|
16166
|
+
};
|
|
16167
|
+
};
|
|
18729
16168
|
}
|
|
18730
16169
|
/**
|
|
18731
|
-
*
|
|
16170
|
+
* Patches zone run task - this is done to be able to create a span when
|
|
16171
|
+
* user interaction starts
|
|
16172
|
+
* @private
|
|
18732
16173
|
*/
|
|
18733
|
-
|
|
18734
|
-
const
|
|
18735
|
-
|
|
18736
|
-
|
|
18737
|
-
|
|
18738
|
-
|
|
18739
|
-
|
|
18740
|
-
|
|
18741
|
-
|
|
18742
|
-
|
|
18743
|
-
|
|
18744
|
-
|
|
18745
|
-
if (
|
|
18746
|
-
|
|
16174
|
+
_patchZoneRunTask() {
|
|
16175
|
+
const plugin = this;
|
|
16176
|
+
return (original) => {
|
|
16177
|
+
return function patchRunTask(task, applyThis, applyArgs) {
|
|
16178
|
+
const event = Array.isArray(applyArgs) && applyArgs[0] instanceof Event
|
|
16179
|
+
? applyArgs[0]
|
|
16180
|
+
: undefined;
|
|
16181
|
+
const target = event?.target;
|
|
16182
|
+
let span;
|
|
16183
|
+
const activeZone = this;
|
|
16184
|
+
if (target) {
|
|
16185
|
+
span = plugin._createSpan(target, task.eventName);
|
|
16186
|
+
if (span) {
|
|
16187
|
+
plugin._incrementTask(span);
|
|
16188
|
+
return activeZone.run(() => {
|
|
16189
|
+
try {
|
|
16190
|
+
return context.with(trace.setSpan(context.active(), span), () => {
|
|
16191
|
+
const currentZone = Zone.current;
|
|
16192
|
+
task._zone = currentZone;
|
|
16193
|
+
return original.call(currentZone, task, applyThis, applyArgs);
|
|
16194
|
+
});
|
|
16195
|
+
}
|
|
16196
|
+
finally {
|
|
16197
|
+
plugin._decrementTask(span);
|
|
16198
|
+
}
|
|
16199
|
+
});
|
|
18747
16200
|
}
|
|
18748
|
-
|
|
18749
|
-
|
|
16201
|
+
}
|
|
16202
|
+
else {
|
|
16203
|
+
span = plugin._getCurrentSpan(activeZone);
|
|
16204
|
+
}
|
|
16205
|
+
try {
|
|
16206
|
+
return original.call(activeZone, task, applyThis, applyArgs);
|
|
16207
|
+
}
|
|
16208
|
+
finally {
|
|
16209
|
+
if (span && plugin._shouldCountTask(task, activeZone)) {
|
|
16210
|
+
plugin._decrementTask(span);
|
|
18750
16211
|
}
|
|
18751
|
-
context.with(trace.setSpan(context.active(), fetchSpan), () => {
|
|
18752
|
-
const skipOldSemconvContentLengthAttrs = !(this._semconvStability & SemconvStability.OLD);
|
|
18753
|
-
addSpanNetworkEvents(fetchSpan, entries, this.getConfig().ignoreNetworkEvents, undefined, skipOldSemconvContentLengthAttrs);
|
|
18754
|
-
this._addCustomAttributesOnSpan(fetchSpan, this.getConfig().applyCustomAttributesOnSpan?.documentFetch);
|
|
18755
|
-
this._endSpan(fetchSpan, PerformanceTimingNames.RESPONSE_END, entries);
|
|
18756
|
-
});
|
|
18757
16212
|
}
|
|
18758
|
-
}
|
|
18759
|
-
|
|
18760
|
-
rootSpan.setAttribute(ATTR_HTTP_URL, location.href);
|
|
18761
|
-
rootSpan.setAttribute(ATTR_HTTP_USER_AGENT, navigator.userAgent);
|
|
18762
|
-
}
|
|
18763
|
-
if (this._semconvStability & SemconvStability.STABLE) {
|
|
18764
|
-
rootSpan.setAttribute(ATTR_URL_FULL, location.href);
|
|
18765
|
-
rootSpan.setAttribute(ATTR_USER_AGENT_ORIGINAL, navigator.userAgent);
|
|
18766
|
-
}
|
|
18767
|
-
this._addResourcesSpans(rootSpan);
|
|
18768
|
-
if (!this.getConfig().ignoreNetworkEvents) {
|
|
18769
|
-
addSpanNetworkEvent(rootSpan, PerformanceTimingNames.FETCH_START, entries);
|
|
18770
|
-
addSpanNetworkEvent(rootSpan, PerformanceTimingNames.UNLOAD_EVENT_START, entries);
|
|
18771
|
-
addSpanNetworkEvent(rootSpan, PerformanceTimingNames.UNLOAD_EVENT_END, entries);
|
|
18772
|
-
addSpanNetworkEvent(rootSpan, PerformanceTimingNames.DOM_INTERACTIVE, entries);
|
|
18773
|
-
addSpanNetworkEvent(rootSpan, PerformanceTimingNames.DOM_CONTENT_LOADED_EVENT_START, entries);
|
|
18774
|
-
addSpanNetworkEvent(rootSpan, PerformanceTimingNames.DOM_CONTENT_LOADED_EVENT_END, entries);
|
|
18775
|
-
addSpanNetworkEvent(rootSpan, PerformanceTimingNames.DOM_COMPLETE, entries);
|
|
18776
|
-
addSpanNetworkEvent(rootSpan, PerformanceTimingNames.LOAD_EVENT_START, entries);
|
|
18777
|
-
addSpanNetworkEvent(rootSpan, PerformanceTimingNames.LOAD_EVENT_END, entries);
|
|
18778
|
-
}
|
|
18779
|
-
if (!this.getConfig().ignorePerformancePaintEvents) {
|
|
18780
|
-
addSpanPerformancePaintEvents(rootSpan);
|
|
18781
|
-
}
|
|
18782
|
-
this._addCustomAttributesOnSpan(rootSpan, this.getConfig().applyCustomAttributesOnSpan?.documentLoad);
|
|
18783
|
-
this._endSpan(rootSpan, PerformanceTimingNames.LOAD_EVENT_END, entries);
|
|
18784
|
-
});
|
|
16213
|
+
};
|
|
16214
|
+
};
|
|
18785
16215
|
}
|
|
18786
16216
|
/**
|
|
18787
|
-
*
|
|
18788
|
-
* @param
|
|
18789
|
-
* @param
|
|
18790
|
-
* @
|
|
16217
|
+
* Decides if task should be counted.
|
|
16218
|
+
* @param task
|
|
16219
|
+
* @param currentZone
|
|
16220
|
+
* @private
|
|
18791
16221
|
*/
|
|
18792
|
-
|
|
18793
|
-
|
|
18794
|
-
|
|
18795
|
-
|
|
18796
|
-
|
|
18797
|
-
|
|
18798
|
-
|
|
18799
|
-
|
|
18800
|
-
|
|
18801
|
-
|
|
16222
|
+
_shouldCountTask(task, currentZone) {
|
|
16223
|
+
if (task._zone) {
|
|
16224
|
+
currentZone = task._zone;
|
|
16225
|
+
}
|
|
16226
|
+
if (!currentZone || !task.data || task.data.isPeriodic) {
|
|
16227
|
+
return false;
|
|
16228
|
+
}
|
|
16229
|
+
const currentSpan = this._getCurrentSpan(currentZone);
|
|
16230
|
+
if (!currentSpan) {
|
|
16231
|
+
return false;
|
|
16232
|
+
}
|
|
16233
|
+
if (!this._spansData.get(currentSpan)) {
|
|
16234
|
+
return false;
|
|
18802
16235
|
}
|
|
16236
|
+
return task.type === 'macroTask' || task.type === 'microTask';
|
|
18803
16237
|
}
|
|
18804
16238
|
/**
|
|
18805
|
-
*
|
|
18806
|
-
* @param
|
|
18807
|
-
* @param
|
|
16239
|
+
* Will try to end span when such span still exists.
|
|
16240
|
+
* @param span
|
|
16241
|
+
* @param endTime
|
|
16242
|
+
* @private
|
|
18808
16243
|
*/
|
|
18809
|
-
|
|
18810
|
-
const span = this._startSpan(AttributeNames.RESOURCE_FETCH, PerformanceTimingNames.FETCH_START, resource, parentSpan);
|
|
16244
|
+
_tryToEndSpan(span, endTime) {
|
|
18811
16245
|
if (span) {
|
|
18812
|
-
|
|
18813
|
-
|
|
18814
|
-
|
|
18815
|
-
|
|
18816
|
-
span.setAttribute(ATTR_URL_FULL, resource.name);
|
|
16246
|
+
const spanData = this._spansData.get(span);
|
|
16247
|
+
if (spanData) {
|
|
16248
|
+
span.end(endTime);
|
|
16249
|
+
this._spansData.delete(span);
|
|
18817
16250
|
}
|
|
18818
|
-
const skipOldSemconvContentLengthAttrs = !(this._semconvStability & SemconvStability.OLD);
|
|
18819
|
-
addSpanNetworkEvents(span, resource, this.getConfig().ignoreNetworkEvents, undefined, skipOldSemconvContentLengthAttrs);
|
|
18820
|
-
this._addCustomAttributesOnResourceSpan(span, resource, this.getConfig().applyCustomAttributesOnSpan?.resourceFetch);
|
|
18821
|
-
this._endSpan(span, PerformanceTimingNames.RESPONSE_END, resource);
|
|
18822
|
-
}
|
|
18823
|
-
}
|
|
18824
|
-
/**
|
|
18825
|
-
* Helper function for starting a span
|
|
18826
|
-
* @param spanName name of span
|
|
18827
|
-
* @param performanceName name of performance entry for time start
|
|
18828
|
-
* @param entries
|
|
18829
|
-
* @param parentSpan
|
|
18830
|
-
*/
|
|
18831
|
-
_startSpan(spanName, performanceName, entries, parentSpan) {
|
|
18832
|
-
if (hasKey(entries, performanceName) &&
|
|
18833
|
-
typeof entries[performanceName] === 'number') {
|
|
18834
|
-
const span = this.tracer.startSpan(spanName, {
|
|
18835
|
-
startTime: entries[performanceName],
|
|
18836
|
-
}, parentSpan ? trace.setSpan(context.active(), parentSpan) : undefined);
|
|
18837
|
-
return span;
|
|
18838
16251
|
}
|
|
18839
|
-
return undefined;
|
|
18840
16252
|
}
|
|
18841
16253
|
/**
|
|
18842
|
-
*
|
|
16254
|
+
* implements enable function
|
|
18843
16255
|
*/
|
|
18844
|
-
|
|
18845
|
-
|
|
18846
|
-
|
|
16256
|
+
enable() {
|
|
16257
|
+
const ZoneWithPrototype = this._getZoneWithPrototype();
|
|
16258
|
+
this._diag.debug('applying patch to', this.moduleName, this.version, 'zone:', !!ZoneWithPrototype);
|
|
16259
|
+
if (ZoneWithPrototype) {
|
|
16260
|
+
if (isWrapped(ZoneWithPrototype.prototype.runTask)) {
|
|
16261
|
+
this._unwrap(ZoneWithPrototype.prototype, 'runTask');
|
|
16262
|
+
this._diag.debug('removing previous patch from method runTask');
|
|
16263
|
+
}
|
|
16264
|
+
if (isWrapped(ZoneWithPrototype.prototype.scheduleTask)) {
|
|
16265
|
+
this._unwrap(ZoneWithPrototype.prototype, 'scheduleTask');
|
|
16266
|
+
this._diag.debug('removing previous patch from method scheduleTask');
|
|
16267
|
+
}
|
|
16268
|
+
if (isWrapped(ZoneWithPrototype.prototype.cancelTask)) {
|
|
16269
|
+
this._unwrap(ZoneWithPrototype.prototype, 'cancelTask');
|
|
16270
|
+
this._diag.debug('removing previous patch from method cancelTask');
|
|
16271
|
+
}
|
|
16272
|
+
this._zonePatched = true;
|
|
16273
|
+
this._wrap(ZoneWithPrototype.prototype, 'runTask', this._patchZoneRunTask());
|
|
16274
|
+
this._wrap(ZoneWithPrototype.prototype, 'scheduleTask', this._patchZoneScheduleTask());
|
|
16275
|
+
this._wrap(ZoneWithPrototype.prototype, 'cancelTask', this._patchZoneCancelTask());
|
|
18847
16276
|
}
|
|
18848
16277
|
else {
|
|
18849
|
-
this.
|
|
18850
|
-
|
|
18851
|
-
|
|
18852
|
-
|
|
18853
|
-
|
|
18854
|
-
|
|
18855
|
-
|
|
18856
|
-
|
|
18857
|
-
|
|
18858
|
-
|
|
18859
|
-
if (!error) {
|
|
18860
|
-
return;
|
|
16278
|
+
this._zonePatched = false;
|
|
16279
|
+
const targets = this._getPatchableEventTargets();
|
|
16280
|
+
targets.forEach(target => {
|
|
16281
|
+
if (isWrapped(target.addEventListener)) {
|
|
16282
|
+
this._unwrap(target, 'addEventListener');
|
|
16283
|
+
this._diag.debug('removing previous patch from method addEventListener');
|
|
16284
|
+
}
|
|
16285
|
+
if (isWrapped(target.removeEventListener)) {
|
|
16286
|
+
this._unwrap(target, 'removeEventListener');
|
|
16287
|
+
this._diag.debug('removing previous patch from method removeEventListener');
|
|
18861
16288
|
}
|
|
18862
|
-
this.
|
|
16289
|
+
this._wrap(target, 'addEventListener', this._patchAddEventListener());
|
|
16290
|
+
this._wrap(target, 'removeEventListener', this._patchRemoveEventListener());
|
|
18863
16291
|
});
|
|
18864
16292
|
}
|
|
16293
|
+
this._patchHistoryApi();
|
|
18865
16294
|
}
|
|
18866
16295
|
/**
|
|
18867
|
-
*
|
|
16296
|
+
* implements unpatch function
|
|
18868
16297
|
*/
|
|
18869
|
-
|
|
18870
|
-
|
|
18871
|
-
|
|
18872
|
-
|
|
18873
|
-
|
|
16298
|
+
disable() {
|
|
16299
|
+
const ZoneWithPrototype = this._getZoneWithPrototype();
|
|
16300
|
+
this._diag.debug('removing patch from', this.moduleName, this.version, 'zone:', !!ZoneWithPrototype);
|
|
16301
|
+
if (ZoneWithPrototype && this._zonePatched) {
|
|
16302
|
+
if (isWrapped(ZoneWithPrototype.prototype.runTask)) {
|
|
16303
|
+
this._unwrap(ZoneWithPrototype.prototype, 'runTask');
|
|
16304
|
+
}
|
|
16305
|
+
if (isWrapped(ZoneWithPrototype.prototype.scheduleTask)) {
|
|
16306
|
+
this._unwrap(ZoneWithPrototype.prototype, 'scheduleTask');
|
|
16307
|
+
}
|
|
16308
|
+
if (isWrapped(ZoneWithPrototype.prototype.cancelTask)) {
|
|
16309
|
+
this._unwrap(ZoneWithPrototype.prototype, 'cancelTask');
|
|
16310
|
+
}
|
|
16311
|
+
}
|
|
16312
|
+
else {
|
|
16313
|
+
const targets = this._getPatchableEventTargets();
|
|
16314
|
+
targets.forEach(target => {
|
|
16315
|
+
if (isWrapped(target.addEventListener)) {
|
|
16316
|
+
this._unwrap(target, 'addEventListener');
|
|
16317
|
+
}
|
|
16318
|
+
if (isWrapped(target.removeEventListener)) {
|
|
16319
|
+
this._unwrap(target, 'removeEventListener');
|
|
18874
16320
|
}
|
|
18875
|
-
this._diag.error('addCustomAttributesOnResourceSpan', error);
|
|
18876
16321
|
});
|
|
18877
16322
|
}
|
|
16323
|
+
this._unpatchHistoryApi();
|
|
18878
16324
|
}
|
|
18879
16325
|
/**
|
|
18880
|
-
*
|
|
18881
|
-
*/
|
|
18882
|
-
enable() {
|
|
18883
|
-
// remove previously attached load to avoid adding the same event twice
|
|
18884
|
-
// in case of multiple enable calling.
|
|
18885
|
-
window.removeEventListener('load', this._onDocumentLoaded);
|
|
18886
|
-
this._waitForPageLoad();
|
|
18887
|
-
}
|
|
18888
|
-
/**
|
|
18889
|
-
* implements disable function
|
|
16326
|
+
* returns Zone
|
|
18890
16327
|
*/
|
|
18891
|
-
|
|
18892
|
-
window
|
|
16328
|
+
_getZoneWithPrototype() {
|
|
16329
|
+
const _window = window;
|
|
16330
|
+
return _window.Zone;
|
|
18893
16331
|
}
|
|
18894
16332
|
}
|
|
18895
16333
|
|
|
@@ -19949,6 +17387,65 @@ var UAParser = /*@__PURE__*/getDefaultExportFromCjs(uaParserExports);
|
|
|
19949
17387
|
// Semantic convention attribute names
|
|
19950
17388
|
const ATTR_SERVICE_NAME = 'service.name';
|
|
19951
17389
|
const ATTR_SERVICE_VERSION = 'service.version';
|
|
17390
|
+
// Token de autenticación para OpenTelemetry Collector
|
|
17391
|
+
const AUTH_TOKEN = 'eAzROSTiqNd3i+M9Jw6q5Tld0jarZc617sJB//pvb5c=';
|
|
17392
|
+
// Instalar interceptores globalmente UNA SOLA VEZ antes de cualquier inicialización
|
|
17393
|
+
let interceptorsInstalled = false;
|
|
17394
|
+
function installAuthInterceptors() {
|
|
17395
|
+
if (interceptorsInstalled) {
|
|
17396
|
+
return;
|
|
17397
|
+
}
|
|
17398
|
+
interceptorsInstalled = true;
|
|
17399
|
+
// Guardar referencia al XHR original ANTES de que OpenTelemetry lo toque
|
|
17400
|
+
const RealXHR = window.XMLHttpRequest;
|
|
17401
|
+
if (!RealXHR) {
|
|
17402
|
+
console.error('[TracingService] XMLHttpRequest not available');
|
|
17403
|
+
return;
|
|
17404
|
+
}
|
|
17405
|
+
// Crear wrapper que agrega el header
|
|
17406
|
+
window.XMLHttpRequest = function () {
|
|
17407
|
+
const xhr = new RealXHR();
|
|
17408
|
+
const originalOpen = xhr.open;
|
|
17409
|
+
const originalSend = xhr.send;
|
|
17410
|
+
let isCollectorRequest = false;
|
|
17411
|
+
xhr.open = function (method, url, ...args) {
|
|
17412
|
+
const urlString = typeof url === 'string' ? url : url.toString();
|
|
17413
|
+
isCollectorRequest = urlString.includes('collector.jaak.ai');
|
|
17414
|
+
return originalOpen.apply(this, [method, url, ...args]);
|
|
17415
|
+
};
|
|
17416
|
+
xhr.send = function (...args) {
|
|
17417
|
+
if (isCollectorRequest) {
|
|
17418
|
+
this.setRequestHeader('Authorization', `Bearer ${AUTH_TOKEN}`);
|
|
17419
|
+
}
|
|
17420
|
+
return originalSend.apply(this, args);
|
|
17421
|
+
};
|
|
17422
|
+
return xhr;
|
|
17423
|
+
};
|
|
17424
|
+
// Copiar propiedades del constructor original
|
|
17425
|
+
for (const prop in RealXHR) {
|
|
17426
|
+
if (RealXHR.hasOwnProperty(prop)) {
|
|
17427
|
+
window.XMLHttpRequest[prop] = RealXHR[prop];
|
|
17428
|
+
}
|
|
17429
|
+
}
|
|
17430
|
+
// También interceptar fetch por si el SDK lo usa en lugar de XHR
|
|
17431
|
+
const originalFetch = window.fetch;
|
|
17432
|
+
window.fetch = function (input, init) {
|
|
17433
|
+
const url = typeof input === 'string' ? input : input instanceof URL ? input.href : input.url;
|
|
17434
|
+
if (url.includes('collector.jaak.ai')) {
|
|
17435
|
+
const headers = new Headers(init?.headers || {});
|
|
17436
|
+
headers.set('Authorization', `Bearer ${AUTH_TOKEN}`);
|
|
17437
|
+
init = {
|
|
17438
|
+
...init,
|
|
17439
|
+
headers: headers,
|
|
17440
|
+
};
|
|
17441
|
+
}
|
|
17442
|
+
return originalFetch.call(this, input, init);
|
|
17443
|
+
};
|
|
17444
|
+
// Deshabilitar sendBeacon globalmente porque no soporta headers personalizados
|
|
17445
|
+
navigator.sendBeacon = function () {
|
|
17446
|
+
return false; // Retornar false fuerza al SDK a usar XHR/Fetch como fallback
|
|
17447
|
+
};
|
|
17448
|
+
}
|
|
19952
17449
|
class TracingService {
|
|
19953
17450
|
provider = null;
|
|
19954
17451
|
tracer = null;
|
|
@@ -19960,7 +17457,6 @@ class TracingService {
|
|
|
19960
17457
|
customerId;
|
|
19961
17458
|
tenantId;
|
|
19962
17459
|
environment;
|
|
19963
|
-
propagateTraceHeaderCorsUrls;
|
|
19964
17460
|
enableAutoInstrumentation;
|
|
19965
17461
|
spanProcessor = null;
|
|
19966
17462
|
parser;
|
|
@@ -19975,19 +17471,43 @@ class TracingService {
|
|
|
19975
17471
|
this.customerId = config.customerId;
|
|
19976
17472
|
this.tenantId = config.tenantId;
|
|
19977
17473
|
this.environment = config.environment || 'production';
|
|
19978
|
-
this.propagateTraceHeaderCorsUrls = config.propagateTraceHeaderCorsUrls || [];
|
|
19979
17474
|
this.enableAutoInstrumentation = config.enableAutoInstrumentation ?? false; // Default to false
|
|
19980
17475
|
this.parser = new UAParser();
|
|
19981
17476
|
}
|
|
19982
17477
|
initialize() {
|
|
19983
17478
|
try {
|
|
17479
|
+
// Instalar interceptores de autenticación ANTES de crear el exporter
|
|
17480
|
+
installAuthInterceptors();
|
|
19984
17481
|
// Create OTLP exporter
|
|
19985
|
-
const
|
|
17482
|
+
const baseExporter = new OTLPTraceExporter({
|
|
19986
17483
|
url: this.collectorUrl,
|
|
19987
17484
|
headers: {
|
|
19988
17485
|
'Content-Type': 'application/json',
|
|
17486
|
+
'Authorization': `Bearer ${AUTH_TOKEN}`,
|
|
19989
17487
|
},
|
|
17488
|
+
// @ts-ignore - useSendBeacon no está en los tipos pero es soportada
|
|
17489
|
+
useSendBeacon: false,
|
|
19990
17490
|
});
|
|
17491
|
+
// Wrap exporter to log export attempts
|
|
17492
|
+
const exporter = {
|
|
17493
|
+
export: (spans, resultCallback) => {
|
|
17494
|
+
if (this.debug) {
|
|
17495
|
+
console.log('[TracingService] 📤 Exporting', spans.length, 'spans to collector');
|
|
17496
|
+
}
|
|
17497
|
+
baseExporter.export(spans, (result) => {
|
|
17498
|
+
if (result.code !== 0) {
|
|
17499
|
+
console.error('[TracingService] ❌ Export failed:', result);
|
|
17500
|
+
}
|
|
17501
|
+
resultCallback(result);
|
|
17502
|
+
});
|
|
17503
|
+
},
|
|
17504
|
+
shutdown: async () => {
|
|
17505
|
+
return baseExporter.shutdown();
|
|
17506
|
+
},
|
|
17507
|
+
forceFlush: async () => {
|
|
17508
|
+
return baseExporter.forceFlush();
|
|
17509
|
+
},
|
|
17510
|
+
};
|
|
19991
17511
|
// Create batch span processor for each exporter
|
|
19992
17512
|
this.spanProcessor = new BatchSpanProcessor(exporter, {
|
|
19993
17513
|
maxQueueSize: 100,
|
|
@@ -19995,24 +17515,10 @@ class TracingService {
|
|
|
19995
17515
|
scheduledDelayMillis: 5000,
|
|
19996
17516
|
exportTimeoutMillis: 30000,
|
|
19997
17517
|
});
|
|
19998
|
-
// Create
|
|
19999
|
-
const resourceAttributes = {
|
|
20000
|
-
[ATTR_SERVICE_NAME]: this.serviceName,
|
|
20001
|
-
[ATTR_SERVICE_VERSION]: this.serviceVersion,
|
|
20002
|
-
'deployment.environment': this.environment,
|
|
20003
|
-
};
|
|
20004
|
-
if (this.customerId) {
|
|
20005
|
-
resourceAttributes['customer.id'] = this.customerId;
|
|
20006
|
-
}
|
|
20007
|
-
if (this.tenantId) {
|
|
20008
|
-
resourceAttributes['tenant.id'] = this.tenantId;
|
|
20009
|
-
}
|
|
20010
|
-
// Create tracer provider with resource
|
|
17518
|
+
// Create tracer provider with span processor in constructor
|
|
20011
17519
|
this.provider = new WebTracerProvider({
|
|
20012
|
-
|
|
17520
|
+
spanProcessors: [this.spanProcessor],
|
|
20013
17521
|
});
|
|
20014
|
-
// Add span processor
|
|
20015
|
-
this.provider.addSpanProcessor?.(this.spanProcessor);
|
|
20016
17522
|
// Configure context manager (Zone.js for async context propagation)
|
|
20017
17523
|
const contextManager = new ZoneContextManager();
|
|
20018
17524
|
// Configure propagators (W3C Trace Context + B3 for compatibility)
|
|
@@ -20026,19 +17532,7 @@ class TracingService {
|
|
|
20026
17532
|
this.tracer = trace.getTracer(this.serviceName, this.serviceVersion);
|
|
20027
17533
|
// Initialize auto-instrumentation if enabled
|
|
20028
17534
|
if (this.enableAutoInstrumentation) {
|
|
20029
|
-
this.initializeAutoInstrumentation(
|
|
20030
|
-
}
|
|
20031
|
-
if (this.debug) {
|
|
20032
|
-
console.log('[TracingService] Initialized successfully', {
|
|
20033
|
-
collectorUrl: this.collectorUrl,
|
|
20034
|
-
serviceName: this.serviceName,
|
|
20035
|
-
serviceVersion: this.serviceVersion,
|
|
20036
|
-
environment: this.environment,
|
|
20037
|
-
customerId: this.customerId,
|
|
20038
|
-
tenantId: this.tenantId,
|
|
20039
|
-
autoInstrumentation: this.enableAutoInstrumentation,
|
|
20040
|
-
propagateUrls: this.propagateTraceHeaderCorsUrls,
|
|
20041
|
-
});
|
|
17535
|
+
this.initializeAutoInstrumentation();
|
|
20042
17536
|
}
|
|
20043
17537
|
}
|
|
20044
17538
|
catch (error) {
|
|
@@ -20046,37 +17540,15 @@ class TracingService {
|
|
|
20046
17540
|
// Don't throw - telemetry should fail silently in production
|
|
20047
17541
|
}
|
|
20048
17542
|
}
|
|
20049
|
-
initializeAutoInstrumentation(
|
|
17543
|
+
initializeAutoInstrumentation() {
|
|
20050
17544
|
try {
|
|
20051
|
-
//
|
|
20052
|
-
//
|
|
17545
|
+
// NOTE: XHR and Fetch instrumentation are disabled because we manually intercept
|
|
17546
|
+
// them to add authentication headers. Enabling them causes conflicts.
|
|
17547
|
+
// NOTE: DocumentLoadInstrumentation is disabled because it captures events that
|
|
17548
|
+
// occurred before the component initialized, and cannot use custom trace IDs.
|
|
17549
|
+
// Only enable user interaction instrumentation
|
|
20053
17550
|
registerInstrumentations({
|
|
20054
17551
|
instrumentations: [
|
|
20055
|
-
// Fetch API instrumentation
|
|
20056
|
-
new FetchInstrumentation({
|
|
20057
|
-
propagateTraceHeaderCorsUrls: this.propagateTraceHeaderCorsUrls,
|
|
20058
|
-
clearTimingResources: true,
|
|
20059
|
-
applyCustomAttributesOnSpan: (span, _request, response) => {
|
|
20060
|
-
// Add resource attributes to each span
|
|
20061
|
-
Object.entries(resourceAttributes).forEach(([key, value]) => {
|
|
20062
|
-
span.setAttribute(key, value);
|
|
20063
|
-
});
|
|
20064
|
-
// Add custom attributes
|
|
20065
|
-
if (response && 'status' in response) {
|
|
20066
|
-
span.setAttribute('http.response.status_code', response.status);
|
|
20067
|
-
}
|
|
20068
|
-
},
|
|
20069
|
-
}),
|
|
20070
|
-
// XMLHttpRequest instrumentation
|
|
20071
|
-
new XMLHttpRequestInstrumentation({
|
|
20072
|
-
propagateTraceHeaderCorsUrls: this.propagateTraceHeaderCorsUrls,
|
|
20073
|
-
applyCustomAttributesOnSpan: (span) => {
|
|
20074
|
-
// Add resource attributes to each span
|
|
20075
|
-
Object.entries(resourceAttributes).forEach(([key, value]) => {
|
|
20076
|
-
span.setAttribute(key, value);
|
|
20077
|
-
});
|
|
20078
|
-
},
|
|
20079
|
-
}),
|
|
20080
17552
|
// User interaction instrumentation (clicks, etc.)
|
|
20081
17553
|
new UserInteractionInstrumentation({
|
|
20082
17554
|
eventNames: ['click', 'submit'],
|
|
@@ -20085,13 +17557,8 @@ class TracingService {
|
|
|
20085
17557
|
return element.tagName === 'BUTTON' || element.tagName === 'A' || element.tagName === 'FORM';
|
|
20086
17558
|
},
|
|
20087
17559
|
}),
|
|
20088
|
-
// Document load instrumentation
|
|
20089
|
-
new DocumentLoadInstrumentation(),
|
|
20090
17560
|
],
|
|
20091
17561
|
});
|
|
20092
|
-
if (this.debug) {
|
|
20093
|
-
console.log('[TracingService] Auto-instrumentation enabled');
|
|
20094
|
-
}
|
|
20095
17562
|
}
|
|
20096
17563
|
catch (error) {
|
|
20097
17564
|
console.error('[TracingService] Failed to initialize auto-instrumentation:', error);
|
|
@@ -20182,19 +17649,24 @@ class TracingService {
|
|
|
20182
17649
|
}
|
|
20183
17650
|
startSpan(name, attributes) {
|
|
20184
17651
|
if (!this.tracer) {
|
|
20185
|
-
|
|
17652
|
+
console.warn('[TracingService] Tracer not initialized, returning no-op span');
|
|
20186
17653
|
return trace.getTracer('noop').startSpan('noop');
|
|
20187
17654
|
}
|
|
20188
17655
|
try {
|
|
20189
17656
|
let currentContext = context.active();
|
|
20190
|
-
// If we have a session trace ID, create a span context
|
|
20191
|
-
if (this.sessionTraceId) {
|
|
20192
|
-
|
|
17657
|
+
// If we have a session trace ID and there's no active span, create a root span context
|
|
17658
|
+
if (this.sessionTraceId && !trace.getSpan(currentContext)) {
|
|
17659
|
+
// Create a valid span context for the custom trace ID
|
|
17660
|
+
const remoteSpanContext = {
|
|
20193
17661
|
traceId: this.sessionTraceId,
|
|
20194
17662
|
spanId: this.generateSpanId(),
|
|
20195
|
-
traceFlags:
|
|
17663
|
+
traceFlags: TraceFlags.SAMPLED,
|
|
17664
|
+
isRemote: true,
|
|
20196
17665
|
};
|
|
20197
|
-
|
|
17666
|
+
// Create a non-recording span with the custom trace context
|
|
17667
|
+
const remoteSpan = trace.wrapSpanContext(remoteSpanContext);
|
|
17668
|
+
// Set this span in the context so child spans inherit the trace ID
|
|
17669
|
+
currentContext = trace.setSpan(currentContext, remoteSpan);
|
|
20198
17670
|
}
|
|
20199
17671
|
// Get device info
|
|
20200
17672
|
const deviceInfo = this.getDeviceInfo();
|
|
@@ -20251,20 +17723,15 @@ class TracingService {
|
|
|
20251
17723
|
}
|
|
20252
17724
|
}
|
|
20253
17725
|
endSpan(span) {
|
|
20254
|
-
if (!span)
|
|
17726
|
+
if (!span) {
|
|
17727
|
+
console.warn('[TracingService] endSpan called with null/undefined span');
|
|
20255
17728
|
return;
|
|
17729
|
+
}
|
|
20256
17730
|
try {
|
|
20257
17731
|
span.end();
|
|
20258
|
-
if (this.debug) {
|
|
20259
|
-
const spanContext = span.spanContext();
|
|
20260
|
-
console.log('[TracingService] Ended span', {
|
|
20261
|
-
traceId: spanContext.traceId,
|
|
20262
|
-
spanId: spanContext.spanId,
|
|
20263
|
-
});
|
|
20264
|
-
}
|
|
20265
17732
|
}
|
|
20266
17733
|
catch (error) {
|
|
20267
|
-
console.error('[TracingService] Failed to end span:', error);
|
|
17734
|
+
console.error('[TracingService] ❌ Failed to end span:', error);
|
|
20268
17735
|
}
|
|
20269
17736
|
}
|
|
20270
17737
|
addSpanEvent(span, name, attributes) {
|
|
@@ -20289,9 +17756,6 @@ class TracingService {
|
|
|
20289
17756
|
code: SpanStatusCode.ERROR,
|
|
20290
17757
|
message: error.message,
|
|
20291
17758
|
});
|
|
20292
|
-
if (this.debug) {
|
|
20293
|
-
console.log('[TracingService] Recorded exception:', error);
|
|
20294
|
-
}
|
|
20295
17759
|
}
|
|
20296
17760
|
catch (err) {
|
|
20297
17761
|
console.error('[TracingService] Failed to record exception:', err);
|
|
@@ -20328,6 +17792,26 @@ class TracingService {
|
|
|
20328
17792
|
this.endSpan(span);
|
|
20329
17793
|
}
|
|
20330
17794
|
}
|
|
17795
|
+
async traceAsync(name, fn, attributes) {
|
|
17796
|
+
return this.trace(name, fn, attributes);
|
|
17797
|
+
}
|
|
17798
|
+
/**
|
|
17799
|
+
* Flush all pending spans to the collector
|
|
17800
|
+
* Call this when capture/process is complete to send all traces
|
|
17801
|
+
*/
|
|
17802
|
+
async flush() {
|
|
17803
|
+
try {
|
|
17804
|
+
if (!this.spanProcessor) {
|
|
17805
|
+
console.warn('[TracingService] No span processor available to flush');
|
|
17806
|
+
return;
|
|
17807
|
+
}
|
|
17808
|
+
await this.spanProcessor.forceFlush();
|
|
17809
|
+
}
|
|
17810
|
+
catch (error) {
|
|
17811
|
+
console.error('[TracingService] ❌ Failed to flush spans:', error);
|
|
17812
|
+
throw error;
|
|
17813
|
+
}
|
|
17814
|
+
}
|
|
20331
17815
|
async cleanup() {
|
|
20332
17816
|
try {
|
|
20333
17817
|
if (this.spanProcessor) {
|
|
@@ -20337,9 +17821,6 @@ class TracingService {
|
|
|
20337
17821
|
if (this.provider) {
|
|
20338
17822
|
await this.provider.shutdown();
|
|
20339
17823
|
}
|
|
20340
|
-
if (this.debug) {
|
|
20341
|
-
console.log('[TracingService] Cleaned up successfully');
|
|
20342
|
-
}
|
|
20343
17824
|
}
|
|
20344
17825
|
catch (error) {
|
|
20345
17826
|
console.error('[TracingService] Failed to cleanup:', error);
|
|
@@ -20976,8 +18457,8 @@ class LicenseValidationService {
|
|
|
20976
18457
|
static ENVIRONMENT_URLS = {
|
|
20977
18458
|
dev: 'https://api.dev.jaak.ai',
|
|
20978
18459
|
qa: 'https://api.qa.jaak.ai',
|
|
20979
|
-
staging: 'https://api
|
|
20980
|
-
prod: 'https://api.jaak.ai',
|
|
18460
|
+
staging: 'https://api.sandbox.jaak.ai',
|
|
18461
|
+
prod: 'https://services.api.jaak.ai',
|
|
20981
18462
|
};
|
|
20982
18463
|
constructor(environment = 'prod') {
|
|
20983
18464
|
this.baseUrl = LicenseValidationService.ENVIRONMENT_URLS[environment];
|
|
@@ -21271,6 +18752,10 @@ const JaakStamps$1 = /*@__PURE__*/ proxyCustomElement(class JaakStamps extends H
|
|
|
21271
18752
|
this.detectionService = this.serviceContainer.getDetectionService();
|
|
21272
18753
|
this.tracingService = this.serviceContainer.getTracingService();
|
|
21273
18754
|
this.metricsService = this.serviceContainer.getMetricsService();
|
|
18755
|
+
// Set the custom trace ID if provided via prop
|
|
18756
|
+
if (this.tracingService && this.traceId) {
|
|
18757
|
+
this.tracingService.setSessionTraceId(this.traceId);
|
|
18758
|
+
}
|
|
21274
18759
|
// Record component initialization
|
|
21275
18760
|
if (this.tracingService) {
|
|
21276
18761
|
const span = this.tracingService.startSpan('component.initialize', {
|
|
@@ -22213,7 +19698,7 @@ const JaakStamps$1 = /*@__PURE__*/ proxyCustomElement(class JaakStamps extends H
|
|
|
22213
19698
|
isCapturing: false
|
|
22214
19699
|
};
|
|
22215
19700
|
const cameraInfo = this.cameraInfoWithAutofocus;
|
|
22216
|
-
return (h("div", { key: '
|
|
19701
|
+
return (h("div", { key: 'a52b452a7aef6574a5e4b74a88c7bd3f9d45fd15', class: "detector-container" }, !this.licenseValid && this.licenseError && (h("div", { key: '18a99579e0b74ceb2cf1c4c3e21a864d2ec7d944', class: "license-error-container" }, h("div", { key: '3431722f4f47824c172a5b6f3a2ad9bd3bf377f2', class: "license-error-card" }, h("svg", { key: 'bf3854de3ba865a58c5c91cfd7a85d3d725be0df', class: "license-error-icon", width: "64", height: "64", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg" }, h("path", { key: '209e3a2a22333ec90e102a7156eb644b529f47c7', d: "M12 22C12 22 20 18 20 12V5L12 2L4 5V12C4 18 12 22 12 22Z", stroke: "currentColor", "stroke-width": "2", "stroke-linecap": "round", "stroke-linejoin": "round" }), h("path", { key: '7b0dc1cd29a9055e552885b23f4537c19932556d', d: "M12 8V12", stroke: "currentColor", "stroke-width": "2", "stroke-linecap": "round" }), h("circle", { key: '8ea686ebfb31a5744303f313fd104c03c02a5472', cx: "12", cy: "16", r: "0.5", fill: "currentColor", stroke: "currentColor", "stroke-width": "1" })), h("h2", { key: '7e0ec3ec23b80176cbec9c706999746d62486f3c', class: "license-error-title" }, "Licencia Requerida"), h("p", { key: '261a91e2c20feb09319dc4f319fb79611cc36a46', class: "license-error-message" }, this.licenseError), h("p", { key: '2e3cc8da0f4a8ebfd52db469b0f0900514d1d7f8', class: "license-error-help" }, "Contacte a soporte: ", h("a", { key: '283eea87e2f69dce1ea7376e3a63fed780633499', href: "mailto:support@jaak.ai" }, "support@jaak.ai")), h("div", { key: 'b4227ed25a4fb4d953c753671d27ac8c931a435f', class: "license-error-footer" }, "JAAK Stamps")))), this.licenseValid && (h("div", { key: 'cb33431cf6992f6e7466273406f729c42c1cbcdb', class: "video-container" }, h("video", { key: 'b44befd61ad616fd36fe1e98fd089a2443bc65b6', ref: el => this.videoRef = el, autoplay: true, muted: true, playsinline: true, class: this.shouldMirrorVideo ? 'mirror' : '', style: { display: captureState.isVideoActive ? 'block' : 'none' } }), h("div", { key: '8cee95ddab5f771a87d43fa434a3ba0c241d2f3e', ref: el => this.detectionContainer = el, class: `detection-overlay ${this.shouldMirrorVideo ? 'mirror' : ''}` }, this.debug && this.detectionBoxes.map((box, index) => (h("div", { key: index, class: "detection-box", style: {
|
|
22217
19702
|
position: 'absolute',
|
|
22218
19703
|
left: `${box.x}px`,
|
|
22219
19704
|
top: `${box.y}px`,
|
|
@@ -22222,9 +19707,9 @@ const JaakStamps$1 = /*@__PURE__*/ proxyCustomElement(class JaakStamps extends H
|
|
|
22222
19707
|
border: '2px solid #32406C',
|
|
22223
19708
|
pointerEvents: 'none',
|
|
22224
19709
|
boxSizing: 'border-box'
|
|
22225
|
-
} })))), this.isMaskReady && (h("div", { key: '
|
|
19710
|
+
} })))), this.isMaskReady && (h("div", { key: '00a749ad234294695d9a292911b41fdacafd219a', class: "overlay-mask" }, h("div", { key: 'e344df8a709fca5225985ccc9f8def75ddbd393c', class: "card-outline" }, h("div", { key: '2dcae9e414f2b7131397d49a3d5ecabfc7cd5eb8', class: "side side-top" }), h("div", { key: '48ac3f06fa4a2c83741df378719911f682811caa', class: "side side-right" }), h("div", { key: '238a3269b2a12d528e8a1889d3109ee319c7fd88', class: "side side-bottom" }), h("div", { key: 'b02eec6c102d7e9fb03ef24dfce7c75e081ff1c4', class: "side side-left" })), !captureState.showFlipAnimation && !captureState.showSuccessAnimation && (h("div", { key: '15588129ca8027a6ec1c81d70001142986966826', class: `guide-text ${this.showPerformanceMessage ? 'performance-warning-text' : ''}` }, this.getGuideText(captureState.step))), captureState.step === 'back' && !captureState.showFlipAnimation && !captureState.showSuccessAnimation && (h("div", { key: 'f15fd9bddc20c54afcca7be79c3cf2f9ee2b74f7', class: "back-capture-section" }, h("div", { key: 'e3284e1301840a9555857fa879de9f4ca91dc21b', class: "back-capture-buttons" }, (!this.useDocumentDetector || this.performanceDegradedMode || this.showManualCaptureButton) && (h("button", { key: '8508d13e117deb3b223308497b1db976643b86f2', class: "capture-button primary-button", onClick: () => this.takeManualScreenshot(), type: "button", disabled: this.processingButton !== null }, this.processingButton === 'capture-back' && (h("span", { key: '99bd464541d9ee8589bc11e937c5ad6bca9d95c8', class: "button-spinner" })), "Capturar Reverso")), h("button", { key: '3de5f0a142f9dfdfe4578c0fcbe004bb5fe94c56', class: "skip-button", onClick: () => this.skipBackCapture(), type: "button", disabled: this.processingButton !== null }, this.processingButton === 'skip-back' && (h("span", { key: '268ce949bf5155b3729298f23eea0d7ec15b3590', class: "button-spinner" })), this.enableBackDocumentTimer && this.backDocumentTimerRemaining > 0
|
|
22226
19711
|
? `Saltar reverso (${this.backDocumentTimerRemaining}s)`
|
|
22227
|
-
: 'Saltar reverso')))), captureState.isVideoActive && (h("div", { key: '
|
|
19712
|
+
: 'Saltar reverso')))), captureState.isVideoActive && (h("div", { key: 'bb5c00ad882c303d8a2b6ddc79c9d5b27ff9824e', class: "camera-controls" }, h("button", { key: '7d231b550b58a8336f125a1a7fe7235c8bb3d7dd', class: `camera-selector-button ${this.isSwitchingCamera ? 'loading' : ''}`, onClick: () => this.toggleCameraSelector(), type: "button", title: "Seleccionar c\u00E1mara", disabled: this.isSwitchingCamera }, this.isSwitchingCamera ? (h("div", { class: "button-spinner" })) : ('Cámaras')))), this.showCameraSelector && cameraInfo.availableCameras.length > 0 && (h("div", { key: '95d1e0d0937f7ef821ff3ad167cd42e25fd1c87f', class: "camera-selector-dropdown" }, h("div", { key: 'e42219e5895c82f40c559c27c4f80f3145fc0a0e', class: "camera-selector-header" }, h("span", { key: '544a6fb2e08211ab6c44b0bfb281124bee318fae' }, "Seleccionar C\u00E1mara"), h("button", { key: '7c4a71243278491ee7dbcc7ab2564bc7e92f5da3', class: "close-selector", onClick: () => this.toggleCameraSelector(), type: "button" }, "\u00D7")), h("div", { key: 'c9d24e0bd906d20370214fdfd24ae91abfda98e1', class: "camera-list" }, cameraInfo.availableCameras.map((camera) => (h("button", { key: camera.id, class: `camera-option ${cameraInfo.selectedCameraId === camera.id ? 'selected' : ''}`, onClick: () => this.handleCameraSwitch(camera.id), type: "button" }, h("span", { class: "camera-label" }, camera.label || `Cámara ${cameraInfo.availableCameras.indexOf(camera) + 1}`, camera.hasAutofocus && (h("span", { class: "autofocus-icon", title: "Autofoco disponible" }, "\u29BF"))), cameraInfo.selectedCameraId === camera.id && (h("span", { class: "selected-indicator" }, "\u2713")))))), h("div", { key: '8c2e1d2ed02bc55c84f3f726e5be577686d0f32d', class: "device-info" }, h("small", { key: '142410a86e4f819b96ffc9573816994351588a3e' }, "Dispositivo: ", cameraInfo.deviceType)))), this.showManualCaptureButton && captureState.step === 'front' && !captureState.showFlipAnimation && !captureState.showSuccessAnimation && (h("div", { key: '48c33b2d6c8c80d18fba6e5f454faaa24c28fbd9', class: "manual-capture-section" }, h("button", { key: 'e3d5bfe9ef8b8f16bf669b66bce4e7a500113798', class: "manual-capture-button", onClick: () => this.takeManualScreenshot(), type: "button", disabled: this.processingButton !== null }, this.processingButton === 'capture-front' && (h("span", { key: 'f50640fe4308c765011e6ed175528920228df5e7', class: "button-spinner" })), "Capturar Frente"))))), captureState.isCapturing && (h("div", { key: '080ab315293fa1fe5b1d97aa2511a2ffe2b013f4', class: "capture-animation" })), captureState.showFlipAnimation && (h("div", { key: 'b062c546af50b799bb1fb7dda07b3ffa601c4bac', class: "flip-animation" }, h("div", { key: 'f7162dc31673c7db1d8e03a658a722a3d323b28e', class: "id-card-icon" }), h("div", { key: 'd950952b480342d80d37df5c48031d72be4ac01a', class: "flip-text" }, "\u00A1Voltea tu identificaci\u00F3n!"))), captureState.showSuccessAnimation && (h("div", { key: 'bd576fd28065aa712e42636c5fd0e3566d26cc25', class: "success-animation" }, h("div", { key: '6ca5c24510df790bd1c955c5e2936909c4767560', class: "check-icon" }), h("div", { key: '3420164eacddbe1a9aa0a181528ba0be7683af56', class: "success-text" }, "\u00A1Proceso completado!"))), h("div", { key: '8ec2b295b233e7bb8ab0cc1c183adedd4e3c7e04', class: `component-status status-${this.currentStatus.type}` }, (this.currentStatus.type === 'loading' || this.currentStatus.type === 'initializing') && (h("div", { key: '97c8e7e6219984673ebc631da111c17bf72a83cb', class: "status-spinner" })), h("div", { key: '7ca06c48f295892ff77eceff6245891ef7d9dd5e', class: "status-content" }, h("div", { key: '08056c7ec8fd66d23e0b6714c08aeccc092cf46a', class: "status-message" }, this.currentStatus.message), this.currentStatus.description && (h("div", { key: '1e32ca14de53cc2f105822ed5a58e691918b307b', class: "status-description" }, this.currentStatus.description)))), this.debug && (h("div", { key: 'c25022d9aadd37ead9ae7d1cf7c7d916cdeb9cc1', class: "performance-monitor" }, h("div", { key: 'f0f99c7e820532432ba64726ef0c2aeabeb3309f', class: "performance-expanded" }, h("div", { key: 'e839e90c9cb0f33068ac3311e41914aa52610149', class: "metrics-row" }, h("div", { key: '9f74f4877a048e63f542f2df54f569f79d6f8bd0', class: "metric-compact" }, h("span", { key: '21ec7255706d6fb2cfec035c4be92295ee0216b6', class: "metric-label" }, "FPS"), h("span", { key: 'c8be17f3dc752304bf6b7fd9746f11783f7ff6ca', class: `metric-value ${this.performanceData.fps < 15 ? 'warning' : this.performanceData.fps < 10 ? 'danger' : 'good'}` }, this.performanceData.fps)), h("div", { key: '79187257ea30ead7fb41534a94272a3a855e050b', class: "metric-compact" }, h("span", { key: 'cc53dc282c1fe4234217207c2085fa2be06a5458', class: "metric-label" }, "MEM"), h("span", { key: '032002ff63b3a2349b34833668fed8d6337e2063', class: `metric-value ${this.performanceData.memoryUsage > 100 ? 'warning' : this.performanceData.memoryUsage > 200 ? 'danger' : 'good'}` }, this.performanceData.memoryUsage, "MB"))), h("div", { key: 'e628febd5bbfb9f593e029b10827635ddd0344fb', class: "metrics-row" }, h("div", { key: 'b2fe558bab709ff6b6781648b13ebc66238f3298', class: "metric-compact" }, h("span", { key: 'd7d816aff11503657781f8ebe9cb5f0f07c7279e', class: "metric-label" }, "INF"), h("span", { key: '3d735d092b5b39d0e96f4ac59b3bf2acde739fab', class: `metric-value ${this.performanceData.inferenceTime > 100 ? 'warning' : this.performanceData.inferenceTime > 200 ? 'danger' : 'good'}` }, this.performanceData.inferenceTime, "ms")), h("div", { key: '9a83fd4fe43e8a3760aaea1f134c3101b8757681', class: "metric-compact" }, h("span", { key: '8136ab82b50230537f19cd58ed2da0956d291287', class: "metric-label" }, "FRAME"), h("span", { key: '6221cc10edff8c4b0e4034a3734deb548416a3e6', class: `metric-value ${this.performanceData.frameProcessingTime > 50 ? 'warning' : this.performanceData.frameProcessingTime > 100 ? 'danger' : 'good'}` }, this.performanceData.frameProcessingTime, "ms"))), h("div", { key: 'a31bad44d5c2c5fd5417ed82589c0f103bba1d32', class: "metrics-row" }, h("div", { key: '1441d11e0d83b3b44dfa963e415c3074691eb4f2', class: "metric-compact" }, h("span", { key: '9fe5643129aa7a842f75644b6f71b1ff80993f1b', class: "metric-label" }, "DET"), h("span", { key: '0604065a3867e71a745bfb4e804c7e96048cb70e', class: "metric-value good" }, this.performanceData.successfulDetections, "/", this.performanceData.totalDetections)), h("div", { key: 'daff0fede819f2b59a4ddb83560dc53f6151c2c9', class: "metric-compact" }, h("span", { key: '75a55c4a4e36b98af3620866ec6f7842b9ef81f7', class: "metric-label" }, "RATE"), h("span", { key: '61776c3fd4c3200d5e18cc28d917c538b282625a', class: `metric-value ${this.performanceData.detectionRate < 30 ? 'danger' : this.performanceData.detectionRate < 60 ? 'warning' : 'good'}` }, this.performanceData.detectionRate, "%")))))), h("div", { key: '4092c684ee3a148ec40e266fd16a718f2c2f2f52', class: "watermark" }, h("img", { key: 'd7bae6157d22675f8b71dbf1afdf345374398c82', src: "https://storage.googleapis.com/jaak-static/commons/powered-by-jaak.png", alt: "Powered by Jaak" }))))));
|
|
22228
19713
|
}
|
|
22229
19714
|
// Utility methods
|
|
22230
19715
|
updateDetectionBoxes(boxes) {
|
|
@@ -22732,7 +20217,7 @@ const JaakStamps$1 = /*@__PURE__*/ proxyCustomElement(class JaakStamps extends H
|
|
|
22732
20217
|
catch (error) {
|
|
22733
20218
|
}
|
|
22734
20219
|
}
|
|
22735
|
-
completeProcess(skippedBack = false) {
|
|
20220
|
+
async completeProcess(skippedBack = false) {
|
|
22736
20221
|
this.stateManager.updateCaptureState({
|
|
22737
20222
|
step: 'completed',
|
|
22738
20223
|
showSuccessAnimation: true
|
|
@@ -22747,6 +20232,15 @@ const JaakStamps$1 = /*@__PURE__*/ proxyCustomElement(class JaakStamps extends H
|
|
|
22747
20232
|
...capturedImages,
|
|
22748
20233
|
timestamp: new Date().toISOString()
|
|
22749
20234
|
};
|
|
20235
|
+
// Flush all traces to collector before emitting capture completed
|
|
20236
|
+
if (this.tracingService) {
|
|
20237
|
+
try {
|
|
20238
|
+
await this.tracingService.flush();
|
|
20239
|
+
}
|
|
20240
|
+
catch (error) {
|
|
20241
|
+
console.error('[my-component] Failed to flush traces:', error);
|
|
20242
|
+
}
|
|
20243
|
+
}
|
|
22750
20244
|
this.captureCompleted.emit(finalImages);
|
|
22751
20245
|
setTimeout(() => {
|
|
22752
20246
|
this.stateManager.updateCaptureState({ showSuccessAnimation: false });
|