@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.
Files changed (80) hide show
  1. package/README.md +104 -0
  2. package/package.json +32 -0
  3. package/src/CoralogixExporter.d.ts +15 -0
  4. package/src/CoralogixExporter.js +217 -0
  5. package/src/CoralogixExporter.js.map +1 -0
  6. package/src/CoralogixPropgator.d.ts +3 -0
  7. package/src/CoralogixPropgator.js +9 -0
  8. package/src/CoralogixPropgator.js.map +1 -0
  9. package/src/CoralogixSpanAttributesProcessor.d.ts +18 -0
  10. package/src/CoralogixSpanAttributesProcessor.js +64 -0
  11. package/src/CoralogixSpanAttributesProcessor.js.map +1 -0
  12. package/src/CoralogixWebTracerProvider.d.ts +3 -0
  13. package/src/CoralogixWebTracerProvider.js +11 -0
  14. package/src/CoralogixWebTracerProvider.js.map +1 -0
  15. package/src/constants.d.ts +93 -0
  16. package/src/constants.js +111 -0
  17. package/src/constants.js.map +1 -0
  18. package/src/helpers.d.ts +2 -0
  19. package/src/helpers.js +5 -0
  20. package/src/helpers.js.map +1 -0
  21. package/src/index.d.ts +2 -0
  22. package/src/index.js +203 -0
  23. package/src/index.js.map +1 -0
  24. package/src/instrumentations/CoralogixCustomLogInstrumentation.d.ts +14 -0
  25. package/src/instrumentations/CoralogixCustomLogInstrumentation.js +41 -0
  26. package/src/instrumentations/CoralogixCustomLogInstrumentation.js.map +1 -0
  27. package/src/instrumentations/CoralogixErrorInstrumentation.d.ts +32 -0
  28. package/src/instrumentations/CoralogixErrorInstrumentation.js +226 -0
  29. package/src/instrumentations/CoralogixErrorInstrumentation.js.map +1 -0
  30. package/src/instrumentations/CoralogixFetchInstrumentation.d.ts +8 -0
  31. package/src/instrumentations/CoralogixFetchInstrumentation.js +36 -0
  32. package/src/instrumentations/CoralogixFetchInstrumentation.js.map +1 -0
  33. package/src/instrumentations/CoralogixLongTaskInstrumentation.d.ts +12 -0
  34. package/src/instrumentations/CoralogixLongTaskInstrumentation.js +71 -0
  35. package/src/instrumentations/CoralogixLongTaskInstrumentation.js.map +1 -0
  36. package/src/instrumentations/CoralogixResourcesInstrumentation.d.ts +13 -0
  37. package/src/instrumentations/CoralogixResourcesInstrumentation.js +129 -0
  38. package/src/instrumentations/CoralogixResourcesInstrumentation.js.map +1 -0
  39. package/src/instrumentations/CoralogixUserInteractionInstrumentation.d.ts +17 -0
  40. package/src/instrumentations/CoralogixUserInteractionInstrumentation.js +79 -0
  41. package/src/instrumentations/CoralogixUserInteractionInstrumentation.js.map +1 -0
  42. package/src/instrumentations/CoralogixWebVitalsInstrumentation.d.ts +18 -0
  43. package/src/instrumentations/CoralogixWebVitalsInstrumentation.js +160 -0
  44. package/src/instrumentations/CoralogixWebVitalsInstrumentation.js.map +1 -0
  45. package/src/instrumentations/CoralogixXhrInstrumentation.d.ts +7 -0
  46. package/src/instrumentations/CoralogixXhrInstrumentation.js +33 -0
  47. package/src/instrumentations/CoralogixXhrInstrumentation.js.map +1 -0
  48. package/src/instrumentations/instrumentation.consts.d.ts +18 -0
  49. package/src/instrumentations/instrumentation.consts.js +57 -0
  50. package/src/instrumentations/instrumentation.consts.js.map +1 -0
  51. package/src/instrumentations/instrumentation.helper.d.ts +1 -0
  52. package/src/instrumentations/instrumentation.helper.js +4 -0
  53. package/src/instrumentations/instrumentation.helper.js.map +1 -0
  54. package/src/instrumentations/instrumentation.model.d.ts +30 -0
  55. package/src/instrumentations/instrumentation.model.js +18 -0
  56. package/src/instrumentations/instrumentation.model.js.map +1 -0
  57. package/src/sessionManager.d.ts +12 -0
  58. package/src/sessionManager.js +69 -0
  59. package/src/sessionManager.js.map +1 -0
  60. package/src/tools/addEventListener.d.ts +54 -0
  61. package/src/tools/addEventListener.js +35 -0
  62. package/src/tools/addEventListener.js.map +1 -0
  63. package/src/tools/getGlobalObject.d.ts +5 -0
  64. package/src/tools/getGlobalObject.js +36 -0
  65. package/src/tools/getGlobalObject.js.map +1 -0
  66. package/src/tools/getZoneJsOriginalDom.d.ts +9 -0
  67. package/src/tools/getZoneJsOriginalDom.js +17 -0
  68. package/src/tools/getZoneJsOriginalDom.js.map +1 -0
  69. package/src/types-external.d.ts +8 -0
  70. package/src/types-external.js +10 -0
  71. package/src/types-external.js.map +1 -0
  72. package/src/types.d.ts +270 -0
  73. package/src/types.js +27 -0
  74. package/src/types.js.map +1 -0
  75. package/src/utils.d.ts +24 -0
  76. package/src/utils.js +156 -0
  77. package/src/utils.js.map +1 -0
  78. package/src/version.d.ts +1 -0
  79. package/src/version.js +2 -0
  80. package/src/version.js.map +1 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getZoneJsOriginalDom.js","sourceRoot":"","sources":["../../../../../libs/browser/src/tools/getZoneJsOriginalDom.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAQpD;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAGlC,MAAc,EAAE,IAAU;IAC1B,IAAM,aAAa,GAAG,eAAe,EAA2B,CAAC;IACjE,IAAI,QAAkC,CAAC;IACvC,IACE,aAAa,CAAC,IAAI;QAClB,OAAO,aAAa,CAAC,IAAI,CAAC,UAAU,KAAK,UAAU,EACnD;QACA,QAAQ,GAAI,MAAc,CAAC,aAAa,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC;KACjE;IACD,IAAI,CAAC,QAAQ,EAAE;QACb,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;KACzB;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
@@ -0,0 +1,8 @@
1
+ export declare enum CoralogixLogSeverity {
2
+ Debug = 1,
3
+ Verbose = 2,
4
+ Info = 3,
5
+ Warn = 4,
6
+ Error = 5,
7
+ Critical = 6
8
+ }
@@ -0,0 +1,10 @@
1
+ export var CoralogixLogSeverity;
2
+ (function (CoralogixLogSeverity) {
3
+ CoralogixLogSeverity[CoralogixLogSeverity["Debug"] = 1] = "Debug";
4
+ CoralogixLogSeverity[CoralogixLogSeverity["Verbose"] = 2] = "Verbose";
5
+ CoralogixLogSeverity[CoralogixLogSeverity["Info"] = 3] = "Info";
6
+ CoralogixLogSeverity[CoralogixLogSeverity["Warn"] = 4] = "Warn";
7
+ CoralogixLogSeverity[CoralogixLogSeverity["Error"] = 5] = "Error";
8
+ CoralogixLogSeverity[CoralogixLogSeverity["Critical"] = 6] = "Critical";
9
+ })(CoralogixLogSeverity || (CoralogixLogSeverity = {}));
10
+ //# sourceMappingURL=types-external.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types-external.js","sourceRoot":"","sources":["../../../../libs/browser/src/types-external.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,oBAOX;AAPD,WAAY,oBAAoB;IAC9B,iEAAS,CAAA;IACT,qEAAW,CAAA;IACX,+DAAQ,CAAA;IACR,+DAAQ,CAAA;IACR,iEAAS,CAAA;IACT,uEAAY,CAAA;AACd,CAAC,EAPW,oBAAoB,KAApB,oBAAoB,QAO/B"}
package/src/types.d.ts ADDED
@@ -0,0 +1,270 @@
1
+ import { Attributes } from '@opentelemetry/api';
2
+ import { CoralogixDomainsApiUrlMap } from './constants';
3
+ import { CoralogixLogSeverity } from './types-external';
4
+ import { ErrorSource } from './instrumentations/CoralogixErrorInstrumentation';
5
+ import { FetchSource } from './instrumentations/CoralogixFetchInstrumentation';
6
+ import { XHRSource } from './instrumentations/CoralogixXhrInstrumentation';
7
+ import { LogSource } from './instrumentations/CoralogixCustomLogInstrumentation';
8
+ import { ReadableSpan } from '@opentelemetry/sdk-trace-base';
9
+ import { StackFrame } from 'error-stack-parser';
10
+ import { CoralogixUserInteractionInstrumentationConfig } from './instrumentations/CoralogixUserInteractionInstrumentation';
11
+ import { Metric } from 'web-vitals/attribution';
12
+ import { CoralogixWebVitalsInstrumentationConfig } from './instrumentations/instrumentation.model';
13
+ export declare enum CoralogixEventType {
14
+ ERROR = "error",
15
+ NETWORK_REQUEST = "network-request",
16
+ LOG = "log",
17
+ USER_INTERACTION = "user-interaction",
18
+ WEB_VITALS = "web-vitals",
19
+ LONG_TASK = "longtask",
20
+ RESOURCES = "resources"
21
+ }
22
+ export declare enum PerformanceTypes {
23
+ Resource = "resource",
24
+ LongTask = "longtask",
25
+ Navigation = "navigation"
26
+ }
27
+ export type WebVitalsRating = 'good' | 'needs-improvement' | 'poor';
28
+ export type CoralogixDomain = keyof typeof CoralogixDomainsApiUrlMap;
29
+ export type CoralogixRumLabels = Record<string, any>;
30
+ export interface UserContextConfig {
31
+ user_id: string;
32
+ user_name: string;
33
+ user_email?: string;
34
+ user_metadata?: {
35
+ [key: string]: any;
36
+ };
37
+ }
38
+ export interface CustomTargetElement extends HTMLElement {
39
+ type: string;
40
+ value: string;
41
+ }
42
+ export interface ApplicationContextConfig {
43
+ application: string;
44
+ version: string;
45
+ }
46
+ export interface TraceHeaderConfiguration {
47
+ enabled: boolean;
48
+ options?: {
49
+ /** urls outside of origin that should also add Traceparent to header */
50
+ propagateTraceHeaderCorsUrls?: Array<string | RegExp>;
51
+ /** provides HTTP header propagation for systems that are using AWS X-Amzn-Trace-Id format. */
52
+ propagateAwsXrayTraceHeader?: boolean;
53
+ };
54
+ }
55
+ export interface CoralogixOtelWebOptionsInstrumentations {
56
+ errors?: boolean;
57
+ fetch?: boolean;
58
+ xhr?: boolean;
59
+ custom?: boolean;
60
+ long_tasks?: boolean;
61
+ resources?: boolean;
62
+ interactions?: boolean | CoralogixUserInteractionInstrumentationConfig;
63
+ web_vitals?: boolean | CoralogixWebVitalsInstrumentationConfig;
64
+ }
65
+ interface SendLog {
66
+ log: (severity: CoralogixLogSeverity, message: string, data?: any) => void;
67
+ debug: (message: string, data?: any) => void;
68
+ verbose: (message: string, data?: any) => void;
69
+ info: (message: string, data?: any) => void;
70
+ warn: (message: string, data?: any) => void;
71
+ error: (message: string, data?: any) => void;
72
+ critical: (message: string, data?: any) => void;
73
+ }
74
+ export interface CoralogixBrowserSdkConfig {
75
+ /** Publicly-visible `public_key` value */
76
+ public_key: string;
77
+ /** Sets a value for the `application` attribute */
78
+ application: string;
79
+ /** Coralogix account domain */
80
+ coralogixDomain: CoralogixDomain;
81
+ /** Sets a value for the 'app.version' attribute */
82
+ version: string;
83
+ /** Configuration for user context. */
84
+ user_context?: UserContextConfig;
85
+ /** Turns on/off internal debug logging */
86
+ debug?: boolean;
87
+ /** Sets labels added to every Span. */
88
+ labels?: CoralogixRumLabels;
89
+ /**
90
+ * Applies for XHR and Fetch URLs. URLs that partially match any regex in ignoreUrls will not be traced.
91
+ * In addition, URLs that are _exact matches_ of strings in ignoreUrls will also not be traced.
92
+ * */
93
+ ignoreUrls?: Array<string | RegExp>;
94
+ /**
95
+ A pattern for error messages which should not be sent to Coralogix. By default, all errors will be sent.
96
+ * */
97
+ ignoreErrors?: Array<string | RegExp>;
98
+ /** Configuration for instrumentation modules. */
99
+ instrumentations?: CoralogixOtelWebOptionsInstrumentations;
100
+ /** Add Traceparent to headers in order to start a trace */
101
+ traceParentInHeader?: TraceHeaderConfiguration;
102
+ /** Sets a value for the `environment` attribute */
103
+ environment?: string;
104
+ /** Stringify custom log data property */
105
+ stringifyCustomLogData?: boolean;
106
+ }
107
+ export interface CoralogixOtelWebType extends SendLog {
108
+ /**
109
+ * Init CoralogixRum.
110
+ */
111
+ init: (options: CoralogixBrowserSdkConfig) => void;
112
+ /**
113
+ * Turn CoralogixRum off.
114
+ */
115
+ shutdown: () => void;
116
+ /** Sets labels to be added to every log after CoralogixRum initialization. */
117
+ setLabels: (labels: CoralogixRumLabels) => void;
118
+ /**
119
+ * Provides access to computed, final value of global attributes, which are applied to all created logs.
120
+ */
121
+ getLabels: () => Attributes;
122
+ /** Sets user context to be added to every log after CoralogixRum initialization. */
123
+ setUserContext: (userContext: UserContextConfig) => void;
124
+ /** Sets application context to be added to every log after CoralogixRum initialization. */
125
+ setApplicationContext: (applicationContext: ApplicationContextConfig) => void;
126
+ /**
127
+ * Provides access to computed, final value of user context, which applied to all created logs.
128
+ */
129
+ getUserContext: () => UserContextConfig | undefined;
130
+ /**
131
+ * Provides the session id.
132
+ */
133
+ getSessionId: () => string | undefined;
134
+ readonly isInited: boolean;
135
+ }
136
+ export interface ErrorContext {
137
+ error_type?: string;
138
+ error_message?: string;
139
+ original_stacktrace?: Partial<StackFrame>[];
140
+ }
141
+ export interface LogContext {
142
+ message: string;
143
+ data?: any;
144
+ }
145
+ export interface NetworkRequestContext {
146
+ method: string;
147
+ status_code: number;
148
+ url: string;
149
+ fragments: string;
150
+ host: string;
151
+ schema: string;
152
+ status_text: string;
153
+ response_content_length: string;
154
+ duration: number;
155
+ }
156
+ export interface InteractionContext {
157
+ target_element: string;
158
+ target_element_inner_text: string;
159
+ target_element_inner_html: string;
160
+ target_element_type: string;
161
+ event_name: string;
162
+ element_id: string;
163
+ element_classes: string;
164
+ }
165
+ export interface LongTaskContext extends Omit<PerformanceEntry, 'toJSON'> {
166
+ id: string;
167
+ type: 'regular' | 'after_page_loaded';
168
+ }
169
+ export interface WebVitalsContext extends Metric {
170
+ }
171
+ export interface ResourceContext extends Omit<PerformanceResourceTiming, 'toJSON'> {
172
+ responseStatus?: number;
173
+ deliveryType?: string;
174
+ firstInterimResponseStart?: number;
175
+ renderBlockingStatus?: string;
176
+ }
177
+ export interface EventTypeContext {
178
+ error_context?: ErrorContext;
179
+ log_context?: LogContext;
180
+ network_request_context?: NetworkRequestContext;
181
+ interaction_context?: InteractionContext;
182
+ web_vitals_context?: WebVitalsContext;
183
+ longtask_context?: LongTaskContext;
184
+ resource_context?: ResourceContext;
185
+ }
186
+ export interface SessionContext {
187
+ session_id: string;
188
+ session_creation_date: number;
189
+ user_agent: string;
190
+ user_id: string;
191
+ user_name?: string;
192
+ user_email?: string;
193
+ browser?: Browser;
194
+ browserVersion: string;
195
+ os: OS;
196
+ osVersion: string;
197
+ device: Device;
198
+ user_metadata?: {
199
+ [key: string]: any;
200
+ };
201
+ }
202
+ export type EventSource = ErrorSource | FetchSource | XHRSource | LogSource;
203
+ export interface EventContext {
204
+ type: CoralogixEventType;
205
+ source: EventSource;
206
+ severity: CoralogixLogSeverity;
207
+ }
208
+ interface SpanContext {
209
+ readonly spanId: string;
210
+ readonly traceId: string;
211
+ }
212
+ interface OtelResource {
213
+ attributes: Attributes;
214
+ }
215
+ interface InstrumentationData {
216
+ otelSpan: Partial<ReadableSpan> & SpanContext;
217
+ otelResource: OtelResource;
218
+ }
219
+ interface VersionMetaData {
220
+ app_name: string;
221
+ app_version: string;
222
+ }
223
+ export interface CxRum extends EventTypeContext {
224
+ browser_sdk: {
225
+ version: string;
226
+ };
227
+ version_metadata: VersionMetaData;
228
+ session_context: SessionContext;
229
+ page_context: {
230
+ page_url: string;
231
+ page_fragments: string;
232
+ };
233
+ event_context: EventContext;
234
+ labels: CoralogixRumLabels;
235
+ spanId: string;
236
+ traceId: string;
237
+ environment: string;
238
+ timestamp: number;
239
+ }
240
+ export interface CxSpan {
241
+ version_metadata: VersionMetaData;
242
+ applicationName: string;
243
+ subsystemName: string;
244
+ timestamp: number;
245
+ severity: CoralogixLogSeverity;
246
+ isErrorWithStacktrace: boolean;
247
+ instrumentation_data?: InstrumentationData;
248
+ text: {
249
+ cx_rum: CxRum;
250
+ };
251
+ }
252
+ export interface Session {
253
+ sessionId: string;
254
+ sessionCreationDate: number;
255
+ sessionExpirationDate: number;
256
+ }
257
+ export declare enum OtelNetworkAttrs {
258
+ METHOD = "http.method",
259
+ URL = "http.url",
260
+ STATUS_CODE = "http.status_code",
261
+ HOST = "http.host",
262
+ SCHEME = "http.scheme",
263
+ STATUS_TEXT = "http.status_text",
264
+ RESPONSE_CONTENT_LENGTH = "http.response_content_length"
265
+ }
266
+ export type Browser = 'Chrome' | 'Edge' | 'Firefox' | 'Safari' | 'Opera' | 'IE' | 'Unknown';
267
+ export type OS = 'Windows' | 'MacOS' | 'Linux' | 'iOS' | 'Android' | 'Unknown';
268
+ export type Device = 'Mobile' | 'Tablet' | 'Desktop' | 'Unknown';
269
+ export type EventName = keyof HTMLElementEventMap;
270
+ export {};
package/src/types.js ADDED
@@ -0,0 +1,27 @@
1
+ export var CoralogixEventType;
2
+ (function (CoralogixEventType) {
3
+ CoralogixEventType["ERROR"] = "error";
4
+ CoralogixEventType["NETWORK_REQUEST"] = "network-request";
5
+ CoralogixEventType["LOG"] = "log";
6
+ CoralogixEventType["USER_INTERACTION"] = "user-interaction";
7
+ CoralogixEventType["WEB_VITALS"] = "web-vitals";
8
+ CoralogixEventType["LONG_TASK"] = "longtask";
9
+ CoralogixEventType["RESOURCES"] = "resources";
10
+ })(CoralogixEventType || (CoralogixEventType = {}));
11
+ export var PerformanceTypes;
12
+ (function (PerformanceTypes) {
13
+ PerformanceTypes["Resource"] = "resource";
14
+ PerformanceTypes["LongTask"] = "longtask";
15
+ PerformanceTypes["Navigation"] = "navigation";
16
+ })(PerformanceTypes || (PerformanceTypes = {}));
17
+ export var OtelNetworkAttrs;
18
+ (function (OtelNetworkAttrs) {
19
+ OtelNetworkAttrs["METHOD"] = "http.method";
20
+ OtelNetworkAttrs["URL"] = "http.url";
21
+ OtelNetworkAttrs["STATUS_CODE"] = "http.status_code";
22
+ OtelNetworkAttrs["HOST"] = "http.host";
23
+ OtelNetworkAttrs["SCHEME"] = "http.scheme";
24
+ OtelNetworkAttrs["STATUS_TEXT"] = "http.status_text";
25
+ OtelNetworkAttrs["RESPONSE_CONTENT_LENGTH"] = "http.response_content_length";
26
+ })(OtelNetworkAttrs || (OtelNetworkAttrs = {}));
27
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../libs/browser/src/types.ts"],"names":[],"mappings":"AAaA,MAAM,CAAN,IAAY,kBAQX;AARD,WAAY,kBAAkB;IAC5B,qCAAe,CAAA;IACf,yDAAmC,CAAA;IACnC,iCAAW,CAAA;IACX,2DAAqC,CAAA;IACrC,+CAAyB,CAAA;IACzB,4CAAsB,CAAA;IACtB,6CAAuB,CAAA;AACzB,CAAC,EARW,kBAAkB,KAAlB,kBAAkB,QAQ7B;AAED,MAAM,CAAN,IAAY,gBAIX;AAJD,WAAY,gBAAgB;IAC1B,yCAAqB,CAAA;IACrB,yCAAqB,CAAA;IACrB,6CAAyB,CAAA;AAC3B,CAAC,EAJW,gBAAgB,KAAhB,gBAAgB,QAI3B;AAyRD,MAAM,CAAN,IAAY,gBAQX;AARD,WAAY,gBAAgB;IAC1B,0CAAsB,CAAA;IACtB,oCAAgB,CAAA;IAChB,oDAAgC,CAAA;IAChC,sCAAkB,CAAA;IAClB,0CAAsB,CAAA;IACtB,oDAAgC,CAAA;IAChC,4EAAwD,CAAA;AAC1D,CAAC,EARW,gBAAgB,KAAhB,gBAAgB,QAQ3B"}
package/src/utils.d.ts ADDED
@@ -0,0 +1,24 @@
1
+ import { Browser, CoralogixBrowserSdkConfig, Device, OS, WebVitalsRating } from './types';
2
+ import { Attributes } from '@opentelemetry/api';
3
+ export declare const supportedPerformanceTypes: Record<string, boolean>;
4
+ export declare function valueEndWithOrInclude(value: string, extensions: string[]): boolean;
5
+ export declare function getInstrumentationConfig<T>(value: T | boolean | undefined, defaults?: T, defaultDisable?: T | boolean): T | false;
6
+ export declare function resolveCoralogixOtelWebConfig(config: CoralogixBrowserSdkConfig): CoralogixBrowserSdkConfig;
7
+ export declare const hrTimeToMilliseconds: ([seconds, nanoseconds]: [
8
+ number,
9
+ number
10
+ ]) => number;
11
+ export declare const isNetworkError: (status?: number) => boolean;
12
+ export declare const getUrlFragments: (url: string) => string;
13
+ export declare function parseUserAgent(userAgent: string): {
14
+ browser: Browser;
15
+ browserVersion: string;
16
+ os: OS;
17
+ osVersion: string;
18
+ device: Device;
19
+ };
20
+ export declare function calculateTotalBlockingTime(list: PerformanceEntry[]): number;
21
+ export declare function generateWebVitalUniqueID(): string;
22
+ export declare function rateForTBTMetricValue(value: number): WebVitalsRating;
23
+ export declare function flattenAttributes(attributes: Attributes): Attributes;
24
+ export declare const getCircularReplacer: () => (key: any, value: any) => undefined | any;
package/src/utils.js ADDED
@@ -0,0 +1,156 @@
1
+ import { __assign } from "tslib";
2
+ import { CoralogixAttributes, ID_MASK_KEY, NANOID_REGEX, OPTIONS_DEFAULTS, UUID_REGEX, } from './constants';
3
+ import { LONGTASK_DURATION } from './instrumentations/instrumentation.consts';
4
+ import { omit } from 'lodash-es';
5
+ export var supportedPerformanceTypes = !(window === null || window === void 0 ? void 0 : window.PerformanceObserver)
6
+ ? {}
7
+ : window.PerformanceObserver.supportedEntryTypes.reduce(function (obj, type) {
8
+ obj[type] = true;
9
+ return obj;
10
+ }, {});
11
+ export function valueEndWithOrInclude(value, extensions) {
12
+ return extensions.some(function (ex) { return value.endsWith(ex) || value.includes(ex); });
13
+ }
14
+ export function getInstrumentationConfig(value, defaults, defaultDisable) {
15
+ if (value === false) {
16
+ return value;
17
+ }
18
+ if (value === undefined && defaultDisable) {
19
+ return false;
20
+ }
21
+ if ((value === null || value === void 0 ? void 0 : value.enabled) === false) {
22
+ return false;
23
+ }
24
+ return Object.assign({}, defaults, value);
25
+ }
26
+ export function resolveCoralogixOtelWebConfig(config) {
27
+ var ignoreUrls = config.ignoreUrls;
28
+ var resolvedIgnoreUrls = [];
29
+ ignoreUrls && resolvedIgnoreUrls.push.apply(resolvedIgnoreUrls, ignoreUrls);
30
+ OPTIONS_DEFAULTS.ignoreUrls && resolvedIgnoreUrls.push.apply(resolvedIgnoreUrls, OPTIONS_DEFAULTS.ignoreUrls);
31
+ return __assign(__assign(__assign({}, OPTIONS_DEFAULTS), config), { ignoreUrls: resolvedIgnoreUrls });
32
+ }
33
+ export var hrTimeToMilliseconds = function (_a) {
34
+ var seconds = _a[0], nanoseconds = _a[1];
35
+ return seconds * 1000 + Math.round(nanoseconds / 1e6);
36
+ };
37
+ export var isNetworkError = function (status) {
38
+ if (!status) {
39
+ return false;
40
+ }
41
+ return status >= 400;
42
+ };
43
+ export var getUrlFragments = function (url) {
44
+ var _a, _b, _c;
45
+ var withoutProtocol = ((_a = url === null || url === void 0 ? void 0 : url.split('://')) === null || _a === void 0 ? void 0 : _a[1]) || url;
46
+ var fragments = ((_b = withoutProtocol.split('#')) === null || _b === void 0 ? void 0 : _b[1]) || withoutProtocol;
47
+ var cleanedFragments = (_c = fragments.split('?')) === null || _c === void 0 ? void 0 : _c[0];
48
+ var pathFragments = cleanedFragments === null || cleanedFragments === void 0 ? void 0 : cleanedFragments.split('/');
49
+ if (pathFragments.length) {
50
+ pathFragments.shift();
51
+ }
52
+ var replacedFragments = pathFragments.map(function (fragment) {
53
+ if (NANOID_REGEX.test(fragment) || UUID_REGEX.test(fragment)) {
54
+ return ID_MASK_KEY;
55
+ }
56
+ return fragment;
57
+ });
58
+ return replacedFragments === null || replacedFragments === void 0 ? void 0 : replacedFragments.join('/');
59
+ };
60
+ export function parseUserAgent(userAgent) {
61
+ var _a;
62
+ var browsers = {
63
+ Chrome: /Chrome\/([\d.]+)/,
64
+ Firefox: /Firefox\/([\d.]+)/,
65
+ Safari: /Version\/([\d.]+).*Safari/,
66
+ Edge: /Edge\/([\d.]+)/,
67
+ Opera: /Opera\/([\d.]+)/,
68
+ IE: /Trident.*rv:([\d.]+)/,
69
+ };
70
+ var operatingSystems = {
71
+ Windows: /Windows NT ([\d.]+)/,
72
+ MacOS: /Mac OS X ([\d._]+)/,
73
+ Linux: /Linux(?: ([\d.]+))?/,
74
+ iOS: /CPU(?: iPhone)? OS (\d+([._]\d+)*)/,
75
+ Android: /Android (\d+([._]\d+)*)/,
76
+ };
77
+ var devices = {
78
+ Mobile: /Mobile|Android|iPhone|iPod|BlackBerry|IEMobile|Windows Phone|webOS|Opera Mini/,
79
+ Tablet: /Tablet|iPad/,
80
+ };
81
+ var browser = 'Unknown';
82
+ var browserVersion = 'Unknown';
83
+ var os = 'Unknown';
84
+ var osVersion = 'Unknown';
85
+ var device = 'Desktop';
86
+ for (var _i = 0, _b = Object.entries(browsers); _i < _b.length; _i++) {
87
+ var _c = _b[_i], name_1 = _c[0], regex = _c[1];
88
+ var match = userAgent.match(regex);
89
+ if (match) {
90
+ browser = name_1;
91
+ browserVersion = match[1] || 'Unknown';
92
+ break;
93
+ }
94
+ }
95
+ for (var _d = 0, _e = Object.entries(operatingSystems); _d < _e.length; _d++) {
96
+ var _f = _e[_d], name_2 = _f[0], regex = _f[1];
97
+ var match = userAgent.match(regex);
98
+ if (match) {
99
+ os = name_2;
100
+ osVersion = ((_a = match[1]) === null || _a === void 0 ? void 0 : _a.replaceAll('_', '.')) || 'Unknown';
101
+ break;
102
+ }
103
+ }
104
+ for (var _g = 0, _h = Object.entries(devices); _g < _h.length; _g++) {
105
+ var _j = _h[_g], name_3 = _j[0], regex = _j[1];
106
+ var match = userAgent.match(regex);
107
+ if (match) {
108
+ device = name_3;
109
+ break;
110
+ }
111
+ }
112
+ return { browser: browser, browserVersion: browserVersion, os: os, osVersion: osVersion, device: device };
113
+ }
114
+ export function calculateTotalBlockingTime(list) {
115
+ return list.reduce(function (total, entry) {
116
+ total += entry.duration - LONGTASK_DURATION;
117
+ return total;
118
+ }, 0);
119
+ }
120
+ export function generateWebVitalUniqueID() {
121
+ return "v3-".concat(Date.now(), "-").concat(Math.floor(Math.random() * (9e12 - 1)) + 1e12);
122
+ }
123
+ export function rateForTBTMetricValue(value // ms
124
+ ) {
125
+ switch (true) {
126
+ case value > 600:
127
+ return 'poor';
128
+ case value > 200 && value <= 600:
129
+ return 'needs-improvement';
130
+ default:
131
+ return 'good';
132
+ }
133
+ }
134
+ export function flattenAttributes(attributes) {
135
+ var customLabels = JSON.parse(attributes[CoralogixAttributes.CUSTOM_LABELS]);
136
+ var flatAttributes = omit(attributes, CoralogixAttributes.CUSTOM_LABELS);
137
+ for (var _i = 0, _a = Object.entries(customLabels); _i < _a.length; _i++) {
138
+ var _b = _a[_i], key = _b[0], value = _b[1];
139
+ flatAttributes[key] =
140
+ typeof value !== 'string' ? JSON.stringify(value) : value;
141
+ }
142
+ return flatAttributes;
143
+ }
144
+ export var getCircularReplacer = function () {
145
+ var seen = new WeakSet();
146
+ return function (key, value) {
147
+ if (typeof value === 'object' && value !== null) {
148
+ if (seen.has(value)) {
149
+ return;
150
+ }
151
+ seen.add(value);
152
+ }
153
+ return value;
154
+ };
155
+ };
156
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../libs/browser/src/utils.ts"],"names":[],"mappings":";AAOA,OAAO,EACL,mBAAmB,EACnB,WAAW,EACX,YAAY,EACZ,gBAAgB,EAChB,UAAU,GACX,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,iBAAiB,EAAE,MAAM,2CAA2C,CAAC;AAE9E,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,MAAM,CAAC,IAAM,yBAAyB,GACpC,CAAC,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,mBAAmB,CAAA;IAC1B,CAAC,CAAC,EAAE;IACJ,CAAC,CAAC,MAAM,CAAC,mBAAmB,CAAC,mBAAmB,CAAC,MAAM,CACnD,UAAC,GAA4B,EAAE,IAAY;QACzC,GAAG,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;QACjB,OAAO,GAAG,CAAC;IACb,CAAC,EACD,EAAE,CACH,CAAC;AAER,MAAM,UAAU,qBAAqB,CACnC,KAAa,EACb,UAAoB;IAEpB,OAAO,UAAU,CAAC,IAAI,CAAC,UAAC,EAAE,IAAK,OAAA,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAxC,CAAwC,CAAC,CAAC;AAC3E,CAAC;AAED,MAAM,UAAU,wBAAwB,CACtC,KAA8B,EAC9B,QAAY,EACZ,cAA4B;IAE5B,IAAI,KAAK,KAAK,KAAK,EAAE;QACnB,OAAO,KAAK,CAAC;KACd;IAED,IAAI,KAAK,KAAK,SAAS,IAAI,cAAc,EAAE;QACzC,OAAO,KAAK,CAAC;KACd;IAED,IAAI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AC,CAAC,CAAC,KAAK,CAAC;KAC7D;IAED,OAAO,cAAc,CAAC;AACxB,CAAC;AAED,MAAM,CAAC,IAAM,mBAAmB,GAAG;IACjC,IAAM,IAAI,GAAG,IAAI,OAAO,EAAE,CAAC;IAC3B,OAAO,UAAC,GAAQ,EAAE,KAAU;QAC1B,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE;YAC/C,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;gBACnB,OAAO;aACR;YACD,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;SACjB;QACD,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export declare const SDK_VERSION = "1.0.73";
package/src/version.js ADDED
@@ -0,0 +1,2 @@
1
+ export var SDK_VERSION = '1.0.73';
2
+ //# sourceMappingURL=version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../../../libs/browser/src/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,IAAM,WAAW,GAAG,QAAQ,CAAC"}