@coralogix/browser 2.8.3 โ†’ 2.8.4

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/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## 2.8.4 (2025-05-29)
2
+
3
+ ### ๐Ÿฉน Fixes & Improvements
4
+
5
+ ๐Ÿ›  Custom Spans
6
+
7
+ - Traceparent propagation: XHR and Fetch requests now correctly include the global span traceId when using custom spans.
8
+ - Improved span creation: Enhanced the logic for generating custom child spans for more accurate trace hierarchy.
9
+ - Interaction tracing: User interaction instrumentation is now correctly linked to the global span context.
10
+
11
+ ๐Ÿงน Logging
12
+
13
+ - Switched internal warning logs to debug level to reduce noise in production environments.
14
+
1
15
  ## 2.8.3 (2025-05-22)
2
16
 
3
17
  ### ๐Ÿ”ฅ Performance
package/README.md CHANGED
@@ -779,9 +779,16 @@ Labels can be added during span creation for additional context.
779
779
  const customTracer = CoralogixRum.getCustomTracer();
780
780
  const globalSpan = customTracer.startGlobalSpan('global-span', { page: 'posts' });
781
781
 
782
- globalSpan.withContext(() => {
783
- const customSpan = globalSpan.startCustomSpan('custom-span', { action: 'scroll' });
784
- customSpan.endSpan();
782
+ // Easily create custom spans for specific operations in your application.
783
+ globalSpan.startCustomSpan('submit-button', { action: 'click' }).endSpan();
784
+
785
+ // You can also use the with context method to modeling a specific flow in your application.
786
+ globalSpan.withContext(async () => {
787
+ globalSpan.startCustomSpan('get-data-btn', { action: 'click' }).endSpan();
788
+ const res = await fetch('my-api-endpoint');
789
+ globalSpan.startCustomSpan('click-on-first-row', { action: 'click' }).endSpan();
790
+
791
+ // ... your code
785
792
  });
786
793
 
787
794
  // note: End the global span only after the operation is complete.
package/index.esm2.js CHANGED
@@ -48,6 +48,46 @@ function generateUUID(placeholder) {
48
48
  : "".concat(1e7, "-").concat(1e3, "-").concat(4e3, "-").concat(8e3, "-").concat(1e11).replace(/[018]/g, generateUUID);
49
49
  }
50
50
 
51
+ var CoralogixEventType;
52
+ (function (CoralogixEventType) {
53
+ CoralogixEventType["ERROR"] = "error";
54
+ CoralogixEventType["NETWORK_REQUEST"] = "network-request";
55
+ CoralogixEventType["LOG"] = "log";
56
+ CoralogixEventType["USER_INTERACTION"] = "user-interaction";
57
+ CoralogixEventType["WEB_VITALS"] = "web-vitals";
58
+ CoralogixEventType["LONG_TASK"] = "longtask";
59
+ CoralogixEventType["RESOURCES"] = "resources";
60
+ CoralogixEventType["INTERNAL"] = "internal";
61
+ CoralogixEventType["DOM"] = "dom";
62
+ CoralogixEventType["CUSTOM_MEASUREMENT"] = "custom-measurement";
63
+ CoralogixEventType["MEMORY_USAGE"] = "memory-usage";
64
+ CoralogixEventType["SCREENSHOT"] = "screenshot";
65
+ CoralogixEventType["CUSTOM_SPAN"] = "custom-span";
66
+ CoralogixEventType["WORKER"] = "web-worker";
67
+ })(CoralogixEventType || (CoralogixEventType = {}));
68
+ var PerformanceTypes;
69
+ (function (PerformanceTypes) {
70
+ PerformanceTypes["Resource"] = "resource";
71
+ PerformanceTypes["LongTask"] = "longtask";
72
+ PerformanceTypes["Navigation"] = "navigation";
73
+ PerformanceTypes["SoftNavigation"] = "soft-navigation";
74
+ })(PerformanceTypes || (PerformanceTypes = {}));
75
+ var OtelNetworkAttrs;
76
+ (function (OtelNetworkAttrs) {
77
+ OtelNetworkAttrs["METHOD"] = "http.method";
78
+ OtelNetworkAttrs["URL"] = "http.url";
79
+ OtelNetworkAttrs["STATUS_CODE"] = "http.status_code";
80
+ OtelNetworkAttrs["HOST"] = "http.host";
81
+ OtelNetworkAttrs["SCHEME"] = "http.scheme";
82
+ OtelNetworkAttrs["STATUS_TEXT"] = "http.status_text";
83
+ OtelNetworkAttrs["RESPONSE_CONTENT_LENGTH"] = "http.response_content_length";
84
+ })(OtelNetworkAttrs || (OtelNetworkAttrs = {}));
85
+ var UrlType;
86
+ (function (UrlType) {
87
+ UrlType["PAGE"] = "page";
88
+ UrlType["NETWORK_REQUEST"] = "network_request";
89
+ })(UrlType || (UrlType = {}));
90
+
51
91
  function isFunction(funktion) {
52
92
  return typeof funktion === 'function';
53
93
  }
@@ -151,45 +191,6 @@ shimmer.unwrap = unwrap;
151
191
  shimmer.massUnwrap = massUnwrap;
152
192
  var shimmer_1 = shimmer;
153
193
 
154
- var CoralogixEventType;
155
- (function (CoralogixEventType) {
156
- CoralogixEventType["ERROR"] = "error";
157
- CoralogixEventType["NETWORK_REQUEST"] = "network-request";
158
- CoralogixEventType["LOG"] = "log";
159
- CoralogixEventType["USER_INTERACTION"] = "user-interaction";
160
- CoralogixEventType["WEB_VITALS"] = "web-vitals";
161
- CoralogixEventType["LONG_TASK"] = "longtask";
162
- CoralogixEventType["RESOURCES"] = "resources";
163
- CoralogixEventType["INTERNAL"] = "internal";
164
- CoralogixEventType["DOM"] = "dom";
165
- CoralogixEventType["CUSTOM_MEASUREMENT"] = "custom-measurement";
166
- CoralogixEventType["MEMORY_USAGE"] = "memory-usage";
167
- CoralogixEventType["SCREENSHOT"] = "screenshot";
168
- CoralogixEventType["CUSTOM_SPAN"] = "custom-span";
169
- })(CoralogixEventType || (CoralogixEventType = {}));
170
- var PerformanceTypes;
171
- (function (PerformanceTypes) {
172
- PerformanceTypes["Resource"] = "resource";
173
- PerformanceTypes["LongTask"] = "longtask";
174
- PerformanceTypes["Navigation"] = "navigation";
175
- PerformanceTypes["SoftNavigation"] = "soft-navigation";
176
- })(PerformanceTypes || (PerformanceTypes = {}));
177
- var OtelNetworkAttrs;
178
- (function (OtelNetworkAttrs) {
179
- OtelNetworkAttrs["METHOD"] = "http.method";
180
- OtelNetworkAttrs["URL"] = "http.url";
181
- OtelNetworkAttrs["STATUS_CODE"] = "http.status_code";
182
- OtelNetworkAttrs["HOST"] = "http.host";
183
- OtelNetworkAttrs["SCHEME"] = "http.scheme";
184
- OtelNetworkAttrs["STATUS_TEXT"] = "http.status_text";
185
- OtelNetworkAttrs["RESPONSE_CONTENT_LENGTH"] = "http.response_content_length";
186
- })(OtelNetworkAttrs || (OtelNetworkAttrs = {}));
187
- var UrlType;
188
- (function (UrlType) {
189
- UrlType["PAGE"] = "page";
190
- UrlType["NETWORK_REQUEST"] = "network_request";
191
- })(UrlType || (UrlType = {}));
192
-
193
194
  var CoralogixLogSeverity;
194
195
  (function (CoralogixLogSeverity) {
195
196
  CoralogixLogSeverity[CoralogixLogSeverity["Debug"] = 1] = "Debug";
@@ -298,7 +299,7 @@ function clearGlobalSpan() {
298
299
  function setCustomTracer(customTracer) {
299
300
  CxGlobal[CUSTOM_TRACER_KEY] = customTracer;
300
301
  }
301
- function getCustomTracer() {
302
+ function getActiveCustomTracer() {
302
303
  return CxGlobal[CUSTOM_TRACER_KEY];
303
304
  }
304
305
  function setCustomTracerIgnoredInstruments(ignoredInstruments) {
@@ -313,13 +314,8 @@ function shouldAttachSpanToGlobalSpan(instrumentationType) {
313
314
  !((_a = getCustomTracerIgnoredInstruments()) === null || _a === void 0 ? void 0 : _a.includes(instrumentationType)));
314
315
  }
315
316
  function attachChildSpanToGlobalSpan(name) {
316
- var span;
317
317
  var globalSpan = getGlobalSpan();
318
- globalSpan.withContext(function () {
319
- var childSpan = globalSpan.startCustomSpan(name);
320
- span = childSpan.span;
321
- });
322
- return span;
318
+ return globalSpan.startCustomSpan(name).span;
323
319
  }
324
320
 
325
321
  var IS_OTEL_READY = 'otelReady';
@@ -2084,10 +2080,10 @@ var CoralogixUserInteractionInstrumentation = /** @class */ (function (_super) {
2084
2080
  this.handler = function (e) {
2085
2081
  var span;
2086
2082
  if (shouldAttachSpanToGlobalSpan(CoralogixEventType.USER_INTERACTION)) {
2087
- span = attachChildSpanToGlobalSpan(USER_INTERACTION_INSTRUMENTATION_NAME);
2083
+ span = attachChildSpanToGlobalSpan(CoralogixEventType.USER_INTERACTION);
2088
2084
  }
2089
2085
  else {
2090
- span = _this.tracer.startSpan(USER_INTERACTION_INSTRUMENTATION_NAME);
2086
+ span = _this.tracer.startSpan(CoralogixEventType.USER_INTERACTION);
2091
2087
  }
2092
2088
  var eventTarget = e.target;
2093
2089
  var config = getSdkConfig();
@@ -2606,32 +2602,32 @@ var INSTRUMENTATIONS = [
2606
2602
  },
2607
2603
  {
2608
2604
  Instrument: CoralogixInternalInstrumentation,
2609
- confKey: INTERNAL_INSTRUMENTATION_NAME,
2605
+ confKey: CoralogixEventType.INTERNAL,
2610
2606
  disable: false,
2611
2607
  },
2612
2608
  {
2613
2609
  Instrument: CoralogixDOMInstrumentation,
2614
- confKey: DOM_INSTRUMENTATION_NAME,
2610
+ confKey: CoralogixEventType.DOM,
2615
2611
  disable: false,
2616
2612
  },
2617
2613
  {
2618
2614
  Instrument: CoralogixCustomMeasurementInstrumentation,
2619
- confKey: CUSTOM_MEASUREMENT_INSTRUMENTATION_NAME,
2615
+ confKey: CoralogixEventType.CUSTOM_MEASUREMENT,
2620
2616
  disable: false,
2621
2617
  },
2622
2618
  {
2623
2619
  Instrument: CoralogixMemoryUsageInstrumentation,
2624
- confKey: MEMORY_USAGE_INSTRUMENTATION_NAME,
2620
+ confKey: CoralogixEventType.MEMORY_USAGE,
2625
2621
  disable: false,
2626
2622
  },
2627
2623
  {
2628
2624
  Instrument: CoralogixScreenshotInstrumentation,
2629
- confKey: SCREENSHOT_INSTRUMENTATION_NAME,
2625
+ confKey: CoralogixEventType.SCREENSHOT,
2630
2626
  disable: false,
2631
2627
  },
2632
2628
  {
2633
2629
  Instrument: CoralogixWorkerInstrumentation,
2634
- confKey: WORKER_INSTRUMENTATION,
2630
+ confKey: CoralogixEventType.WORKER,
2635
2631
  disable: false,
2636
2632
  },
2637
2633
  ];
@@ -4121,17 +4117,28 @@ var CxPropagator = /** @class */ (function () {
4121
4117
  };
4122
4118
  CxPropagator.prototype.inject = function (context, carrier, setter) {
4123
4119
  var _a, _b;
4120
+ function checkSpanContextChanges() {
4121
+ if (shouldAttachSpanToGlobalSpan(CoralogixEventType.NETWORK_REQUEST)) {
4122
+ var globalSpan = getGlobalSpan();
4123
+ var currentSpanContext = trace.getSpanContext(context);
4124
+ var globalTraceId = globalSpan.span.spanContext().traceId;
4125
+ if (currentSpanContext) {
4126
+ currentSpanContext.traceId = globalTraceId;
4127
+ context = trace.setSpanContext(context, currentSpanContext);
4128
+ }
4129
+ }
4130
+ }
4124
4131
  var allowedUrls = (_b = (_a = this.config.traceParentInHeader) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b.allowedTracingUrls;
4132
+ var shouldInjectContext = true;
4125
4133
  if (allowedUrls) {
4126
4134
  var span = trace.getSpan(context);
4127
4135
  var url = span.attributes[OtelNetworkAttrs.URL];
4128
- var isUrlAllowed = isPatternMatch(url, allowedUrls, 'allowedTracingUrls');
4129
- if (isUrlAllowed) {
4130
- this.internalPropagator.inject(context, carrier, setter);
4131
- }
4132
- return;
4136
+ shouldInjectContext = isPatternMatch(url, allowedUrls, 'allowedTracingUrls');
4137
+ }
4138
+ if (shouldInjectContext) {
4139
+ checkSpanContextChanges();
4140
+ this.internalPropagator.inject(context, carrier, setter);
4133
4141
  }
4134
- this.internalPropagator.inject(context, carrier, setter);
4135
4142
  };
4136
4143
  return CxPropagator;
4137
4144
  }());
@@ -4210,7 +4217,7 @@ function resolveUrlBlueprinters(urlBlueprinters) {
4210
4217
  return resolvedUrlBlueprinters;
4211
4218
  }
4212
4219
 
4213
- var SDK_VERSION = '2.8.3';
4220
+ var SDK_VERSION = '2.8.4';
4214
4221
 
4215
4222
  function shouldDropEvent(cxRumEvent, options) {
4216
4223
  if (isDocumentErrorWithoutMessage(cxRumEvent)) {
@@ -4729,8 +4736,8 @@ var CoralogixRum = {
4729
4736
  var _this = this;
4730
4737
  try {
4731
4738
  // Check if CoralogixRum already inited.
4732
- if (isInited) {
4733
- console.warn('CoralogixRum already inited.');
4739
+ if (isInited && (options === null || options === void 0 ? void 0 : options.debug)) {
4740
+ console.debug('CoralogixRum already initialized, skipping init');
4734
4741
  return;
4735
4742
  }
4736
4743
  // Abort if not in browser environment.
@@ -4769,7 +4776,7 @@ var CoralogixRum = {
4769
4776
  if (pluginConf) {
4770
4777
  var instrumentation = void 0;
4771
4778
  switch (confKey) {
4772
- case WORKER_INSTRUMENTATION: {
4779
+ case CoralogixEventType.WORKER: {
4773
4780
  if (resolvedOptions_1.workerSupport) {
4774
4781
  instrumentation = new Instrument(pluginConf, errorsInstrumentation, _this);
4775
4782
  }
@@ -4792,12 +4799,12 @@ var CoralogixRum = {
4792
4799
  instrumentation = new Instrument(__assign(__assign({}, pluginConf), { ignoreUrls: ignoreUrls_1, traceParentInHeader: traceParentInHeader_1 }));
4793
4800
  break;
4794
4801
  }
4795
- case INTERNAL_INSTRUMENTATION_NAME: {
4802
+ case CoralogixEventType.INTERNAL: {
4796
4803
  instrumentation = new Instrument(pluginConf);
4797
4804
  saveInternalRumData(INTERNAL_INSTRUMENTATION_NAME, instrumentation);
4798
4805
  break;
4799
4806
  }
4800
- case SCREENSHOT_INSTRUMENTATION_NAME: {
4807
+ case CoralogixEventType.SCREENSHOT: {
4801
4808
  if ((_c = resolvedOptions_1.sessionRecordingConfig) === null || _c === void 0 ? void 0 : _c.enable) {
4802
4809
  instrumentation = new Instrument(pluginConf);
4803
4810
  screenshotInstrumentation =
@@ -4805,7 +4812,7 @@ var CoralogixRum = {
4805
4812
  }
4806
4813
  break;
4807
4814
  }
4808
- case MEMORY_USAGE_INSTRUMENTATION_NAME: {
4815
+ case CoralogixEventType.MEMORY_USAGE: {
4809
4816
  if (resolvedOptions_1.memoryUsageConfig.enabled &&
4810
4817
  isMeasureUserAgentSpecificMemoryAllowed()) {
4811
4818
  instrumentation = new Instrument(pluginConf);
@@ -4872,7 +4879,7 @@ var CoralogixRum = {
4872
4879
  saveInternalRumData(NETWORK_URL_LABEL_PROVIDERS_KEY, networkUrlLabelProviders);
4873
4880
  isInited = true;
4874
4881
  if (options === null || options === void 0 ? void 0 : options.debug) {
4875
- console.info('Coralogix Browser SDK - initialization has completed');
4882
+ console.debug('Coralogix Browser SDK - initialization has completed');
4876
4883
  }
4877
4884
  reportInternalEvent('init');
4878
4885
  }
@@ -4890,7 +4897,7 @@ var CoralogixRum = {
4890
4897
  console.debug('Coralogix Browser SDK - TraceParentInHeader is not enabled');
4891
4898
  return;
4892
4899
  }
4893
- if (getCustomTracer()) {
4900
+ if (getActiveCustomTracer()) {
4894
4901
  console.warn('Coralogix Browser SDK - Custom tracer already exists');
4895
4902
  return;
4896
4903
  }
@@ -4899,7 +4906,7 @@ var CoralogixRum = {
4899
4906
  return {
4900
4907
  startGlobalSpan: function (name, labels) {
4901
4908
  if (getGlobalSpan()) {
4902
- console.warn('Coralogix Browser SDK - Global span already exists');
4909
+ console.warn('Coralogix Browser SDK - Global span already exists');
4903
4910
  return;
4904
4911
  }
4905
4912
  setCustomTracerIgnoredInstruments((ignoredList === null || ignoredList === void 0 ? void 0 : ignoredList.ignoredInstruments) || []);
@@ -4920,13 +4927,16 @@ var CoralogixRum = {
4920
4927
  clearGlobalSpan();
4921
4928
  },
4922
4929
  startCustomSpan: function (name, labels) {
4923
- var customSpan = tracer.startSpan(name);
4924
- customSpan[CoralogixAttributes.EVENT_TYPE] =
4925
- CoralogixEventType.CUSTOM_SPAN;
4926
- if (labels) {
4927
- setCustomLabelsForSpan(customSpan, labels);
4928
- }
4929
- markSpanAsOtelToSend(customSpan);
4930
+ var customSpan;
4931
+ context.with(trace.setSpan(context.active(), globalSpan), function () {
4932
+ customSpan = tracer.startSpan(name);
4933
+ customSpan[CoralogixAttributes.EVENT_TYPE] =
4934
+ CoralogixEventType.CUSTOM_SPAN;
4935
+ if (labels) {
4936
+ setCustomLabelsForSpan(customSpan, labels);
4937
+ }
4938
+ markSpanAsOtelToSend(customSpan);
4939
+ });
4930
4940
  return {
4931
4941
  span: customSpan,
4932
4942
  endSpan: function () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coralogix/browser",
3
- "version": "2.8.3",
3
+ "version": "2.8.4",
4
4
  "description": "Official Coralogix SDK for browsers",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Coralogix",
@@ -5,7 +5,7 @@ export declare function setGlobalSpan(globalSpan: GlobalSpan): void;
5
5
  export declare function getGlobalSpan(): GlobalSpan;
6
6
  export declare function clearGlobalSpan(): void;
7
7
  export declare function setCustomTracer(customTracer: Tracer): void;
8
- export declare function getCustomTracer(): Tracer;
8
+ export declare function getActiveCustomTracer(): Tracer;
9
9
  export declare function clearCustomTracer(): void;
10
10
  export declare function setCustomTracerIgnoredInstruments(ignoredInstruments: CustomTracerIgnoredInstruments[]): void;
11
11
  export declare function getCustomTracerIgnoredInstruments(): CustomTracerIgnoredInstruments[];
@@ -1,8 +1,5 @@
1
1
  import { InstrumentationConfig } from '@opentelemetry/instrumentation';
2
- import { CUSTOM_MEASUREMENT_INSTRUMENTATION_NAME, DOM_INSTRUMENTATION_NAME, INTERNAL_INSTRUMENTATION_NAME, WORKER_INSTRUMENTATION } from './instrumentation.consts';
3
- import { MEMORY_USAGE_INSTRUMENTATION_NAME } from './memory-usage';
4
- import { SCREENSHOT_INSTRUMENTATION_NAME } from './screenshot/screenshot.utils';
5
- import { CoralogixOtelWebOptionsInstrumentations } from '../types';
2
+ import { CoralogixEventType, CoralogixOtelWebOptionsInstrumentations } from '../types';
6
3
  export interface CoralogixWebVitalsMetrics {
7
4
  lcp: boolean;
8
5
  fid: boolean;
@@ -34,6 +31,6 @@ export declare enum ResourceInitiatorTypes {
34
31
  }
35
32
  export type InternalInstrumentationConfig = {
36
33
  Instrument: any;
37
- confKey: keyof CoralogixOtelWebOptionsInstrumentations | typeof CUSTOM_MEASUREMENT_INSTRUMENTATION_NAME | typeof INTERNAL_INSTRUMENTATION_NAME | typeof DOM_INSTRUMENTATION_NAME | typeof MEMORY_USAGE_INSTRUMENTATION_NAME | typeof SCREENSHOT_INSTRUMENTATION_NAME | typeof WORKER_INSTRUMENTATION;
34
+ confKey: keyof CoralogixOtelWebOptionsInstrumentations | CoralogixEventType;
38
35
  disable: boolean;
39
36
  };
package/src/types.d.ts CHANGED
@@ -45,7 +45,8 @@ export declare enum CoralogixEventType {
45
45
  CUSTOM_MEASUREMENT = "custom-measurement",
46
46
  MEMORY_USAGE = "memory-usage",
47
47
  SCREENSHOT = "screenshot",
48
- CUSTOM_SPAN = "custom-span"
48
+ CUSTOM_SPAN = "custom-span",
49
+ WORKER = "web-worker"
49
50
  }
50
51
  export declare enum PerformanceTypes {
51
52
  Resource = "resource",
package/src/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "2.8.3";
1
+ export declare const SDK_VERSION = "2.8.4";