1 | /*!
|
2 | * OpenUI5
|
3 | * (c) Copyright 2009-2022 SAP SE or an SAP affiliate company.
|
4 | * Licensed under the Apache License, Version 2.0 - see LICENSE.txt.
|
5 | */
|
6 |
|
7 | /*
|
8 | * This module should provide the foundation for tracing capabilities. There are three different namespaces.
|
9 | * <ul>
|
10 | * <li><code>jQuery.sap.interaction</code> - contains logic for the detection of interaction traces</li>
|
11 | * <li><code>jQuery.sap.fesr</code> - handles the creation and transmission of frontend-subrecords http-headers</li>
|
12 | * <li><code>jQuery.sap.passport</code> - handles the creation of the passport http-header, which is used by fesr and the
|
13 | * E2eTraceLib module</li>
|
14 | * </ul>
|
15 | * All measurement activities get recorded by jquery.sap.measure, which is located in jquery.sap.global. As the initial
|
16 | * interaction is the app startup, we need the measuring capability already before this module is loaded.
|
17 | */
|
18 | sap.ui.define(['jquery.sap.global', 'sap/ui/performance/trace/Passport', 'sap/ui/performance/trace/Interaction', 'sap/ui/performance/trace/FESR', 'sap/base/Log', 'sap/ui/Global'],
|
19 | function(jQuery, Passport, Interaction, FESR, Log) {
|
20 | ;
|
21 |
|
22 |
|
23 | function logSupportWarning() {
|
24 | // in case we do not have this API measurement is superfluous due to insufficient performance data
|
25 | if (!(window.performance && window.performance.getEntries)) {
|
26 | Log.warning("Interaction tracking is not supported on browsers with insufficient performance API");
|
27 | }
|
28 | }
|
29 |
|
30 | /**
|
31 | * @namespace Provides base functionality for interaction detection heuristics & API<br>
|
32 | * <p>
|
33 | * Interaction detection works through the detection of relevant events and tracking of rendering activities.<br>
|
34 | * An example:<br>
|
35 | * The user clicks on a button<br>
|
36 | * -> "click" event gets detected via notification (jQuery.sap.interaction.notifyEventStart)<br>
|
37 | * -> a click handler is registered on the button, so this is an interaction start (jQuery.sap.interaction.notifyStepStart)<br>
|
38 | * -> some requests are made and rendering has finished (jQuery.sap.interaction.notifyStepEnd)<br>
|
39 | * </p>
|
40 | * All measurement takes place in {@link jQuery.sap.measure}<br>.
|
41 | *
|
42 | * Namespace exists since 1.32 and became public API since 1.36.
|
43 | *
|
44 | * @name jQuery.sap.interaction
|
45 | * @static
|
46 | * @public
|
47 | * @since 1.36
|
48 | * @deprecated since 1.58 use {@link module:sap/ui/performance/trace/Interaction} instead
|
49 | */
|
50 | jQuery.sap.interaction = {};
|
51 |
|
52 | /**
|
53 | * Enables the interaction tracking.
|
54 | *
|
55 | * @param {boolean} bActive state of the interaction detection
|
56 | * @public
|
57 | * @since 1.36
|
58 | */
|
59 | jQuery.sap.interaction.setActive = function() {
|
60 | logSupportWarning();
|
61 | Interaction.setActive.apply(this, arguments);
|
62 | };
|
63 |
|
64 | /**
|
65 | * Returns true if the interaction detection was enabled explicitly, or implicitly along with fesr.
|
66 | *
|
67 | * @return {boolean} bActive state of the interaction detection
|
68 | * @private
|
69 | * @since 1.32
|
70 | */
|
71 | jQuery.sap.interaction.getActive = Interaction.getActive;
|
72 |
|
73 | /**
|
74 | * This method starts the actual interaction measurement when all criteria are met. As it is the starting point
|
75 | * for the new interaction the creation of the FESR headers for the last interaction is triggered here, so that
|
76 | * the headers can be sent with the first request of the current interaction.<br>
|
77 | *
|
78 | * @param {sap.ui.core.Element} oElement Element on which the interaction has been triggered
|
79 | * @param {boolean} bForce forces the interaction to start independently from a currently active browser event
|
80 | * @private
|
81 | * @since 1.32
|
82 | */
|
83 | jQuery.sap.interaction.notifyStepStart = Interaction.notifyStepStart;
|
84 |
|
85 | /**
|
86 | * This method ends the started interaction measurement.
|
87 | *
|
88 | * @private
|
89 | * @since 1.32
|
90 | */
|
91 | jQuery.sap.interaction.notifyStepEnd = Interaction.notifyStepEnd;
|
92 |
|
93 | /**
|
94 | * This method notifies if a relevant event has been triggered.
|
95 | *
|
96 | * @param {Event} oEvent event whose processing has started
|
97 | * @private
|
98 | * @since 1.32
|
99 | */
|
100 | jQuery.sap.interaction.notifyEventStart = Interaction.notifyEventStart;
|
101 |
|
102 | /**
|
103 | * This method notifies if a scroll event has been triggered. Some controls require this special treatment,
|
104 | * as the generic detection process via notifyEventStart is not sufficient.
|
105 | *
|
106 | * @param {Event} oEvent scroll event whose processing has started
|
107 | * @private
|
108 | * @since 1.36.2
|
109 | */
|
110 | jQuery.sap.interaction.notifyScrollEvent = Interaction.notifyScrollEvent;
|
111 |
|
112 | /**
|
113 | * This method notifies if a relevant event has ended by detecting another interaction.
|
114 | *
|
115 | * @private
|
116 | * @since 1.32
|
117 | */
|
118 | jQuery.sap.interaction.notifyEventEnd = Interaction.notifyEventEnd;
|
119 |
|
120 | /**
|
121 | * This method sets the component name for an interaction.
|
122 | *
|
123 | * @private
|
124 | * @since 1.38.5
|
125 | */
|
126 | jQuery.sap.interaction.setStepComponent = Interaction.setStepComponent;
|
127 |
|
128 |
|
129 | /**
|
130 | * @namespace FESR API, consumed by E2eTraceLib instead of former EppLib.js <br>
|
131 | *<p>
|
132 | * Provides functionality for creating the headers for the frontend-subrecords which will be sent with each
|
133 | * first request of an interaction. The headers have a specific format, you may have a look at the createFESR
|
134 | * methods.<br>
|
135 | *</p><p>
|
136 | * There is a special order in which things are happening: <br>
|
137 | * 1. Interaction starts<br>
|
138 | * 1.1. Request 1.1 sent<br>
|
139 | * 1.2. Request 1.2 sent<br>
|
140 | * 2. Interaction starts<br>
|
141 | * 2.1 Creation of FESR for 1. interaction<br>
|
142 | * 2.2 Request 2.1 sent with FESR header for 1. interaction<br>
|
143 | * ...<br>
|
144 | *</p>
|
145 | * @name jQuery.sap.fesr
|
146 | * @static
|
147 | * @private
|
148 | * @deprecated since 1.58 use {@link module:sap/ui/performance/trace/FESR} instead
|
149 | */
|
150 | jQuery.sap.fesr = {};
|
151 |
|
152 | /**
|
153 | * @param {boolean} bActive state of the FESR header creation
|
154 | * @private
|
155 | * @since 1.32
|
156 | */
|
157 | jQuery.sap.fesr.setActive = function() {
|
158 | logSupportWarning();
|
159 | FESR.setActive.apply(this, arguments);
|
160 | };
|
161 |
|
162 | /**
|
163 | * @return {boolean} state of the FESR header creation
|
164 | * @private
|
165 | * @since 1.36.2
|
166 | */
|
167 | jQuery.sap.fesr.getActive = FESR.getActive;
|
168 |
|
169 | /**
|
170 | * @return {string} ID of the currently processed transaction
|
171 | * @private
|
172 | * @since 1.32
|
173 | */
|
174 | jQuery.sap.fesr.getCurrentTransactionId = Passport.getTransactionId;
|
175 |
|
176 | /**
|
177 | * @return {string} Root ID of the current session
|
178 | * @private
|
179 | * @since 1.32
|
180 | */
|
181 | jQuery.sap.fesr.getRootId = Passport.getRootId;
|
182 |
|
183 |
|
184 | /**
|
185 | * @param {float} iDuration increase busy duration of pending interaction by this value
|
186 | * @private
|
187 | * @since 1.36.2
|
188 | */
|
189 | jQuery.sap.fesr.addBusyDuration = Interaction.addBusyDuration;
|
190 |
|
191 |
|
192 | /**
|
193 | * @namespace Passport implementation, former EppLib.js <br>
|
194 | *
|
195 | * Provides functionality which was former located in the EppLib.js, but as the PASSPORT header is mandatory
|
196 | * for correct assignment of the FESR headers some functionality had to be moved to here. The actual tracing
|
197 | * functionality of EppLib.js remained in the original file.
|
198 | *
|
199 | * @name jQuery.sap.passport
|
200 | * @static
|
201 | * @private
|
202 | * @deprecated since 1.58 use {@link module:sap/ui/performance/trace/Passport} instead
|
203 | */
|
204 | jQuery.sap.passport = {};
|
205 |
|
206 | /**
|
207 | * @param {boolean} bActive state of the Passport header creation
|
208 | * @private
|
209 | * @since 1.32
|
210 | */
|
211 | jQuery.sap.passport.setActive = Passport.setActive;
|
212 |
|
213 |
|
214 | /**
|
215 | * @param {string} lvl tracing level to be calculated
|
216 | * @return {int[]} Array with two int representation of characters for trace level
|
217 | * @private
|
218 | * @since 1.32
|
219 | */
|
220 | jQuery.sap.passport.traceFlags = Passport.traceFlags;
|
221 |
|
222 | // @EVO-TODO This should be part of configuration. It is here as this module is required before the actual configuration is loaded.
|
223 | function getInitialFESRState() {
|
224 | var bActive = !!document.querySelector("meta[name=sap-ui-fesr][content=true]"),
|
225 | aParamMatches = window.location.search.match(/[\?|&]sap-ui-(?:xx-)?fesr=(true|x|X|false)&?/);
|
226 | if (aParamMatches) {
|
227 | bActive = aParamMatches[1] && aParamMatches[1] != "false";
|
228 | }
|
229 | return bActive;
|
230 | }
|
231 |
|
232 | // start initial interaction
|
233 | jQuery.sap.interaction.notifyStepStart(null, true);
|
234 |
|
235 | // activate FESR header generation
|
236 | FESR.setActive(getInitialFESRState());
|
237 |
|
238 | // *********** Include E2E-Trace Scripts *************
|
239 | if (/sap-ui-xx-e2e-trace=(true|x|X)/.test(location.search)) {
|
240 | sap.ui.requireSync("sap/ui/core/support/trace/E2eTraceLib");
|
241 | }
|
242 |
|
243 | return jQuery;
|
244 |
|
245 | });
|