@coralogix/browser 1.0.0

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 (50) hide show
  1. package/README.md +3 -0
  2. package/browser-sdk-version.d.ts +1 -0
  3. package/browser-sdk-version.js +2 -0
  4. package/browser-sdk-version.js.map +1 -0
  5. package/package.json +21 -0
  6. package/src/CoralogixCustomLogInstrumentation.d.ts +12 -0
  7. package/src/CoralogixCustomLogInstrumentation.js +32 -0
  8. package/src/CoralogixCustomLogInstrumentation.js.map +1 -0
  9. package/src/CoralogixErrorInstrumentation.d.ts +30 -0
  10. package/src/CoralogixErrorInstrumentation.js +193 -0
  11. package/src/CoralogixErrorInstrumentation.js.map +1 -0
  12. package/src/CoralogixExporter.d.ts +14 -0
  13. package/src/CoralogixExporter.js +149 -0
  14. package/src/CoralogixExporter.js.map +1 -0
  15. package/src/CoralogixFetchInstrumentation.d.ts +8 -0
  16. package/src/CoralogixFetchInstrumentation.js +28 -0
  17. package/src/CoralogixFetchInstrumentation.js.map +1 -0
  18. package/src/CoralogixPropgator.d.ts +3 -0
  19. package/src/CoralogixPropgator.js +9 -0
  20. package/src/CoralogixPropgator.js.map +1 -0
  21. package/src/CoralogixSpanAttributesProcessor.d.ts +18 -0
  22. package/src/CoralogixSpanAttributesProcessor.js +57 -0
  23. package/src/CoralogixSpanAttributesProcessor.js.map +1 -0
  24. package/src/CoralogixWebTracerProvider.d.ts +3 -0
  25. package/src/CoralogixWebTracerProvider.js +4 -0
  26. package/src/CoralogixWebTracerProvider.js.map +1 -0
  27. package/src/CoralogixXhrInstrumentation.d.ts +7 -0
  28. package/src/CoralogixXhrInstrumentation.js +25 -0
  29. package/src/CoralogixXhrInstrumentation.js.map +1 -0
  30. package/src/constants.d.ts +54 -0
  31. package/src/constants.js +67 -0
  32. package/src/constants.js.map +1 -0
  33. package/src/index.d.ts +2 -0
  34. package/src/index.js +170 -0
  35. package/src/index.js.map +1 -0
  36. package/src/types-external.d.ts +8 -0
  37. package/src/types-external.js +10 -0
  38. package/src/types-external.js.map +1 -0
  39. package/src/types.d.ts +202 -0
  40. package/src/types.js +17 -0
  41. package/src/types.js.map +1 -0
  42. package/src/utils..d.ts +11 -0
  43. package/src/utils..js +67 -0
  44. package/src/utils..js.map +1 -0
  45. package/tests/integration/utils.d.ts +7 -0
  46. package/tests/integration/utils.js +39 -0
  47. package/tests/integration/utils.js.map +1 -0
  48. package/tests/unit/test-utils.d.ts +2 -0
  49. package/tests/unit/test-utils.js +14 -0
  50. package/tests/unit/test-utils.js.map +1 -0
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Coralogix Browser Sdk
2
+
3
+ Visit Coralogix [Docs](https://coralogix.com/docs/).
@@ -0,0 +1 @@
1
+ export declare const browserSdkVersion = "1.0.0";
@@ -0,0 +1,2 @@
1
+ export const browserSdkVersion = '1.0.0';
2
+ //# sourceMappingURL=browser-sdk-version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser-sdk-version.js","sourceRoot":"","sources":["../../../libs/browser/browser-sdk-version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,iBAAiB,GAAG,OAAO,CAAC"}
package/package.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "@coralogix/browser",
3
+ "version": "1.0.0",
4
+ "dependencies": {
5
+ "@opentelemetry/api": "1.4.1",
6
+ "@opentelemetry/exporter-trace-otlp-http": "0.40.0",
7
+ "@opentelemetry/instrumentation": "0.40.0",
8
+ "@opentelemetry/instrumentation-fetch": "0.40.0",
9
+ "@opentelemetry/instrumentation-xml-http-request": "0.40.0",
10
+ "@opentelemetry/sdk-trace-base": "1.14.0",
11
+ "@opentelemetry/sdk-trace-web": "1.14.0",
12
+ "error-stack-parser": "2.1.4",
13
+ "lodash-es": "4.17.21",
14
+ "@types/lodash-es": "4.17.8",
15
+ "tslib": "2.3.0",
16
+ "ts-node": "10.9.1",
17
+ "typescript": "4.8.2"
18
+ },
19
+ "main": "./src/index.js",
20
+ "types": "./src/index.d.ts"
21
+ }
@@ -0,0 +1,12 @@
1
+ import { InstrumentationBase, InstrumentationConfig } from '@opentelemetry/instrumentation';
2
+ import { CoralogixLogSeverity } from './types-external';
3
+ export declare const CUSTOM_INSTRUMENTATION_VERSION = "1";
4
+ export declare enum LogSource {
5
+ CODE = "code"
6
+ }
7
+ export declare class CoralogixCustomLogInstrumentation extends InstrumentationBase {
8
+ constructor(config: InstrumentationConfig);
9
+ init(): void;
10
+ enable(): void;
11
+ log(severity: CoralogixLogSeverity, message: string, data?: any): void;
12
+ }
@@ -0,0 +1,32 @@
1
+ import { InstrumentationBase, } from '@opentelemetry/instrumentation';
2
+ import { hrTime } from '@opentelemetry/core';
3
+ import { CoralogixAttributes } from './constants';
4
+ import { CoralogixEventType } from './types';
5
+ export const CUSTOM_INSTRUMENTATION_VERSION = '1';
6
+ export var LogSource;
7
+ (function (LogSource) {
8
+ LogSource["CODE"] = "code";
9
+ })(LogSource || (LogSource = {}));
10
+ export class CoralogixCustomLogInstrumentation extends InstrumentationBase {
11
+ constructor(config) {
12
+ super(CoralogixEventType.LOG, CUSTOM_INSTRUMENTATION_VERSION, config);
13
+ }
14
+ init() { }
15
+ enable() { }
16
+ log(severity, message, data) {
17
+ const now = hrTime();
18
+ const span = this.tracer.startSpan(CoralogixEventType.LOG, {
19
+ startTime: now,
20
+ });
21
+ span.setAttribute(CoralogixAttributes.EVENT_TYPE, CoralogixEventType.LOG);
22
+ span.setAttribute(CoralogixAttributes.SOURCE, LogSource.CODE);
23
+ span.setAttribute(CoralogixAttributes.SEVERITY, severity);
24
+ span.setAttribute(CoralogixAttributes.LOG, JSON.stringify({
25
+ severity,
26
+ message,
27
+ data,
28
+ }));
29
+ span.end(now);
30
+ }
31
+ }
32
+ //# sourceMappingURL=CoralogixCustomLogInstrumentation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CoralogixCustomLogInstrumentation.js","sourceRoot":"","sources":["../../../../libs/browser/src/C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AAG,CAAC,GAAG,CAAC,CAAC;IAChB,CAAC;CACF"}
@@ -0,0 +1,30 @@
1
+ import { InstrumentationBase, InstrumentationConfig } from '@opentelemetry/instrumentation';
2
+ export declare const ERROR_INSTRUMENTATION_NAME = "errors";
3
+ export declare const ERROR_INSTRUMENTATION_VERSION = "1";
4
+ export declare const ErrorAttributes: {
5
+ TYPE: string;
6
+ STACK: string;
7
+ MESSAGE: string;
8
+ };
9
+ export declare enum ErrorSource {
10
+ CONSOLE = "console",
11
+ WINDOW = "window",
12
+ UNHANDLED_REJECTION = "unhandledrejection",
13
+ DOCUMENT = "document"
14
+ }
15
+ export interface CoralogixErrorInstrumentationConfig extends InstrumentationConfig {
16
+ ignoreErrors?: Array<string | RegExp>;
17
+ }
18
+ export declare class CoralogixErrorInstrumentation extends InstrumentationBase {
19
+ ignoreErrors?: Array<string | RegExp>;
20
+ constructor(config: CoralogixErrorInstrumentationConfig);
21
+ init(): void;
22
+ enable(): void;
23
+ disable(): void;
24
+ report(source: ErrorSource, arg: string | Error | Event | ErrorEvent | Array<any>): void;
25
+ protected reportError(source: ErrorSource, err: Error): void;
26
+ protected reportString(source: ErrorSource, message: string, firstError?: Error): void;
27
+ protected reportErrorEvent(source: ErrorSource, { error, message }: ErrorEvent): void;
28
+ protected reportEvent(source: string, ev: Event): void;
29
+ private _shouldIgnoreError;
30
+ }
@@ -0,0 +1,193 @@
1
+ import { getElementXPath } from '@opentelemetry/sdk-trace-web';
2
+ import { hrTime } from '@opentelemetry/core';
3
+ import { InstrumentationBase, } from '@opentelemetry/instrumentation';
4
+ import { wrap, unwrap } from 'shimmer';
5
+ import { CoralogixAttributes } from './constants';
6
+ import { CoralogixEventType } from './types';
7
+ import { CoralogixLogSeverity } from './types-external';
8
+ export const ERROR_INSTRUMENTATION_NAME = 'errors';
9
+ export const ERROR_INSTRUMENTATION_VERSION = '1';
10
+ export const ErrorAttributes = {
11
+ TYPE: 'error_type',
12
+ STACK: 'error_stack',
13
+ MESSAGE: 'error_message',
14
+ };
15
+ export var ErrorSource;
16
+ (function (ErrorSource) {
17
+ ErrorSource["CONSOLE"] = "console";
18
+ ErrorSource["WINDOW"] = "window";
19
+ ErrorSource["UNHANDLED_REJECTION"] = "unhandledrejection";
20
+ ErrorSource["DOCUMENT"] = "document";
21
+ })(ErrorSource || (ErrorSource = {}));
22
+ const STACK_LIMIT = 4096;
23
+ const MESSAGE_LIMIT = 1024;
24
+ function addStackIfUseful(span, err) {
25
+ const { stack } = err;
26
+ if (err && stack) {
27
+ span.setAttribute(ErrorAttributes.STACK, stack.substring(0, STACK_LIMIT));
28
+ }
29
+ }
30
+ const _consoleErrorHandler = (that) => {
31
+ return (original) => (...args) => {
32
+ that.report(ErrorSource.CONSOLE, args);
33
+ return original.apply(that, args);
34
+ };
35
+ };
36
+ const _errorListener = (that) => {
37
+ return (event) => {
38
+ that.report(ErrorSource.WINDOW, event);
39
+ };
40
+ };
41
+ const _unhandledRejectionListener = (that) => {
42
+ return (event) => {
43
+ that.report(ErrorSource.UNHANDLED_REJECTION, event.reason);
44
+ };
45
+ };
46
+ const _documentErrorListener = (that) => {
47
+ return (event) => {
48
+ that.report(ErrorSource.DOCUMENT, event);
49
+ };
50
+ };
51
+ function addErrorDefaultAttributes(span) {
52
+ span.setAttribute(CoralogixAttributes.EVENT_TYPE, CoralogixEventType.ERROR);
53
+ span.setAttribute(CoralogixAttributes.SEVERITY, CoralogixLogSeverity.Error);
54
+ }
55
+ export class CoralogixErrorInstrumentation extends InstrumentationBase {
56
+ constructor(config) {
57
+ super(ERROR_INSTRUMENTATION_NAME, ERROR_INSTRUMENTATION_VERSION, config);
58
+ this.ignoreErrors = config.ignoreErrors;
59
+ }
60
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
61
+ init() { }
62
+ enable() {
63
+ wrap(console, 'error', _consoleErrorHandler(this));
64
+ window.addEventListener('error', _errorListener(this));
65
+ window.addEventListener('unhandledrejection', _unhandledRejectionListener(this));
66
+ document.documentElement.addEventListener('error', _documentErrorListener(this), {
67
+ capture: true,
68
+ });
69
+ }
70
+ disable() {
71
+ unwrap(console, 'error');
72
+ window.removeEventListener('error', _errorListener(this));
73
+ window.removeEventListener('unhandledrejection', _unhandledRejectionListener(this));
74
+ document.documentElement.removeEventListener('error', _documentErrorListener(this), { capture: true });
75
+ }
76
+ report(source, arg) {
77
+ if (this._shouldIgnoreError(arg)) {
78
+ return;
79
+ }
80
+ if (arg instanceof Array) {
81
+ if (arg.length === 0) {
82
+ return;
83
+ }
84
+ else {
85
+ arg = arg[0];
86
+ }
87
+ }
88
+ switch (true) {
89
+ case arg instanceof Error:
90
+ this.reportError(source, arg);
91
+ break;
92
+ case arg instanceof ErrorEvent:
93
+ this.reportErrorEvent(source, arg);
94
+ break;
95
+ case arg instanceof Event:
96
+ this.reportEvent(source, arg);
97
+ break;
98
+ case typeof arg === 'string':
99
+ this.reportString(source, arg);
100
+ break;
101
+ case arg instanceof Array: {
102
+ // if any arguments are Errors then add the stack trace even though the message is handled differently
103
+ const firstError = arg.find((x) => x instanceof Error);
104
+ this.reportString(source, arg.map((x) => JSON.stringify(x)).join(' '), firstError);
105
+ break;
106
+ }
107
+ default:
108
+ this.reportString(source, JSON.stringify(arg));
109
+ }
110
+ }
111
+ reportError(source, err) {
112
+ const now = hrTime();
113
+ const { message, name } = err;
114
+ const span = this.tracer.startSpan('error', { startTime: now });
115
+ addErrorDefaultAttributes(span);
116
+ span.setAttribute(CoralogixAttributes.SOURCE, source);
117
+ span.setAttribute(ErrorAttributes.TYPE, name);
118
+ span.setAttribute(ErrorAttributes.MESSAGE, message);
119
+ addStackIfUseful(span, err);
120
+ span.end(now);
121
+ }
122
+ reportString(source, message, firstError) {
123
+ const now = hrTime();
124
+ const span = this.tracer.startSpan(source, { startTime: now });
125
+ addErrorDefaultAttributes(span);
126
+ span.setAttribute(CoralogixAttributes.SOURCE, source);
127
+ span.setAttribute(ErrorAttributes.MESSAGE, message === null || message === void 0 ? void 0 : message.substring(0, MESSAGE_LIMIT));
128
+ if (firstError) {
129
+ addStackIfUseful(span, firstError);
130
+ }
131
+ span.end(now);
132
+ }
133
+ reportErrorEvent(source, { error, message }) {
134
+ const event = error !== null && error !== void 0 ? error : message;
135
+ this.report(source, event);
136
+ }
137
+ reportEvent(source, ev) {
138
+ if (!ev.target) {
139
+ return;
140
+ }
141
+ const now = hrTime();
142
+ const span = this.tracer.startSpan(source, { startTime: now });
143
+ addErrorDefaultAttributes(span);
144
+ span.setAttribute(CoralogixAttributes.SOURCE, source);
145
+ if (ev.target) {
146
+ span.setAttribute('target_element', ev.target.tagName);
147
+ span.setAttribute('target_xpath', getElementXPath(ev.target, true));
148
+ span.setAttribute('target_src', ev.target.src);
149
+ }
150
+ span.end(now);
151
+ }
152
+ _shouldIgnoreError(arg) {
153
+ var _a;
154
+ if (!((_a = this.ignoreErrors) === null || _a === void 0 ? void 0 : _a.length)) {
155
+ return false;
156
+ }
157
+ let toBeMatched = '';
158
+ switch (true) {
159
+ case arg instanceof Error: {
160
+ const { name, message } = arg;
161
+ toBeMatched = name + ' ' + message;
162
+ break;
163
+ }
164
+ case arg instanceof ErrorEvent: {
165
+ const { message } = arg;
166
+ toBeMatched = message;
167
+ break;
168
+ }
169
+ case arg instanceof Event: {
170
+ const { type } = arg;
171
+ toBeMatched = type;
172
+ break;
173
+ }
174
+ case typeof arg === 'string': {
175
+ toBeMatched = arg;
176
+ break;
177
+ }
178
+ case arg instanceof Array: {
179
+ toBeMatched = arg.join(' ');
180
+ break;
181
+ }
182
+ default:
183
+ toBeMatched = arg;
184
+ }
185
+ for (const ignoreError of this.ignoreErrors) {
186
+ if (toBeMatched.match(ignoreError)) {
187
+ return true;
188
+ }
189
+ }
190
+ return false;
191
+ }
192
+ }
193
+ //# sourceMappingURL=CoralogixErrorInstrumentation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CoralogixErrorInstrumentation.js","sourceRoot":"","sources":["../../../../libs/browser/src/CoralogixErrorInstrumentation.ts"],"names":[],"mappings":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K,GAAG,YAAY,KAAK,CAAC,CAAC;gBACzB,WAAW,GAAI,GAAkB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;gBAC5C,MAAM;aACP;YACD;gBACE,WAAW,GAAG,GAAa,CAAC;SAC/B;QAED,KAAK,MAAM,WAAW,IAAI,IAAI,CAAC,YAAY,EAAE;YAC3C,IAAI,WAAW,CAAC,KAAK,CAAC,WAAW,CAAC,EAAE;gBAClC,OAAO,IAAI,CAAC;aACb;SACF;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF"}
@@ -0,0 +1,14 @@
1
+ import { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-base';
2
+ import { CoralogixOtelWebConfig } from './types';
3
+ declare type CoralogixExporterConfig = Pick<CoralogixOtelWebConfig, 'public_key' | 'application' | 'coralogixdDomain'>;
4
+ export declare class CoralogixExporter implements SpanExporter {
5
+ private public_key;
6
+ private application;
7
+ private coralogixdDomain;
8
+ constructor({ public_key, application, coralogixdDomain, }: CoralogixExporterConfig);
9
+ export(spans: ReadableSpan[]): void;
10
+ shutdown(): Promise<void>;
11
+ private _mapToCxSpan;
12
+ private _getEventTypeContext;
13
+ }
14
+ export {};
@@ -0,0 +1,149 @@
1
+ import { CoralogixEventType, OtelNetworkAttrs, } from './types';
2
+ import { CORALOGIX_LOGS_URL_SUFFIX, CoralogixAttributes, CoralogixDomainsApiUrlMap, miillisecondsInSecond, } from './constants';
3
+ import { CoralogixLogSeverity } from './types-external';
4
+ import { browserSdkVersion } from '../browser-sdk-version';
5
+ import ErrorStackParser from 'error-stack-parser';
6
+ import { parseUserAgent } from './utils.';
7
+ export class CoralogixExporter {
8
+ constructor({ public_key, application, coralogixdDomain, }) {
9
+ this.public_key = '';
10
+ this.application = '';
11
+ this.coralogixdDomain = 'EU2';
12
+ this.public_key = public_key;
13
+ this.application = application;
14
+ this.coralogixdDomain = coralogixdDomain;
15
+ }
16
+ export(spans) {
17
+ const cxSpans = spans.map((s) => this._mapToCxSpan(s));
18
+ const url = `${CoralogixDomainsApiUrlMap[this.coralogixdDomain]}${CORALOGIX_LOGS_URL_SUFFIX}`;
19
+ fetch(url, {
20
+ method: 'POST',
21
+ headers: {
22
+ 'Content-Type': 'application/json',
23
+ Authorization: `Bearer ${this.public_key}`,
24
+ },
25
+ body: JSON.stringify({ logs: cxSpans }),
26
+ }).catch((e) => {
27
+ return e;
28
+ });
29
+ }
30
+ shutdown() {
31
+ return Promise.resolve();
32
+ }
33
+ _mapToCxSpan(span) {
34
+ var _a, _b;
35
+ const { attributes, startTime, parentSpanId, name, endTime, status, duration, kind, } = span;
36
+ const eventTypeContext = this._getEventTypeContext(span);
37
+ const { spanId, traceId } = span.spanContext();
38
+ const resourceAttributes = Object.assign(Object.assign({}, (_a = span.resource) === null || _a === void 0 ? void 0 : _a.attributes), { 'service.name': this.application });
39
+ const user_context = JSON.parse(attributes[CoralogixAttributes.USER_CONTEXT]);
40
+ const { user_id, user_name, user_metadata, user_email } = user_context;
41
+ const labels = JSON.parse(attributes[CoralogixAttributes.CUSTOM_LABELS]);
42
+ const isErrorWithStacktrace = !!((_b = eventTypeContext === null || eventTypeContext === void 0 ? void 0 : eventTypeContext.error_context) === null || _b === void 0 ? void 0 : _b.original_stacktrace);
43
+ return {
44
+ applicationName: this.application,
45
+ subsystemName: 'cx_rum',
46
+ isErrorWithStacktrace,
47
+ severity: (attributes === null || attributes === void 0 ? void 0 : attributes[CoralogixAttributes.SEVERITY]) ||
48
+ CoralogixLogSeverity.Info,
49
+ timestamp: startTime[0] * miillisecondsInSecond,
50
+ instrumentation_data: {
51
+ otelSpan: {
52
+ spanId,
53
+ traceId,
54
+ parentSpanId,
55
+ name,
56
+ attributes,
57
+ startTime,
58
+ endTime,
59
+ status,
60
+ kind,
61
+ duration,
62
+ },
63
+ otelResource: {
64
+ attributes: resourceAttributes,
65
+ },
66
+ },
67
+ text: {
68
+ cx_rum: Object.assign(Object.assign({}, eventTypeContext), { browser_sdk: {
69
+ version: browserSdkVersion,
70
+ }, version_metadata: {
71
+ app_name: attributes[CoralogixAttributes.APP_NAME],
72
+ app_version: attributes[CoralogixAttributes.APP_VERSION],
73
+ }, session_context: Object.assign(Object.assign({ session_id: '', user_session_id: '', user_agent: attributes[CoralogixAttributes.USER_AGENT] }, parseUserAgent(attributes[CoralogixAttributes.USER_AGENT])), { user_id,
74
+ user_name,
75
+ user_email,
76
+ user_metadata }), page_context: {
77
+ page_url: attributes[CoralogixAttributes.LOCATION_HREF],
78
+ }, event_context: {
79
+ type: attributes[CoralogixAttributes.EVENT_TYPE],
80
+ source: attributes[CoralogixAttributes.SOURCE],
81
+ severity: CoralogixLogSeverity.Error,
82
+ }, labels,
83
+ spanId,
84
+ traceId, environment: attributes[CoralogixAttributes.ENVIRONMENT] || '' }),
85
+ },
86
+ };
87
+ }
88
+ _getEventTypeContext({ attributes }) {
89
+ var _a;
90
+ const eventType = attributes[CoralogixAttributes.EVENT_TYPE];
91
+ switch (eventType) {
92
+ case CoralogixEventType.ERROR: {
93
+ const errorMessage = attributes[CoralogixAttributes.ERROR.MESSAGE];
94
+ const stack = attributes[CoralogixAttributes.ERROR.STACK];
95
+ let originalStackTrace = undefined;
96
+ if (stack) {
97
+ originalStackTrace = (_a = ErrorStackParser.parse({
98
+ stack: attributes[CoralogixAttributes.ERROR.STACK],
99
+ message: errorMessage,
100
+ name: '',
101
+ })) === null || _a === void 0 ? void 0 : _a.map(({ fileName, columnNumber, lineNumber, functionName }) => ({
102
+ fileName,
103
+ columnNumber,
104
+ lineNumber,
105
+ functionName,
106
+ }));
107
+ }
108
+ return {
109
+ error_context: {
110
+ error_type: attributes[CoralogixAttributes.ERROR.TYPE],
111
+ error_message: errorMessage,
112
+ original_stacktrace: originalStackTrace,
113
+ },
114
+ };
115
+ }
116
+ case CoralogixEventType.NETWORK_REQUEST: {
117
+ return {
118
+ network_request_context: {
119
+ method: attributes[OtelNetworkAttrs.METHOD],
120
+ status_code: attributes[OtelNetworkAttrs.STATUS_CODE],
121
+ url: attributes[OtelNetworkAttrs.URL],
122
+ host: attributes[OtelNetworkAttrs.HOST],
123
+ schema: attributes[OtelNetworkAttrs.SCHEME],
124
+ status_text: attributes[OtelNetworkAttrs.STATUS_TEXT],
125
+ response_content_length: attributes[OtelNetworkAttrs.RESPONSE_CONTENT_LENGTH],
126
+ },
127
+ };
128
+ }
129
+ case CoralogixEventType.LOG: {
130
+ if (attributes[CoralogixAttributes.LOG]) {
131
+ const cxLog = JSON.parse(attributes[CoralogixAttributes.LOG]);
132
+ return {
133
+ log_context: {
134
+ message: cxLog.message,
135
+ data: cxLog === null || cxLog === void 0 ? void 0 : cxLog.data,
136
+ },
137
+ };
138
+ }
139
+ return {
140
+ log_context: {
141
+ message: '',
142
+ },
143
+ };
144
+ }
145
+ }
146
+ return {};
147
+ }
148
+ }
149
+ //# sourceMappingURL=CoralogixExporter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CoralogixExporter.js","sourceRoot":"","sources":["../../../../libs/browser/src/CoralogixExporter.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,kBAAkB,EAMlB,gBAAgB,GAEjB,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,yBAAyB,EACzB,mBAAmB,EACnB,yBAAyB,EACzB,qBAAqB,GACtB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,gBAAgC,MAAM,oBAAoB,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAO1C,MAAM,OAAO,iBAAiB;IAK5B,YAAY,EACV,UAAU,EACV,WAAW,EACX,gBAAgB,GACQ;QARlB,eAAU,GAAG,EAAE,CAAC;QAChB,gBAAW,GAAG,EAAE,CAAC;QACjB,qBAAgB,GAAoB,KAAK,CAAC;QAOhD,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAA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+ 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,28 @@
1
+ import { FetchInstrumentation, } from '@opentelemetry/instrumentation-fetch';
2
+ import { CoralogixAttributes } from './constants';
3
+ import { CoralogixEventType } from './types';
4
+ import { CoralogixLogSeverity } from './types-external';
5
+ import { propagateTraceHeaderCorsUrls } from './CoralogixPropgator';
6
+ import { isNetworkError } from './utils.';
7
+ export var FetchSource;
8
+ (function (FetchSource) {
9
+ FetchSource["FETCH"] = "fetch";
10
+ })(FetchSource || (FetchSource = {}));
11
+ export class CoralogixFetchInstrumentation extends FetchInstrumentation {
12
+ constructor(config) {
13
+ propagateTraceHeaderCorsUrls(config);
14
+ config.applyCustomAttributesOnSpan = (span, request, result) => {
15
+ const { status } = result;
16
+ span.setAttribute(CoralogixAttributes.SEVERITY, isNetworkError(status)
17
+ ? CoralogixLogSeverity.Error
18
+ : CoralogixLogSeverity.Info);
19
+ span.setAttribute(CoralogixAttributes.EVENT_TYPE, CoralogixEventType.NETWORK_REQUEST);
20
+ span.setAttribute(CoralogixAttributes.SOURCE, FetchSource.FETCH);
21
+ };
22
+ super(config);
23
+ }
24
+ enable() {
25
+ super.enable();
26
+ }
27
+ }
28
+ //# sourceMappingURL=CoralogixFetchInstrumentation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CoralogixFetchInstrumentation.js","sourceRoot":"","sources":["../../../../libs/browser/src/CoralogixFetchInstrumentation.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,GAErB,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,4BAA4B,EAAE,MAAM,sBAAsB,CAAC;AACpE,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,MAAM,OAAO,6BAA8B,SAAQ,oBAAoB;IACrE,YAAY,MAAkC;QAC5C,4BAA4B,CAAC,MAAM,CAAC,CAAC;QAErC,MAAM,CAAC,2BAA2B,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE;YAC7D,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;YAE1B,IAAI,CAAC,YAAY,CACf,mBAAmB,CAAC,QAAQ,EAC5B,cAAc,CAAC,MAAM,CAAC;gBACpB,CAAC,CAAC,oBAAoB,CAAC,KAAK;gBAC5B,CAAC,CAAC,oBAAoB,CAAC,IAAI,CAC9B,CAAC;YACF,IAAI,CAAC,YAAY,CACf,mBAAmB,CAAC,UAAU,EAC9B,kBAAkB,CAAC,eAAe,CACnC,CAAC;YACF,IAAI,CAAC,YAAY,CAAC,mBAAmB,CAAC,MAAM,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC;QACnE,CAAC,CAAC;QAEF,KAAK,CAAC,MAAM,CAAC,CAAC;IAChB,CAAC;IAEQ,MAAM;QACb,KAAK,CAAC,MAAM,EAAE,CAAC;IACjB,CAAC;CACF"}
@@ -0,0 +1,3 @@
1
+ import { FetchInstrumentationConfig } from '@opentelemetry/instrumentation-fetch';
2
+ import { XMLHttpRequestInstrumentationConfig } from '@opentelemetry/instrumentation-xml-http-request';
3
+ export declare const propagateTraceHeaderCorsUrls: (config: FetchInstrumentationConfig | XMLHttpRequestInstrumentationConfig) => void;
@@ -0,0 +1,9 @@
1
+ export const propagateTraceHeaderCorsUrls = (config) => {
2
+ var _a;
3
+ const { traceParentInHeader } = config;
4
+ const propagateCorsUrls = (_a = traceParentInHeader === null || traceParentInHeader === void 0 ? void 0 : traceParentInHeader.options) === null || _a === void 0 ? void 0 : _a.propagateTraceHeaderCorsUrls;
5
+ if ((traceParentInHeader === null || traceParentInHeader === void 0 ? void 0 : traceParentInHeader.enabled) && propagateCorsUrls) {
6
+ config.propagateTraceHeaderCorsUrls = propagateCorsUrls;
7
+ }
8
+ };
9
+ //# sourceMappingURL=CoralogixPropgator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CoralogixPropgator.js","sourceRoot":"","sources":["../../../../libs/browser/src/CoralogixPropgator.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAC1C,MAAwE,EACxE,EAAE;;IACF,MAAM,EAAE,mBAAmB,EAAE,GAAG,MAAgC,CAAC;IAEjE,MAAM,iBAAiB,GACrB,MAAA,mBAAmB,aAAnB,mBAAmB,uBAAnB,mBAAmB,CAAE,OAAO,0CAAE,4BAA4B,CAAC;IAE7D,IAAI,CAAA,mBAAmB,aAAnB,mBAAmB,uBAAnB,mBAAmB,CAAE,OAAO,KAAI,iBAAiB,EAAE;QACrD,MAAM,CAAC,4BAA4B,GAAG,iBAAiB,CAAC;KACzD;AACH,CAAC,CAAC"}
@@ -0,0 +1,18 @@
1
+ import { Attributes } from '@opentelemetry/api';
2
+ import { Span, SpanProcessor } from '@opentelemetry/sdk-trace-base';
3
+ import { CoralogixRumLabels, UserContextConfig } from './types';
4
+ export declare class CoralogixSpanAttributesProcessor implements SpanProcessor {
5
+ private labels;
6
+ constructor(labels?: Attributes);
7
+ setCustomLabels(labels?: CoralogixRumLabels): void;
8
+ setInternalLabels(labels?: CoralogixRumLabels): void;
9
+ getLabels(): any;
10
+ getCustomLabels(): Attributes;
11
+ getInternalLabels(): Attributes;
12
+ getUserContext(): UserContextConfig | undefined;
13
+ forceFlush(): Promise<void>;
14
+ onStart(span: Span): void;
15
+ onEnd(): void;
16
+ shutdown(): Promise<void>;
17
+ private stringifyValues;
18
+ }
@@ -0,0 +1,57 @@
1
+ import { CoralogixAttributes } from './constants';
2
+ export class CoralogixSpanAttributesProcessor {
3
+ constructor(labels) {
4
+ this.labels = {
5
+ [CoralogixAttributes.CUSTOM_LABELS]: '{}',
6
+ };
7
+ if (labels) {
8
+ this.labels = labels;
9
+ }
10
+ }
11
+ setCustomLabels(labels) {
12
+ this.labels[CoralogixAttributes.CUSTOM_LABELS] = JSON.stringify(labels !== null && labels !== void 0 ? labels : {});
13
+ }
14
+ setInternalLabels(labels) {
15
+ this.labels = Object.assign({ [CoralogixAttributes.CUSTOM_LABELS]: this.labels[CoralogixAttributes.CUSTOM_LABELS] }, (labels ? this.stringifyValues(labels) : {}));
16
+ }
17
+ getLabels() {
18
+ return JSON.parse(JSON.stringify(this.labels));
19
+ }
20
+ getCustomLabels() {
21
+ return JSON.parse(this.labels[CoralogixAttributes.CUSTOM_LABELS]);
22
+ }
23
+ getInternalLabels() {
24
+ const labels = Object.assign({}, this.labels);
25
+ delete labels[CoralogixAttributes.CUSTOM_LABELS];
26
+ return labels;
27
+ }
28
+ getUserContext() {
29
+ const userContext = this.labels[CoralogixAttributes.USER_CONTEXT];
30
+ return userContext ? JSON.parse(`${userContext}`) : undefined;
31
+ }
32
+ forceFlush() {
33
+ return Promise.resolve();
34
+ }
35
+ onStart(span) {
36
+ var _a, _b, _c, _d;
37
+ span.setAttribute(CoralogixAttributes.LOCATION_HREF, location.href);
38
+ span.setAttribute(CoralogixAttributes.USER_AGENT, navigator.userAgent);
39
+ span.setAttribute(CoralogixAttributes.COUNTRY, (_d = (_c = (_b = (_a = new Date().toString()) === null || _a === void 0 ? void 0 : _a.split('(')) === null || _b === void 0 ? void 0 : _b[1]) === null || _c === void 0 ? void 0 : _c.split(' ')) === null || _d === void 0 ? void 0 : _d[0]);
40
+ span.setAttributes(this.labels);
41
+ }
42
+ onEnd() { }
43
+ shutdown() {
44
+ return Promise.resolve();
45
+ }
46
+ stringifyValues(labels) {
47
+ const resolvedLabels = {};
48
+ for (const key in labels) {
49
+ resolvedLabels[key] =
50
+ typeof labels[key] === 'string'
51
+ ? labels[key]
52
+ : JSON.stringify(labels[key]);
53
+ }
54
+ return resolvedLabels;
55
+ }
56
+ }
57
+ //# sourceMappingURL=CoralogixSpanAttributesProcessor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CoralogixSpanAttributesProcessor.js","sourceRoot":"","sources":["../../../../libs/browser/src/CoralogixSpanAttributesProcessor.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAElD,MAAM,OAAO,gCAAgC;IAK3C,YAAY,MAAmB;QAJvB,WAAM,GAAuB;YACnC,CAAC,mBAAmB,CAAC,aAAa,CAAC,EAAE,IAAI;SAC1C,CAAC;QAGA,IAAI,MAAM,EAAE;YACV,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;SACtB;IACH,CAAC;IAED,eAAe,CAAC,MAA2B;QACzC,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC,aAAa,CAAC,GAAG,IAAI,CAAC,SAAS,CAC7D,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CACb,CAAC;IACJ,CAAC;IAED,iBAAiB,CAAC,MAA2B;QAC3C,IAAI,CAAC,MAAM,mBACT,CAAC,mBAAmB,CAAC,aAAa,CAAC,EACjC,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC,aAAa,CAAC,IAC7C,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAChD,CAAC;IACJ,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IACjD,CAAC;IAED,eAAe;QACb,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CA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