@coralogix/browser 0.0.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/README.md +104 -0
- package/package.json +32 -0
- package/src/CoralogixExporter.d.ts +15 -0
- package/src/CoralogixExporter.js +217 -0
- package/src/CoralogixExporter.js.map +1 -0
- package/src/CoralogixPropgator.d.ts +3 -0
- package/src/CoralogixPropgator.js +9 -0
- package/src/CoralogixPropgator.js.map +1 -0
- package/src/CoralogixSpanAttributesProcessor.d.ts +18 -0
- package/src/CoralogixSpanAttributesProcessor.js +64 -0
- package/src/CoralogixSpanAttributesProcessor.js.map +1 -0
- package/src/CoralogixWebTracerProvider.d.ts +3 -0
- package/src/CoralogixWebTracerProvider.js +11 -0
- package/src/CoralogixWebTracerProvider.js.map +1 -0
- package/src/constants.d.ts +93 -0
- package/src/constants.js +111 -0
- package/src/constants.js.map +1 -0
- package/src/helpers.d.ts +2 -0
- package/src/helpers.js +5 -0
- package/src/helpers.js.map +1 -0
- package/src/index.d.ts +2 -0
- package/src/index.js +203 -0
- package/src/index.js.map +1 -0
- package/src/instrumentations/CoralogixCustomLogInstrumentation.d.ts +14 -0
- package/src/instrumentations/CoralogixCustomLogInstrumentation.js +41 -0
- package/src/instrumentations/CoralogixCustomLogInstrumentation.js.map +1 -0
- package/src/instrumentations/CoralogixErrorInstrumentation.d.ts +32 -0
- package/src/instrumentations/CoralogixErrorInstrumentation.js +226 -0
- package/src/instrumentations/CoralogixErrorInstrumentation.js.map +1 -0
- package/src/instrumentations/CoralogixFetchInstrumentation.d.ts +8 -0
- package/src/instrumentations/CoralogixFetchInstrumentation.js +36 -0
- package/src/instrumentations/CoralogixFetchInstrumentation.js.map +1 -0
- package/src/instrumentations/CoralogixLongTaskInstrumentation.d.ts +12 -0
- package/src/instrumentations/CoralogixLongTaskInstrumentation.js +71 -0
- package/src/instrumentations/CoralogixLongTaskInstrumentation.js.map +1 -0
- package/src/instrumentations/CoralogixResourcesInstrumentation.d.ts +13 -0
- package/src/instrumentations/CoralogixResourcesInstrumentation.js +129 -0
- package/src/instrumentations/CoralogixResourcesInstrumentation.js.map +1 -0
- package/src/instrumentations/CoralogixUserInteractionInstrumentation.d.ts +17 -0
- package/src/instrumentations/CoralogixUserInteractionInstrumentation.js +79 -0
- package/src/instrumentations/CoralogixUserInteractionInstrumentation.js.map +1 -0
- package/src/instrumentations/CoralogixWebVitalsInstrumentation.d.ts +18 -0
- package/src/instrumentations/CoralogixWebVitalsInstrumentation.js +160 -0
- package/src/instrumentations/CoralogixWebVitalsInstrumentation.js.map +1 -0
- package/src/instrumentations/CoralogixXhrInstrumentation.d.ts +7 -0
- package/src/instrumentations/CoralogixXhrInstrumentation.js +33 -0
- package/src/instrumentations/CoralogixXhrInstrumentation.js.map +1 -0
- package/src/instrumentations/instrumentation.consts.d.ts +18 -0
- package/src/instrumentations/instrumentation.consts.js +57 -0
- package/src/instrumentations/instrumentation.consts.js.map +1 -0
- package/src/instrumentations/instrumentation.helper.d.ts +1 -0
- package/src/instrumentations/instrumentation.helper.js +4 -0
- package/src/instrumentations/instrumentation.helper.js.map +1 -0
- package/src/instrumentations/instrumentation.model.d.ts +30 -0
- package/src/instrumentations/instrumentation.model.js +18 -0
- package/src/instrumentations/instrumentation.model.js.map +1 -0
- package/src/sessionManager.d.ts +12 -0
- package/src/sessionManager.js +69 -0
- package/src/sessionManager.js.map +1 -0
- package/src/tools/addEventListener.d.ts +54 -0
- package/src/tools/addEventListener.js +35 -0
- package/src/tools/addEventListener.js.map +1 -0
- package/src/tools/getGlobalObject.d.ts +5 -0
- package/src/tools/getGlobalObject.js +36 -0
- package/src/tools/getGlobalObject.js.map +1 -0
- package/src/tools/getZoneJsOriginalDom.d.ts +9 -0
- package/src/tools/getZoneJsOriginalDom.js +17 -0
- package/src/tools/getZoneJsOriginalDom.js.map +1 -0
- package/src/types-external.d.ts +8 -0
- package/src/types-external.js +10 -0
- package/src/types-external.js.map +1 -0
- package/src/types.d.ts +270 -0
- package/src/types.js +27 -0
- package/src/types.js.map +1 -0
- package/src/utils.d.ts +24 -0
- package/src/utils.js +156 -0
- package/src/utils.js.map +1 -0
- package/src/version.d.ts +1 -0
- package/src/version.js +2 -0
- package/src/version.js.map +1 -0
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { __extends } from "tslib";
|
|
2
|
+
import { getElementXPath } from '@opentelemetry/sdk-trace-web';
|
|
3
|
+
import { InstrumentationBase, } from '@opentelemetry/instrumentation';
|
|
4
|
+
import { unwrap, wrap } from 'shimmer';
|
|
5
|
+
import { CoralogixAttributes } from '../constants';
|
|
6
|
+
import { CoralogixEventType } from '../types';
|
|
7
|
+
import { CoralogixLogSeverity } from '../types-external';
|
|
8
|
+
import { getCircularReplacer } from '../utils';
|
|
9
|
+
export var ERROR_INSTRUMENTATION_NAME = 'errors';
|
|
10
|
+
export var ERROR_INSTRUMENTATION_VERSION = '1';
|
|
11
|
+
export var ErrorAttributes = {
|
|
12
|
+
TYPE: 'error_type',
|
|
13
|
+
STACK: 'error_stack',
|
|
14
|
+
MESSAGE: 'error_message',
|
|
15
|
+
};
|
|
16
|
+
export var ErrorSource;
|
|
17
|
+
(function (ErrorSource) {
|
|
18
|
+
ErrorSource["CONSOLE"] = "console";
|
|
19
|
+
ErrorSource["WINDOW"] = "window";
|
|
20
|
+
ErrorSource["UNHANDLED_REJECTION"] = "unhandledrejection";
|
|
21
|
+
ErrorSource["DOCUMENT"] = "document";
|
|
22
|
+
})(ErrorSource || (ErrorSource = {}));
|
|
23
|
+
var STACK_LIMIT = 4096;
|
|
24
|
+
var MESSAGE_LIMIT = 1024;
|
|
25
|
+
function addStackIfUseful(span, err) {
|
|
26
|
+
var stack = err.stack;
|
|
27
|
+
var hasStack = !!(stack === null || stack === void 0 ? void 0 : stack.includes('at '));
|
|
28
|
+
if (err && hasStack) {
|
|
29
|
+
span.setAttribute(ErrorAttributes.STACK, stack.substring(0, STACK_LIMIT));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
var _consoleErrorHandler = function (that) {
|
|
33
|
+
return function (original) {
|
|
34
|
+
return function () {
|
|
35
|
+
var args = [];
|
|
36
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
37
|
+
args[_i] = arguments[_i];
|
|
38
|
+
}
|
|
39
|
+
that.report(ErrorSource.CONSOLE, args);
|
|
40
|
+
return original.apply(that, args);
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
var _errorListener = function (that) {
|
|
45
|
+
return function (event) {
|
|
46
|
+
that.report(ErrorSource.WINDOW, event);
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
var _unhandledRejectionListener = function (that) {
|
|
50
|
+
return function (event) {
|
|
51
|
+
that.report(ErrorSource.UNHANDLED_REJECTION, event.reason);
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
var _documentErrorListener = function (that) {
|
|
55
|
+
return function (event) {
|
|
56
|
+
that.report(ErrorSource.DOCUMENT, event);
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
function addErrorDefaultAttributes(span) {
|
|
60
|
+
span.setAttribute(CoralogixAttributes.EVENT_TYPE, CoralogixEventType.ERROR);
|
|
61
|
+
span.setAttribute(CoralogixAttributes.SEVERITY, CoralogixLogSeverity.Error);
|
|
62
|
+
}
|
|
63
|
+
var CoralogixErrorInstrumentation = /** @class */ (function (_super) {
|
|
64
|
+
__extends(CoralogixErrorInstrumentation, _super);
|
|
65
|
+
function CoralogixErrorInstrumentation(config) {
|
|
66
|
+
var _this = _super.call(this, ERROR_INSTRUMENTATION_NAME, ERROR_INSTRUMENTATION_VERSION, config) || this;
|
|
67
|
+
_this.parseErrorObject = function (obj) {
|
|
68
|
+
var _a;
|
|
69
|
+
return (_a = obj === null || obj === void 0 ? void 0 : obj.message) !== null && _a !== void 0 ? _a : JSON.stringify(obj, getCircularReplacer());
|
|
70
|
+
};
|
|
71
|
+
_this.ignoreErrors = config.ignoreErrors;
|
|
72
|
+
return _this;
|
|
73
|
+
}
|
|
74
|
+
CoralogixErrorInstrumentation.prototype.init = function () { };
|
|
75
|
+
CoralogixErrorInstrumentation.prototype.enable = function () {
|
|
76
|
+
wrap(console, 'error', _consoleErrorHandler(this));
|
|
77
|
+
window.addEventListener('error', _errorListener(this));
|
|
78
|
+
window.addEventListener('unhandledrejection', _unhandledRejectionListener(this));
|
|
79
|
+
document.documentElement.addEventListener('error', _documentErrorListener(this), {
|
|
80
|
+
capture: true,
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
CoralogixErrorInstrumentation.prototype.disable = function () {
|
|
84
|
+
unwrap(console, 'error');
|
|
85
|
+
window.removeEventListener('error', _errorListener(this));
|
|
86
|
+
window.removeEventListener('unhandledrejection', _unhandledRejectionListener(this));
|
|
87
|
+
document.documentElement.removeEventListener('error', _documentErrorListener(this), { capture: true });
|
|
88
|
+
};
|
|
89
|
+
CoralogixErrorInstrumentation.prototype.report = function (source, arg) {
|
|
90
|
+
var _this = this;
|
|
91
|
+
if (this._shouldIgnoreError(arg)) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (arg instanceof Array) {
|
|
95
|
+
if (arg.length === 0) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
switch (true) {
|
|
100
|
+
case arg instanceof Error:
|
|
101
|
+
this.reportError(source, arg);
|
|
102
|
+
break;
|
|
103
|
+
case arg instanceof ErrorEvent:
|
|
104
|
+
this.reportErrorEvent(source, arg);
|
|
105
|
+
break;
|
|
106
|
+
case arg instanceof Event:
|
|
107
|
+
this.reportEvent(source, arg);
|
|
108
|
+
break;
|
|
109
|
+
case typeof arg === 'string':
|
|
110
|
+
this.reportString(source, arg);
|
|
111
|
+
break;
|
|
112
|
+
case arg instanceof Array: {
|
|
113
|
+
// if any arguments are Errors then add the stack trace even though the message is handled differently
|
|
114
|
+
var firstError = arg.find(function (x) { return x instanceof Error; });
|
|
115
|
+
var message = arg
|
|
116
|
+
.map(function (msg) {
|
|
117
|
+
return typeof msg === 'string' ? msg : _this.parseErrorObject(msg);
|
|
118
|
+
})
|
|
119
|
+
.join(' ');
|
|
120
|
+
this.reportString(source, message, firstError);
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
default:
|
|
124
|
+
this.reportString(source, typeof arg === 'string' ? arg : this.getPossibleEventMessage(arg));
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
CoralogixErrorInstrumentation.prototype.reportError = function (source, err) {
|
|
128
|
+
var message = err.message, name = err.name;
|
|
129
|
+
var span = this.tracer.startSpan('error');
|
|
130
|
+
var cleanMessage = message.split('\n')[0];
|
|
131
|
+
addErrorDefaultAttributes(span);
|
|
132
|
+
span.setAttribute(CoralogixAttributes.TIMESTAMP, Date.now());
|
|
133
|
+
span.setAttribute(CoralogixAttributes.SOURCE, source);
|
|
134
|
+
span.setAttribute(ErrorAttributes.TYPE, name);
|
|
135
|
+
span.setAttribute(ErrorAttributes.MESSAGE, cleanMessage);
|
|
136
|
+
addStackIfUseful(span, err);
|
|
137
|
+
span.end();
|
|
138
|
+
};
|
|
139
|
+
CoralogixErrorInstrumentation.prototype.reportString = function (source, message, firstError) {
|
|
140
|
+
var span = this.tracer.startSpan(source);
|
|
141
|
+
addErrorDefaultAttributes(span);
|
|
142
|
+
span.setAttribute(CoralogixAttributes.SOURCE, source);
|
|
143
|
+
span.setAttribute(ErrorAttributes.MESSAGE, message === null || message === void 0 ? void 0 : message.substring(0, MESSAGE_LIMIT));
|
|
144
|
+
if (firstError) {
|
|
145
|
+
addStackIfUseful(span, firstError);
|
|
146
|
+
}
|
|
147
|
+
span.end();
|
|
148
|
+
};
|
|
149
|
+
CoralogixErrorInstrumentation.prototype.reportErrorEvent = function (source, _a) {
|
|
150
|
+
var error = _a.error, message = _a.message;
|
|
151
|
+
var event = error !== null && error !== void 0 ? error : message;
|
|
152
|
+
this.report(source, event);
|
|
153
|
+
};
|
|
154
|
+
CoralogixErrorInstrumentation.prototype.reportEvent = function (source, ev) {
|
|
155
|
+
if (!ev.target) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
var span = this.tracer.startSpan(source);
|
|
159
|
+
addErrorDefaultAttributes(span);
|
|
160
|
+
span.setAttribute(CoralogixAttributes.TIMESTAMP, Date.now());
|
|
161
|
+
span.setAttribute(CoralogixAttributes.SOURCE, source);
|
|
162
|
+
if (ev.target) {
|
|
163
|
+
span.setAttribute('target_element', ev.target.tagName);
|
|
164
|
+
span.setAttribute('target_xpath', getElementXPath(ev.target, true));
|
|
165
|
+
span.setAttribute('target_src', ev.target.src);
|
|
166
|
+
}
|
|
167
|
+
span.end();
|
|
168
|
+
};
|
|
169
|
+
CoralogixErrorInstrumentation.prototype.getPossibleEventMessage = function (event) {
|
|
170
|
+
var message = event.message, statusMessage = event.statusMessage;
|
|
171
|
+
if (message && typeof message === 'string') {
|
|
172
|
+
return message;
|
|
173
|
+
}
|
|
174
|
+
// GrpcStatusEvent
|
|
175
|
+
if (statusMessage && typeof statusMessage === 'string') {
|
|
176
|
+
return statusMessage;
|
|
177
|
+
}
|
|
178
|
+
return JSON.stringify(event);
|
|
179
|
+
};
|
|
180
|
+
CoralogixErrorInstrumentation.prototype._shouldIgnoreError = function (arg) {
|
|
181
|
+
var _a;
|
|
182
|
+
if (!((_a = this.ignoreErrors) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
var toBeMatched = '';
|
|
186
|
+
switch (true) {
|
|
187
|
+
case arg instanceof Error: {
|
|
188
|
+
var _b = arg, name_1 = _b.name, message = _b.message;
|
|
189
|
+
toBeMatched = name_1 + ' ' + message;
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
case arg instanceof ErrorEvent: {
|
|
193
|
+
var message = arg.message;
|
|
194
|
+
toBeMatched = message;
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
case arg instanceof Event: {
|
|
198
|
+
var type = arg.type;
|
|
199
|
+
toBeMatched = type;
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
case typeof arg === 'string': {
|
|
203
|
+
toBeMatched = arg;
|
|
204
|
+
break;
|
|
205
|
+
}
|
|
206
|
+
case arg instanceof Array: {
|
|
207
|
+
toBeMatched = arg.join(' ');
|
|
208
|
+
break;
|
|
209
|
+
}
|
|
210
|
+
default:
|
|
211
|
+
toBeMatched = this.getPossibleEventMessage(arg);
|
|
212
|
+
}
|
|
213
|
+
if (toBeMatched === null || toBeMatched === void 0 ? void 0 : toBeMatched.match) {
|
|
214
|
+
for (var _i = 0, _c = this.ignoreErrors; _i < _c.length; _i++) {
|
|
215
|
+
var ignoreError = _c[_i];
|
|
216
|
+
if (toBeMatched.match(ignoreError)) {
|
|
217
|
+
return true;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return false;
|
|
222
|
+
};
|
|
223
|
+
return CoralogixErrorInstrumentation;
|
|
224
|
+
}(InstrumentationBase));
|
|
225
|
+
export { CoralogixErrorInstrumentation };
|
|
226
|
+
//# sourceMappingURL=CoralogixErrorInstrumentation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CoralogixErrorInstrumentation.js","sourceRoot":"","sources":["../../../../../libs/browser/src/instrumentations/CoralogixErrorInstrumentation.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAE/D,OAAO,EACL,mBAAmB,GAEpB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;A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iB,CAAC;gBACvC,WAAW,GAAG,MAAI,GAAG,GAAG,GAAG,OAAO,CAAC;gBACnC,MAAM;aACP;YACD,KAAK,GAAG,YAAY,UAAU,CAAC,CAAC;gBACtB,IAAA,OAAO,GAAK,GAAiB,QAAtB,CAAuB;gBACtC,WAAW,GAAG,OAAO,CAAC;gBACtB,MAAM;aACP;YACD,KAAK,GAAG,YAAY,KAAK,CAAC,CAAC;gBACjB,IAAA,IAAI,GAAK,GAAY,KAAjB,CAAkB;gBAC9B,WAAW,GAAG,IAAI,CAAC;gBACnB,MAAM;aACP;YACD,KAAK,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC;gBAC5B,WAAW,GAAG,GAAa,CAAC;gBAC5B,MAAM;aACP;YACD,KAAK,GAAG,YAAY,KAAK,CAAC,CAAC;gBACzB,WAAW,GAAI,GAAkB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;gBAC5C,MAAM;aACP;YACD;gBACE,WAAW,GAAG,IAAI,CAAC,uBAAuB,CAAC,GAAG,CAAC,CAAC;SACnD;QAED,IAAI,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,KAAK,EAAE;YACtB,KAA0B,UAAiB,EAAjB,KAAA,IAAI,CAAC,YAAY,EAAjB,cAAiB,EAAjB,IAAiB,EAAE;gBAAxC,IAAM,WAAW,SAAA;gBACpB,IAAI,WAAW,CAAC,KAAK,CAAC,WAAW,CAAC,EAAE;oBAClC,OAAO,IAAI,CAAC;iBACb;aACF;SACF;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IACH,oCAAC;AAAD,CAAC,AAzND,CAAmD,mBAAmB,GAyNrE"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { FetchInstrumentation, FetchInstrumentationConfig } from '@opentelemetry/instrumentation-fetch';
|
|
2
|
+
export declare enum FetchSource {
|
|
3
|
+
FETCH = "fetch"
|
|
4
|
+
}
|
|
5
|
+
export declare class CoralogixFetchInstrumentation extends FetchInstrumentation {
|
|
6
|
+
constructor(config: FetchInstrumentationConfig);
|
|
7
|
+
enable(): void;
|
|
8
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { __extends } from "tslib";
|
|
2
|
+
import { FetchInstrumentation, } from '@opentelemetry/instrumentation-fetch';
|
|
3
|
+
import { CoralogixAttributes } from '../constants';
|
|
4
|
+
import { CoralogixEventType } from '../types';
|
|
5
|
+
import { CoralogixLogSeverity } from '../types-external';
|
|
6
|
+
import { propagateTraceHeaderCorsUrls } from '../CoralogixPropgator';
|
|
7
|
+
import { isNetworkError } from '../utils';
|
|
8
|
+
export var FetchSource;
|
|
9
|
+
(function (FetchSource) {
|
|
10
|
+
FetchSource["FETCH"] = "fetch";
|
|
11
|
+
})(FetchSource || (FetchSource = {}));
|
|
12
|
+
var CoralogixFetchInstrumentation = /** @class */ (function (_super) {
|
|
13
|
+
__extends(CoralogixFetchInstrumentation, _super);
|
|
14
|
+
function CoralogixFetchInstrumentation(config) {
|
|
15
|
+
propagateTraceHeaderCorsUrls(config);
|
|
16
|
+
config.applyCustomAttributesOnSpan = function (span, request, result) {
|
|
17
|
+
var _a;
|
|
18
|
+
var status = result.status;
|
|
19
|
+
span.setAttributes((_a = {},
|
|
20
|
+
_a[CoralogixAttributes.SEVERITY] = isNetworkError(status)
|
|
21
|
+
? CoralogixLogSeverity.Error
|
|
22
|
+
: CoralogixLogSeverity.Info,
|
|
23
|
+
_a[CoralogixAttributes.EVENT_TYPE] = CoralogixEventType.NETWORK_REQUEST,
|
|
24
|
+
_a[CoralogixAttributes.SOURCE] = FetchSource.FETCH,
|
|
25
|
+
_a[CoralogixAttributes.TIMESTAMP] = Date.now(),
|
|
26
|
+
_a));
|
|
27
|
+
};
|
|
28
|
+
return _super.call(this, config) || this;
|
|
29
|
+
}
|
|
30
|
+
CoralogixFetchInstrumentation.prototype.enable = function () {
|
|
31
|
+
_super.prototype.enable.call(this);
|
|
32
|
+
};
|
|
33
|
+
return CoralogixFetchInstrumentation;
|
|
34
|
+
}(FetchInstrumentation));
|
|
35
|
+
export { CoralogixFetchInstrumentation };
|
|
36
|
+
//# sourceMappingURL=CoralogixFetchInstrumentation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CoralogixFetchInstrumentation.js","sourceRoot":"","sources":["../../../../../libs/browser/src/instrumentations/CoralogixFetchInstrumentation.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,oBAAoB,GAErB,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE1C,MAAM,CAAN,IAAY,WAEX;AAFD,WAAY,WAAW;IACrB,8BAAe,CAAA;AACjB,CAAC,EAFW,WAAW,KAAX,WAAW,QAEtB;AAED;IAAmD,iDAAoB;IACrE,uCAAY,MAAkC;QAC5C,4BAA4B,CAAC,MAAM,CAAC,CAAC;QAErC,MAAM,CAAC,2BAA2B,GAAG,UAAC,IAAI,EAAE,OAAO,EAAE,MAAM;;YACjD,IAAA,MAAM,GAAK,MAAM,OAAX,CAAY;YAE1B,IAAI,CAAC,aAAa;gBAChB,GAAC,mBAAmB,CAAC,QAAQ,IAAG,cAAc,CAAC,MAAM,CAAC;oBACpD,CAAC,CAAC,oBAAoB,CAAC,KAAK;oBAC5B,CAAC,CAAC,oBAAoB,CAAC,IAAI;gBAC7B,GAAC,mBAAmB,CAAC,UAAU,IAAG,kBAAkB,CAAC,eAAe;gBACpE,GAAC,mBAAmB,CAAC,MAAM,IAAG,WAAW,CAAC,KAAK;gBAC/C,GAAC,mBAAmB,CAAC,SAAS,IAAG,IAAI,CAAC,GAAG,EAAE;oBAC3C,CAAC;QACL,CAAC,CAAC;eAEF,kBAAM,MAAM,CAAC;IACf,CAAC;IAEQ,8CAAM,GAAf;QACE,iBAAM,MAAM,WAAE,CAAC;IACjB,CAAC;IACH,oCAAC;AAAD,CAAC,AAvBD,CAAmD,oBAAoB,GAuBtE"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { InstrumentationBase, InstrumentationModuleDefinition } from '@opentelemetry/instrumentation';
|
|
2
|
+
export declare class CoralogixLongTaskInstrumentation extends InstrumentationBase {
|
|
3
|
+
private longTaskObserver;
|
|
4
|
+
private longTasksListAfterPageLoaded;
|
|
5
|
+
constructor();
|
|
6
|
+
private registerToLongTasksAfterPageLoaded;
|
|
7
|
+
private registerToLongTasks;
|
|
8
|
+
private createSpanFromLongTask;
|
|
9
|
+
enable(): void;
|
|
10
|
+
disable(): void;
|
|
11
|
+
protected init(): InstrumentationModuleDefinition<any> | InstrumentationModuleDefinition<any>[] | void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { __assign, __extends } from "tslib";
|
|
2
|
+
import { InstrumentationBase, } from '@opentelemetry/instrumentation';
|
|
3
|
+
import { LONG_TASK_INSTRUMENTATION_VERSION, LONG_TASK_PERFORMANCE_TYPE, } from './instrumentation.consts';
|
|
4
|
+
import { CoralogixEventType, PerformanceTypes, } from '../types';
|
|
5
|
+
import { CoralogixAttributes } from '../constants';
|
|
6
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
7
|
+
import { supportedPerformanceTypes } from '../utils';
|
|
8
|
+
var CoralogixLongTaskInstrumentation = /** @class */ (function (_super) {
|
|
9
|
+
__extends(CoralogixLongTaskInstrumentation, _super);
|
|
10
|
+
function CoralogixLongTaskInstrumentation() {
|
|
11
|
+
var _this = _super.call(this, LONG_TASK_PERFORMANCE_TYPE, LONG_TASK_INSTRUMENTATION_VERSION) || this;
|
|
12
|
+
_this.longTasksListAfterPageLoaded = [];
|
|
13
|
+
if (supportedPerformanceTypes[PerformanceTypes.LongTask]) {
|
|
14
|
+
_this.registerToLongTasks();
|
|
15
|
+
_this.registerToLongTasksAfterPageLoaded();
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
console.warn('RUM SDK - browser doesnt support longtask events');
|
|
19
|
+
}
|
|
20
|
+
return _this;
|
|
21
|
+
}
|
|
22
|
+
CoralogixLongTaskInstrumentation.prototype.registerToLongTasksAfterPageLoaded = function () {
|
|
23
|
+
var _this = this;
|
|
24
|
+
window.addEventListener('load', function () {
|
|
25
|
+
_this.longTasksListAfterPageLoaded.forEach(function (entry) {
|
|
26
|
+
return _this.createSpanFromLongTask(entry, true);
|
|
27
|
+
});
|
|
28
|
+
}, { once: true });
|
|
29
|
+
};
|
|
30
|
+
CoralogixLongTaskInstrumentation.prototype.registerToLongTasks = function () {
|
|
31
|
+
var _this = this;
|
|
32
|
+
this.longTaskObserver = new PerformanceObserver(function (list) {
|
|
33
|
+
_this.longTasksListAfterPageLoaded =
|
|
34
|
+
_this.longTasksListAfterPageLoaded.concat(list.getEntries());
|
|
35
|
+
list
|
|
36
|
+
.getEntries()
|
|
37
|
+
.forEach(function (entry) {
|
|
38
|
+
return _this.createSpanFromLongTask(entry);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
this.longTaskObserver.observe({
|
|
42
|
+
type: PerformanceTypes.LongTask,
|
|
43
|
+
buffered: true,
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
CoralogixLongTaskInstrumentation.prototype.createSpanFromLongTask = function (entry, afterPageLoaded) {
|
|
47
|
+
var longTaskSpan = this.tracer.startSpan(CoralogixEventType.LONG_TASK);
|
|
48
|
+
var longTaskContext = __assign(__assign({}, JSON.parse(JSON.stringify(entry))), { id: uuidv4(), type: afterPageLoaded ? 'after_page_loaded' : 'regular' });
|
|
49
|
+
if (entry['toJSON']) {
|
|
50
|
+
delete longTaskContext['toJSON'];
|
|
51
|
+
}
|
|
52
|
+
if (entry['attribution']) {
|
|
53
|
+
delete longTaskContext['attribution'];
|
|
54
|
+
}
|
|
55
|
+
longTaskSpan.setAttribute(CoralogixAttributes.TIMESTAMP, Date.now());
|
|
56
|
+
longTaskSpan.setAttribute(CoralogixAttributes.EVENT_TYPE, CoralogixEventType.LONG_TASK);
|
|
57
|
+
longTaskSpan.setAttribute(LONG_TASK_PERFORMANCE_TYPE, JSON.stringify(longTaskContext));
|
|
58
|
+
longTaskSpan.end();
|
|
59
|
+
};
|
|
60
|
+
CoralogixLongTaskInstrumentation.prototype.enable = function () { };
|
|
61
|
+
CoralogixLongTaskInstrumentation.prototype.disable = function () {
|
|
62
|
+
var _a;
|
|
63
|
+
(_a = this.longTaskObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
|
|
64
|
+
};
|
|
65
|
+
CoralogixLongTaskInstrumentation.prototype.init = function () {
|
|
66
|
+
return undefined;
|
|
67
|
+
};
|
|
68
|
+
return CoralogixLongTaskInstrumentation;
|
|
69
|
+
}(InstrumentationBase));
|
|
70
|
+
export { CoralogixLongTaskInstrumentation };
|
|
71
|
+
//# sourceMappingURL=CoralogixLongTaskInstrumentation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CoralogixLongTaskInstrumentation.js","sourceRoot":"","sources":["../../../../../libs/browser/src/instrumentations/CoralogixLongTaskInstrumentation.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,mBAAmB,GAEpB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,iCAAiC,EACjC,0BAA0B,GAC3B,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACL,kBAAkB,EAElB,gBAAgB,GACjB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAErD;IAAsD,oDAAmB;IAIvE;QAAA,YACE,kBAAM,0BAA0B,EAAE,i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EF,IAAM,eAAe,yBAChB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,KACpC,EAAE,EAAE,MAAM,EAAE,EACZ,IAAI,EAAE,eAAe,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,SAAS,GACxD,CAAC;QAEF,IAAI,KAAK,CAAC,QAAQ,CAAC,EAAE;YACnB,OAAO,eAAe,CAAC,QAAQ,CAAC,CAAC;SAClC;QAED,IAAI,KAAK,CAAC,aAAa,CAAC,EAAE;YACxB,OAAO,eAAe,CAAC,aAAa,CAAC,CAAC;SACvC;QAED,YAAY,CAAC,YAAY,CAAC,mBAAmB,CAAC,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;QAErE,YAAY,CAAC,YAAY,CACvB,mBAAmB,CAAC,UAAU,EAC9B,kBAAkB,CAAC,SAAS,CAC7B,CAAC;QAEF,YAAY,CAAC,YAAY,CACvB,0BAA0B,EAC1B,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,CAChC,CAAC;QAEF,YAAY,CAAC,GAAG,EAAE,CAAC;IACrB,CAAC;IAEQ,iDAAM,GAAf,cAAmB,CAAC;IAEX,kDAAO,GAAhB;;QACE,MAAA,IAAI,CAAC,gBAAgB,0CAAE,UAAU,EAAE,CAAC;IACtC,CAAC;IAES,+CAAI,GAAd;QAIE,OAAO,SAAS,CAAC;IACnB,CAAC;IACH,uCAAC;AAAD,CAAC,AAhGD,CAAsD,mBAAmB,GAgGxE"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { InstrumentationBase, InstrumentationModuleDefinition } from '@opentelemetry/instrumentation';
|
|
2
|
+
export declare class CoralogixResourcesInstrumentation extends InstrumentationBase {
|
|
3
|
+
private resourcesObserver;
|
|
4
|
+
private ignoreUrls;
|
|
5
|
+
constructor();
|
|
6
|
+
private registerToResources;
|
|
7
|
+
private isResourceIgnored;
|
|
8
|
+
private mapResource;
|
|
9
|
+
private createSpanFromResource;
|
|
10
|
+
enable(): void;
|
|
11
|
+
disable(): void;
|
|
12
|
+
protected init(): InstrumentationModuleDefinition<any> | InstrumentationModuleDefinition<any>[] | void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { __assign, __extends } from "tslib";
|
|
2
|
+
import { InstrumentationBase, } from '@opentelemetry/instrumentation';
|
|
3
|
+
import { CSS_EXTENSIONS, DOC_EXTENSIONS, FONT_EXTENSIONS, FONTS_URL, IMG_EXTENSIONS, MEDIA_EXTENSIONS, OTHER_EXTENSIONS, RESOURCES_INSTRUMENTATION_NAME, RESOURCES_INSTRUMENTATION_VERSION, SCRIPT_EXTENSIONS, } from './instrumentation.consts';
|
|
4
|
+
import { CoralogixEventType, PerformanceTypes } from '../types';
|
|
5
|
+
import { CORALOGIX_LOGS_URL_SUFFIX, CoralogixAttributes, MAX_INTERACTION_ELEMENT_SIZE, } from '../constants';
|
|
6
|
+
import { supportedPerformanceTypes, valueEndWithOrInclude } from '../utils';
|
|
7
|
+
import { resourceInitiatorTypeIs } from './instrumentation.helper';
|
|
8
|
+
import { ResourceInitiatorTypes } from './instrumentation.model';
|
|
9
|
+
import { getSdkConfig } from '../helpers';
|
|
10
|
+
var CoralogixResourcesInstrumentation = /** @class */ (function (_super) {
|
|
11
|
+
__extends(CoralogixResourcesInstrumentation, _super);
|
|
12
|
+
function CoralogixResourcesInstrumentation() {
|
|
13
|
+
var _a;
|
|
14
|
+
var _this = _super.call(this, RESOURCES_INSTRUMENTATION_NAME, RESOURCES_INSTRUMENTATION_VERSION) || this;
|
|
15
|
+
_this.ignoreUrls = (_a = getSdkConfig()) === null || _a === void 0 ? void 0 : _a.ignoreUrls;
|
|
16
|
+
if (supportedPerformanceTypes[PerformanceTypes.Resource]) {
|
|
17
|
+
_this.registerToResources();
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
console.warn('RUM SDK - browser doesnt support resource events');
|
|
21
|
+
}
|
|
22
|
+
return _this;
|
|
23
|
+
}
|
|
24
|
+
CoralogixResourcesInstrumentation.prototype.registerToResources = function () {
|
|
25
|
+
var _this = this;
|
|
26
|
+
this.resourcesObserver = new PerformanceObserver(function (list) {
|
|
27
|
+
list
|
|
28
|
+
.getEntries()
|
|
29
|
+
.reduce(function (mappedEntries, entry) {
|
|
30
|
+
var isNotFetchResourceType = entry.initiatorType !==
|
|
31
|
+
ResourceInitiatorTypes.Fetch;
|
|
32
|
+
var isResourceNotContainsCoralogixLogsSuffix = !entry.name.includes(CORALOGIX_LOGS_URL_SUFFIX);
|
|
33
|
+
var isResourceNotIgnored = !_this.isResourceIgnored(entry.name);
|
|
34
|
+
if ((isNotFetchResourceType ||
|
|
35
|
+
isResourceNotContainsCoralogixLogsSuffix) &&
|
|
36
|
+
isResourceNotIgnored) {
|
|
37
|
+
mappedEntries.push(_this.mapResource(entry));
|
|
38
|
+
}
|
|
39
|
+
return mappedEntries;
|
|
40
|
+
}, [])
|
|
41
|
+
.forEach(function (entry) {
|
|
42
|
+
_this.createSpanFromResource(entry);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
this.resourcesObserver.observe({
|
|
46
|
+
type: PerformanceTypes.Resource,
|
|
47
|
+
buffered: true,
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
CoralogixResourcesInstrumentation.prototype.isResourceIgnored = function (resourceName) {
|
|
51
|
+
var _a;
|
|
52
|
+
if (!resourceName || !((_a = this.ignoreUrls) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
return this.ignoreUrls.some(function (url) {
|
|
56
|
+
if (url instanceof RegExp) {
|
|
57
|
+
return url.test(resourceName);
|
|
58
|
+
}
|
|
59
|
+
else if (typeof url === 'string') {
|
|
60
|
+
resourceName = resourceName.toLowerCase();
|
|
61
|
+
url = url.toLowerCase();
|
|
62
|
+
return url.includes(resourceName);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
console.warn('Coralogix Browser SDK - ignoreUrls must be from type string | Regex');
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
CoralogixResourcesInstrumentation.prototype.mapResource = function (resource) {
|
|
71
|
+
var resourceName = resource.name;
|
|
72
|
+
var initiatorType = resource.initiatorType;
|
|
73
|
+
switch (true) {
|
|
74
|
+
case resourceInitiatorTypeIs(initiatorType, [
|
|
75
|
+
ResourceInitiatorTypes.Beacon,
|
|
76
|
+
]) || valueEndWithOrInclude(resourceName, OTHER_EXTENSIONS):
|
|
77
|
+
initiatorType = ResourceInitiatorTypes.Other;
|
|
78
|
+
break;
|
|
79
|
+
case initiatorType !== ResourceInitiatorTypes.Css &&
|
|
80
|
+
valueEndWithOrInclude(resourceName, CSS_EXTENSIONS):
|
|
81
|
+
initiatorType = ResourceInitiatorTypes.Css;
|
|
82
|
+
break;
|
|
83
|
+
case initiatorType !== ResourceInitiatorTypes.Script &&
|
|
84
|
+
valueEndWithOrInclude(resourceName, SCRIPT_EXTENSIONS):
|
|
85
|
+
initiatorType = ResourceInitiatorTypes.Script;
|
|
86
|
+
break;
|
|
87
|
+
case initiatorType !== ResourceInitiatorTypes.Img &&
|
|
88
|
+
valueEndWithOrInclude(resourceName, IMG_EXTENSIONS):
|
|
89
|
+
initiatorType = ResourceInitiatorTypes.Img;
|
|
90
|
+
break;
|
|
91
|
+
case resourceName.includes(FONTS_URL) ||
|
|
92
|
+
valueEndWithOrInclude(resourceName, FONT_EXTENSIONS):
|
|
93
|
+
initiatorType = ResourceInitiatorTypes.Font;
|
|
94
|
+
break;
|
|
95
|
+
case initiatorType !== ResourceInitiatorTypes.Iframe &&
|
|
96
|
+
valueEndWithOrInclude(resourceName, DOC_EXTENSIONS):
|
|
97
|
+
initiatorType = ResourceInitiatorTypes.Doc;
|
|
98
|
+
break;
|
|
99
|
+
case resourceInitiatorTypeIs(initiatorType, [
|
|
100
|
+
ResourceInitiatorTypes.Video,
|
|
101
|
+
ResourceInitiatorTypes.Audio,
|
|
102
|
+
ResourceInitiatorTypes.Track,
|
|
103
|
+
]) || valueEndWithOrInclude(resourceName, MEDIA_EXTENSIONS):
|
|
104
|
+
initiatorType = ResourceInitiatorTypes.Media;
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
return __assign(__assign({}, JSON.parse(JSON.stringify(resource))), { initiatorType: initiatorType });
|
|
108
|
+
};
|
|
109
|
+
CoralogixResourcesInstrumentation.prototype.createSpanFromResource = function (entry) {
|
|
110
|
+
var _a;
|
|
111
|
+
var resourceSpan = this.tracer.startSpan(RESOURCES_INSTRUMENTATION_NAME);
|
|
112
|
+
resourceSpan.setAttribute(CoralogixAttributes.TIMESTAMP, Date.now());
|
|
113
|
+
resourceSpan.setAttribute(CoralogixAttributes.EVENT_TYPE, CoralogixEventType.RESOURCES);
|
|
114
|
+
var newEntry = __assign(__assign({}, JSON.parse(JSON.stringify(entry))), { name: (_a = entry.name) === null || _a === void 0 ? void 0 : _a.slice(0, MAX_INTERACTION_ELEMENT_SIZE) });
|
|
115
|
+
resourceSpan.setAttribute(RESOURCES_INSTRUMENTATION_NAME, JSON.stringify(newEntry));
|
|
116
|
+
resourceSpan.end();
|
|
117
|
+
};
|
|
118
|
+
CoralogixResourcesInstrumentation.prototype.enable = function () { };
|
|
119
|
+
CoralogixResourcesInstrumentation.prototype.disable = function () {
|
|
120
|
+
var _a;
|
|
121
|
+
(_a = this.resourcesObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
|
|
122
|
+
};
|
|
123
|
+
CoralogixResourcesInstrumentation.prototype.init = function () {
|
|
124
|
+
return undefined;
|
|
125
|
+
};
|
|
126
|
+
return CoralogixResourcesInstrumentation;
|
|
127
|
+
}(InstrumentationBase));
|
|
128
|
+
export { CoralogixResourcesInstrumentation };
|
|
129
|
+
//# sourceMappingURL=CoralogixResourcesInstrumentation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CoralogixResourcesInstrumentation.js","sourceRoot":"","sources":["../../../../../libs/browser/src/instrumentations/CoralogixResourcesInstrumentation.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,mBAAmB,GAEpB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,cAAc,EACd,cAAc,EACd,eAAe,EACf,SAAS,EACT,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,8BAA8B,EAC9B,iCAAiC,EACjC,iBAAiB,GAClB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAEhE,OAAO,EACL,yBAAyB,EACzB,mBAAmB,EACnB,4BAA4B,GAC7B,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,yBAAyB,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAC5E,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1C;IAAuD,qDAAmB;IAKxE;;QAAA,YACE,kBAAM,8BAA8B,EAAE,iCAAiC,CAAC,SAOzE;QAXO,gBAAU,GAChB,MAAA,YAAY,EAAE,0CAAE,UAAU,CAAC;QAK3B,IAAI,yBAAyB,CAAC,gBAAgB,CAAC,QAAQ,CAAC,EAAE;YACxD,KAAI,CAAC,mBAAmB,EAAE,CAAC;SAC5B;aAAM;YACL,OAAO,CAAC,IAAI,CAAC,kDAAkD,CAAC,CAAC;SAClE;;IACH,CAAC;IAEO,+DAAmB,GAA3B;QAAA,iBA0CC;QAzCC,IAAI,CAAC,iBAAiB,GAAG,IAAI,mBAAmB,CAC9C,UAAC,IAAkC;YACjC,IAAI;iBACD,UAAU,EAAE;iBACZ,MAAM,CACL,UAAC,aAAiC,EAAE,KAAuB;gBACzD,IAAM,sBAAsB,GACzB,KAAmC,CAAC,aAAa;oBAClD,sB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@
|
|
|
1
|
+
import { InstrumentationBase, InstrumentationConfig } from '@opentelemetry/instrumentation';
|
|
2
|
+
import { EventName } from '../types';
|
|
3
|
+
export declare const USER_INTERACTION_INSTRUMENTATION_NAME = "user-interaction";
|
|
4
|
+
export declare const USER_INTERACTION_INSTRUMENTATION_VERSION = "1";
|
|
5
|
+
export type UserInteractionEventsConfig = Partial<Record<EventName, boolean>>;
|
|
6
|
+
export interface CoralogixUserInteractionInstrumentationConfig extends InstrumentationConfig {
|
|
7
|
+
events?: UserInteractionEventsConfig;
|
|
8
|
+
}
|
|
9
|
+
export declare const DEFAULT_INSTRUMENTED_EVENTS: UserInteractionEventsConfig;
|
|
10
|
+
export declare class CoralogixUserInteractionInstrumentation extends InstrumentationBase {
|
|
11
|
+
private handler;
|
|
12
|
+
private stop;
|
|
13
|
+
constructor(config: CoralogixUserInteractionInstrumentationConfig);
|
|
14
|
+
enable(): void;
|
|
15
|
+
disable(): void;
|
|
16
|
+
protected init(): undefined;
|
|
17
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
var _a;
|
|
2
|
+
import { __assign, __extends } from "tslib";
|
|
3
|
+
import { InstrumentationBase, } from '@opentelemetry/instrumentation';
|
|
4
|
+
import { CoralogixAttributes, MAX_INTERACTION_ELEMENT_SIZE, } from '../constants';
|
|
5
|
+
import { CoralogixEventType } from '../types';
|
|
6
|
+
import { addEventListeners } from '../tools/addEventListener';
|
|
7
|
+
export var USER_INTERACTION_INSTRUMENTATION_NAME = 'user-interaction';
|
|
8
|
+
export var USER_INTERACTION_INSTRUMENTATION_VERSION = '1';
|
|
9
|
+
export var DEFAULT_INSTRUMENTED_EVENTS = (_a = {},
|
|
10
|
+
_a["click" /* DOM_EVENT.CLICK */] = true,
|
|
11
|
+
_a);
|
|
12
|
+
var CoralogixUserInteractionInstrumentation = /** @class */ (function (_super) {
|
|
13
|
+
__extends(CoralogixUserInteractionInstrumentation, _super);
|
|
14
|
+
function CoralogixUserInteractionInstrumentation(config) {
|
|
15
|
+
var _this = _super.call(this, USER_INTERACTION_INSTRUMENTATION_NAME, USER_INTERACTION_INSTRUMENTATION_VERSION, config) || this;
|
|
16
|
+
_this.handler = function (_) { };
|
|
17
|
+
_this.stop = function () { };
|
|
18
|
+
return _this;
|
|
19
|
+
}
|
|
20
|
+
CoralogixUserInteractionInstrumentation.prototype.enable = function () {
|
|
21
|
+
var _this = this;
|
|
22
|
+
var _a;
|
|
23
|
+
this.handler = function (e) {
|
|
24
|
+
var eventTarget = e.target;
|
|
25
|
+
var span = _this.tracer.startSpan(USER_INTERACTION_INSTRUMENTATION_NAME);
|
|
26
|
+
var innerText = eventTarget.innerText, innerHTML = eventTarget.innerHTML, id = eventTarget.id, type = eventTarget.type, value = eventTarget.value, className = eventTarget.className, nodeName = eventTarget.nodeName;
|
|
27
|
+
span.setAttribute(CoralogixAttributes.TIMESTAMP, Date.now());
|
|
28
|
+
span.setAttribute(CoralogixAttributes.EVENT_TYPE, CoralogixEventType.USER_INTERACTION);
|
|
29
|
+
span.setAttribute(CoralogixAttributes.INTERACTION_EVENT_NAME, e.type);
|
|
30
|
+
if (eventTarget && eventTarget instanceof HTMLElement) {
|
|
31
|
+
var elementInnerText = function () {
|
|
32
|
+
var val = innerText || value || '';
|
|
33
|
+
return typeof val === 'string' ? val : '';
|
|
34
|
+
};
|
|
35
|
+
[
|
|
36
|
+
[
|
|
37
|
+
CoralogixAttributes.ELEMENT_INNER_HTML,
|
|
38
|
+
(innerHTML === null || innerHTML === void 0 ? void 0 : innerHTML.length) < MAX_INTERACTION_ELEMENT_SIZE ? innerHTML : '',
|
|
39
|
+
],
|
|
40
|
+
[CoralogixAttributes.ELEMENT_ID, id],
|
|
41
|
+
[CoralogixAttributes.ELEMENT_CLASSES, className],
|
|
42
|
+
[CoralogixAttributes.TARGET_ELEMENT_TYPE, type],
|
|
43
|
+
[
|
|
44
|
+
CoralogixAttributes.ELEMENT_INNER_TEXT,
|
|
45
|
+
elementInnerText().slice(0, MAX_INTERACTION_ELEMENT_SIZE),
|
|
46
|
+
],
|
|
47
|
+
[CoralogixAttributes.TARGET_ELEMENT, nodeName],
|
|
48
|
+
].forEach(function (_a) {
|
|
49
|
+
var key = _a[0], value = _a[1];
|
|
50
|
+
span.setAttribute(key, value);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
span.end();
|
|
54
|
+
};
|
|
55
|
+
var eventsMap = __assign(__assign({}, DEFAULT_INSTRUMENTED_EVENTS), (_a = this._config) === null || _a === void 0 ? void 0 : _a['events']);
|
|
56
|
+
var eventNames = Object.entries(eventsMap)
|
|
57
|
+
.filter(function (_a) {
|
|
58
|
+
var _ = _a[0], enabled = _a[1];
|
|
59
|
+
return enabled;
|
|
60
|
+
})
|
|
61
|
+
.map(function (_a) {
|
|
62
|
+
var eventName = _a[0];
|
|
63
|
+
return eventName;
|
|
64
|
+
});
|
|
65
|
+
this.stop = addEventListeners(document, eventNames, this.handler, {
|
|
66
|
+
capture: true,
|
|
67
|
+
passive: true,
|
|
68
|
+
}).stop;
|
|
69
|
+
};
|
|
70
|
+
CoralogixUserInteractionInstrumentation.prototype.disable = function () {
|
|
71
|
+
this.stop();
|
|
72
|
+
};
|
|
73
|
+
CoralogixUserInteractionInstrumentation.prototype.init = function () {
|
|
74
|
+
return undefined;
|
|
75
|
+
};
|
|
76
|
+
return CoralogixUserInteractionInstrumentation;
|
|
77
|
+
}(InstrumentationBase));
|
|
78
|
+
export { CoralogixUserInteractionInstrumentation };
|
|
79
|
+
//# sourceMappingURL=CoralogixUserInteractionInstrumentation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CoralogixUserInteractionInstrumentation.js","sourceRoot":"","sources":["../../../../../libs/browser/src/instrumentations/CoralogixUserInteractionInstrumentation.ts"],"names":[],"mappings":";;AAAA,OAAO,EACL,mBAAmB,GAEpB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,mBAAmB,EACnB,4BAA4B,GAC7B,MAAM,cAAc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