@coralogix/browser 2.8.6 → 2.8.7

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,11 @@
1
+ ## 2.8.7 (2025-06-30)
2
+
3
+ ### 🩹 Fixes
4
+
5
+ - Add sessionId to span attr
6
+ - Fix adding network span to global span even when the global span is ended.
7
+ - Handle global span in idle mode.
8
+
1
9
  ## 2.8.6 (2025-06-26)
2
10
 
3
11
  ### 🧰 Improvements
package/index.esm2.js CHANGED
@@ -699,9 +699,26 @@ function getUserAgentData() {
699
699
  }
700
700
 
701
701
  var GLOBAL_SPAN_KEY = '__globalSpan__';
702
+ var GLOBAL_SPAN_MAP_KEY = '__globalSpanMap__';
702
703
  var CUSTOM_TRACER_KEY = '__customTracer__';
703
704
  var CUSTOM_TRACER_IGNORED_INSTRUMENTS = '__customTracerIgnoredInstruments__';
704
705
 
706
+ function addGlobalSpanByTraceId(traceId, globalSpan) {
707
+ var _a;
708
+ CxGlobal[GLOBAL_SPAN_MAP_KEY] = __assign(__assign({}, (CxGlobal[GLOBAL_SPAN_MAP_KEY] || {})), (_a = {}, _a[traceId] = globalSpan, _a));
709
+ }
710
+ function getGlobalSpanByTraceId(traceId) {
711
+ var _a;
712
+ return (_a = CxGlobal[GLOBAL_SPAN_MAP_KEY]) === null || _a === void 0 ? void 0 : _a[traceId];
713
+ }
714
+ function clearGlobalSpanMap() {
715
+ var globalSpanMap = CxGlobal[GLOBAL_SPAN_MAP_KEY];
716
+ Object.keys(globalSpanMap || {}).forEach(function (traceId) {
717
+ var globalSpan = globalSpanMap[traceId];
718
+ globalSpan === null || globalSpan === void 0 ? void 0 : globalSpan.endSpan();
719
+ });
720
+ delete CxGlobal[GLOBAL_SPAN_MAP_KEY];
721
+ }
705
722
  function setGlobalSpan(globalSpan) {
706
723
  CxGlobal[GLOBAL_SPAN_KEY] = globalSpan;
707
724
  }
@@ -724,9 +741,11 @@ function getCustomTracerIgnoredInstruments() {
724
741
  return CxGlobal[CUSTOM_TRACER_IGNORED_INSTRUMENTS];
725
742
  }
726
743
  function shouldAttachSpanToGlobalSpan(instrumentationType) {
744
+ return getGlobalSpan() && !isInstrumentationIgnored(instrumentationType);
745
+ }
746
+ function isInstrumentationIgnored(instrumentationType) {
727
747
  var _a;
728
- return (getGlobalSpan() &&
729
- !((_a = getCustomTracerIgnoredInstruments()) === null || _a === void 0 ? void 0 : _a.includes(instrumentationType)));
748
+ return !!((_a = getCustomTracerIgnoredInstruments()) === null || _a === void 0 ? void 0 : _a.includes(instrumentationType));
730
749
  }
731
750
  function attachChildSpanToGlobalSpan(name) {
732
751
  var globalSpan = getGlobalSpan();
@@ -1314,9 +1333,10 @@ var NetworkInstrumentationAttributes = {
1314
1333
  };
1315
1334
 
1316
1335
  function checkAttachingNetworkSpanToGlobalSpan(span) {
1317
- if (shouldAttachSpanToGlobalSpan(CoralogixEventType.NETWORK_REQUEST)) {
1318
- var globalSpan = getGlobalSpan();
1319
- var _a = globalSpan.span.spanContext(), traceId = _a.traceId, globalSpanId = _a.spanId;
1336
+ var activeGlobalSpan = getGlobalSpanByTraceId(span.spanContext().traceId);
1337
+ if (activeGlobalSpan &&
1338
+ !isInstrumentationIgnored(CoralogixEventType.NETWORK_REQUEST)) {
1339
+ var _a = activeGlobalSpan.span.spanContext(), traceId = _a.traceId, globalSpanId = _a.spanId;
1320
1340
  span['_spanContext'].traceId = traceId;
1321
1341
  span['parentSpanId'] = globalSpanId;
1322
1342
  }
@@ -3825,13 +3845,19 @@ var SessionManager = (function (_super) {
3825
3845
  console.debug('Coralogix Browser SDK - Session expired, clearing session');
3826
3846
  }
3827
3847
  (_a = CxGlobal.sessionStorage) === null || _a === void 0 ? void 0 : _a.setItem(PREV_SESSION_KEY, JSON.stringify(__assign(__assign({}, this.activeSession), { hasRecording: (_b = this.sessionRecorder) === null || _b === void 0 ? void 0 : _b.getSessionHasRecording(), hasScreenshot: (_c = this.sessionRecorder) === null || _c === void 0 ? void 0 : _c.getSessionHasScreenshot() })));
3828
- clearGlobalSpan();
3848
+ this.clearGlobalSpans();
3829
3849
  this.clearSessionWithErrorMode();
3830
3850
  (_d = getSnapshotManager()) === null || _d === void 0 ? void 0 : _d.resetSnapshot();
3831
3851
  this._currentPageFragment = undefined;
3832
3852
  (_e = this.sessionRecorder) === null || _e === void 0 ? void 0 : _e.stopRecording();
3833
3853
  (_f = CxGlobal.sessionStorage) === null || _f === void 0 ? void 0 : _f.removeItem(SESSION_KEY);
3834
3854
  };
3855
+ SessionManager.prototype.clearGlobalSpans = function () {
3856
+ var _a;
3857
+ (_a = getGlobalSpan()) === null || _a === void 0 ? void 0 : _a.endSpan();
3858
+ clearGlobalSpan();
3859
+ clearGlobalSpanMap();
3860
+ };
3835
3861
  SessionManager.prototype.clearSessionWithErrorMode = function () {
3836
3862
  this.sessionHasError = false;
3837
3863
  this.cachedLogsSent = false;
@@ -4014,7 +4040,7 @@ function resolveUrlBlueprinters(urlBlueprinters) {
4014
4040
  return resolvedUrlBlueprinters;
4015
4041
  }
4016
4042
 
4017
- var SDK_VERSION = '2.8.6';
4043
+ var SDK_VERSION = '2.8.7';
4018
4044
 
4019
4045
  function shouldDropEvent(cxRumEvent, options) {
4020
4046
  if (isDocumentErrorWithoutMessage(cxRumEvent)) {
@@ -4175,7 +4201,7 @@ var CoralogixSpanMapProcessor = (function () {
4175
4201
  traceId: traceId,
4176
4202
  parentSpanId: parentSpanId,
4177
4203
  name: name,
4178
- attributes: __assign(__assign({}, flattenAttributes(attributes)), this.resolveLabels(cxSpan.text.cx_rum)),
4204
+ attributes: __assign(__assign(__assign({}, flattenAttributes(attributes)), this.resolveLabels(cxSpan.text.cx_rum)), { sessionId: sessionId }),
4179
4205
  startTime: startTime,
4180
4206
  endTime: endTime,
4181
4207
  status: severity === CoralogixLogSeverity.Error
@@ -4731,6 +4757,7 @@ var CoralogixRum = {
4731
4757
  },
4732
4758
  };
4733
4759
  setGlobalSpan(globalSpanModel);
4760
+ addGlobalSpanByTraceId(globalSpan.spanContext().traceId, globalSpanModel);
4734
4761
  return globalSpanModel;
4735
4762
  },
4736
4763
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coralogix/browser",
3
- "version": "2.8.6",
3
+ "version": "2.8.7",
4
4
  "description": "Official Coralogix SDK for browsers",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Coralogix",
@@ -1,3 +1,4 @@
1
1
  export declare const GLOBAL_SPAN_KEY = "__globalSpan__";
2
+ export declare const GLOBAL_SPAN_MAP_KEY = "__globalSpanMap__";
2
3
  export declare const CUSTOM_TRACER_KEY = "__customTracer__";
3
4
  export declare const CUSTOM_TRACER_IGNORED_INSTRUMENTS = "__customTracerIgnoredInstruments__";
@@ -1,6 +1,9 @@
1
1
  import { CustomTracerIgnoredInstruments, GlobalSpan } from './custom-spans.types';
2
2
  import { Tracer } from '@opentelemetry/sdk-trace-base';
3
3
  import { Span } from '@opentelemetry/api';
4
+ export declare function addGlobalSpanByTraceId(traceId: string, globalSpan: GlobalSpan): void;
5
+ export declare function getGlobalSpanByTraceId(traceId: string): GlobalSpan | undefined;
6
+ export declare function clearGlobalSpanMap(): void;
4
7
  export declare function setGlobalSpan(globalSpan: GlobalSpan): void;
5
8
  export declare function getGlobalSpan(): GlobalSpan;
6
9
  export declare function clearGlobalSpan(): void;
@@ -10,4 +13,5 @@ export declare function clearCustomTracer(): void;
10
13
  export declare function setCustomTracerIgnoredInstruments(ignoredInstruments: CustomTracerIgnoredInstruments[]): void;
11
14
  export declare function getCustomTracerIgnoredInstruments(): CustomTracerIgnoredInstruments[];
12
15
  export declare function shouldAttachSpanToGlobalSpan(instrumentationType: CustomTracerIgnoredInstruments): boolean;
16
+ export declare function isInstrumentationIgnored(instrumentationType: CustomTracerIgnoredInstruments): boolean;
13
17
  export declare function attachChildSpanToGlobalSpan(name: string): Span;
@@ -34,6 +34,7 @@ export declare class SessionManager extends SessionIdle {
34
34
  private clearSessionWhenIdle;
35
35
  private clearPrevSession;
36
36
  private clearSession;
37
+ private clearGlobalSpans;
37
38
  private clearSessionWithErrorMode;
38
39
  private handleRefreshedSessions;
39
40
  private createNewSession;
package/src/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "2.8.6";
1
+ export declare const SDK_VERSION = "2.8.7";