@coralogix/browser 2.10.0 → 2.11.1

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,21 @@
1
+ ## 2.11.1 (2025-11-24)
2
+
3
+ ### 🩹 Fixes
4
+
5
+ - Trigger snapshot context when setUserContext is called
6
+
7
+ ## 2.11.0 (2025-11-23)
8
+
9
+ ### 🚀 Features
10
+
11
+ - **trace:** allow custom propagator
12
+
13
+ ## 2.10.1 (2025-11-17)
14
+
15
+ ### 🩹 Fixes
16
+
17
+ - **url-fragments:** Fix URL encoding of template placeholders in page_fragments. Template placeholders like `{id}`, `{lbid}` etc. added by URL blueprinters are now preserved in `page_fragments` instead of being percent-encoded to `%7Bid%7D`, `%7Blbid%7D`. This ensures consistency between `page_url_blueprint` and `page_fragments`.
18
+
1
19
  ## 2.10.0 (2025-09-14)
2
20
 
3
21
  ### 🚀 Features
package/README.md CHANGED
@@ -657,6 +657,82 @@ CoralogixRum.init({
657
657
  },
658
658
  },
659
659
  });
660
+ ```
661
+
662
+ #### Custom Propagation
663
+ ```javascript
664
+ CoralogixRum.init({
665
+ // ...
666
+ traceParentInHeader: {
667
+ enabled: true,
668
+ options: {
669
+ // ...
670
+ /* for Custom propagation */
671
+ propagateCustomTraceHeader: new CustomPropagator()
672
+ },
673
+ },
674
+ });
675
+
676
+ // Example of CustomPropagator, Converts the 128-bit OpenTelemetry trace/span IDs into 64-bit decimal IDs
677
+
678
+ import {
679
+ TextMapGetter,
680
+ TextMapSetter,
681
+ TextMapPropagator,
682
+ Context,
683
+ trace,
684
+ } from '@opentelemetry/api';
685
+
686
+ export class CustomPropagator implements TextMapPropagator {
687
+ inject(context: Context, carrier: any, setter: TextMapSetter) {
688
+ const span = trace.getSpan(context);
689
+ if (!span) return;
690
+
691
+ const spanContext = span.spanContext();
692
+ if (!spanContext) return;
693
+
694
+ // Custom trace ID = last 64 bits of OTel trace ID
695
+ const customTraceId = BigInt(
696
+ '0x' + spanContext.traceId.slice(16)
697
+ ).toString();
698
+ const customParentId = BigInt('0x' + spanContext.spanId).toString();
699
+
700
+ setter.set(carrier, 'my-custom-trace-id', customTraceId);
701
+ setter.set(carrier, 'my-custom-parent-id', customParentId);
702
+ }
703
+
704
+ extract(context: Context, carrier: any, getter: TextMapGetter): Context {
705
+ const traceIdHeader = getter.get(carrier, 'my-custom-trace-id');
706
+ const parentIdHeader = getter.get(carrier, 'my-custom-parent-id');
707
+
708
+ if (!traceIdHeader || !parentIdHeader) return context;
709
+
710
+ const traceId = BigInt(traceIdHeader as string)
711
+ .toString(16)
712
+ .padStart(32, '0');
713
+
714
+ const spanId = BigInt(parentIdHeader as string)
715
+ .toString(16)
716
+ .padStart(16, '0');
717
+
718
+ return trace.setSpan(
719
+ context,
720
+ trace.wrapSpanContext({
721
+ traceId,
722
+ spanId,
723
+ traceFlags: 1,
724
+ isRemote: true,
725
+ })
726
+ );
727
+ }
728
+
729
+ fields(): string[] {
730
+ return ['my-custom-trace-id', 'my-custom-parent-id'];
731
+ }
732
+ }
733
+
734
+
735
+
660
736
  ```
661
737
 
662
738
  ### Before Send
package/index.esm2.js CHANGED
@@ -2660,7 +2660,7 @@ var getUrlFragments = function (url) {
2660
2660
  if (url.startsWith('blob:')) {
2661
2661
  return url;
2662
2662
  }
2663
- return new URL(url).pathname.substring(1) || BASE_PATH;
2663
+ return decodeURIComponent(new URL(url).pathname.substring(1)) || BASE_PATH;
2664
2664
  }
2665
2665
  catch (err) {
2666
2666
  console.warn('Coralogix Browser SDK - Error parsing URL', err);
@@ -3819,12 +3819,12 @@ var reportInternalEvent = function (event, message) {
3819
3819
 
3820
3820
  function handlePropagators(config, tracerProvider) {
3821
3821
  return __awaiter(this, void 0, void 0, function () {
3822
- var propagators, _a, propagateB3TraceHeader, propagateAwsXrayTraceHeader, singleHeader, multiHeader;
3822
+ var propagators, _a, propagateB3TraceHeader, propagateAwsXrayTraceHeader, propagateCustomTraceHeader, singleHeader, multiHeader;
3823
3823
  var _b, _c;
3824
3824
  return __generator(this, function (_d) {
3825
3825
  if ((_b = config.traceParentInHeader) === null || _b === void 0 ? void 0 : _b.enabled) {
3826
3826
  propagators = [];
3827
- _a = ((_c = config.traceParentInHeader) === null || _c === void 0 ? void 0 : _c.options) || {}, propagateB3TraceHeader = _a.propagateB3TraceHeader, propagateAwsXrayTraceHeader = _a.propagateAwsXrayTraceHeader;
3827
+ _a = ((_c = config.traceParentInHeader) === null || _c === void 0 ? void 0 : _c.options) || {}, propagateB3TraceHeader = _a.propagateB3TraceHeader, propagateAwsXrayTraceHeader = _a.propagateAwsXrayTraceHeader, propagateCustomTraceHeader = _a.propagateCustomTraceHeader;
3828
3828
  if (!propagateAwsXrayTraceHeader && !propagateB3TraceHeader) {
3829
3829
  propagators = __spreadArray(__spreadArray([], __read$1(propagators), false), [
3830
3830
  new W3CBaggagePropagator(),
@@ -3843,6 +3843,9 @@ function handlePropagators(config, tracerProvider) {
3843
3843
  propagators.push(new B3Propagator({ injectEncoding: B3InjectEncoding.MULTI_HEADER }));
3844
3844
  }
3845
3845
  }
3846
+ if (propagateCustomTraceHeader) {
3847
+ propagators.push(propagateCustomTraceHeader);
3848
+ }
3846
3849
  tracerProvider.register({
3847
3850
  propagator: new CxPropagator(config, new CompositePropagator({
3848
3851
  propagators: propagators,
@@ -3965,7 +3968,7 @@ function resolveUrlBlueprinters(urlBlueprinters) {
3965
3968
  return resolvedUrlBlueprinters;
3966
3969
  }
3967
3970
 
3968
- var SDK_VERSION = '2.10.0';
3971
+ var SDK_VERSION = '2.11.1';
3969
3972
 
3970
3973
  function shouldDropEvent(cxRumEvent, options) {
3971
3974
  if (isDocumentErrorWithoutMessage(cxRumEvent)) {
@@ -4375,6 +4378,10 @@ var CoralogixSnapshotSpanProcessor = (function () {
4375
4378
  if (spanType === CoralogixEventType.USER_INTERACTION) {
4376
4379
  updateSnapshot({ actionCount: actionCount + 1 });
4377
4380
  }
4381
+ if (getSnapshotManager().shouldTriggerSnapshotContext) {
4382
+ shouldCreateSnapshot = true;
4383
+ getSnapshotManager().shouldTriggerSnapshotContext = false;
4384
+ }
4378
4385
  return shouldCreateSnapshot;
4379
4386
  };
4380
4387
  return CoralogixSnapshotSpanProcessor;
@@ -4383,6 +4390,7 @@ var CoralogixSnapshotSpanProcessor = (function () {
4383
4390
  var SnapshotManager = (function () {
4384
4391
  function SnapshotManager() {
4385
4392
  var _this = this;
4393
+ this._shouldTriggerSnapshotContext = false;
4386
4394
  this.updateSnapshot = function (overrides) {
4387
4395
  _this._currentSnapshot = __assign(__assign({}, _this._currentSnapshot), overrides);
4388
4396
  };
@@ -4418,6 +4426,16 @@ var SnapshotManager = (function () {
4418
4426
  enumerable: false,
4419
4427
  configurable: true
4420
4428
  });
4429
+ Object.defineProperty(SnapshotManager.prototype, "shouldTriggerSnapshotContext", {
4430
+ get: function () {
4431
+ return this._shouldTriggerSnapshotContext;
4432
+ },
4433
+ set: function (value) {
4434
+ this._shouldTriggerSnapshotContext = value;
4435
+ },
4436
+ enumerable: false,
4437
+ configurable: true
4438
+ });
4421
4439
  return SnapshotManager;
4422
4440
  }());
4423
4441
 
@@ -4790,6 +4808,7 @@ var CoralogixRum = {
4790
4808
  console.debug('CoralogixRum must be initiated before setting user context');
4791
4809
  return;
4792
4810
  }
4811
+ getSnapshotManager().shouldTriggerSnapshotContext = true;
4793
4812
  attributesProcessor === null || attributesProcessor === void 0 ? void 0 : attributesProcessor.setInternalLabels(__assign(__assign({}, attributesProcessor.getInternalLabels()), (_a = {}, _a[CoralogixAttributes.USER_CONTEXT] = userContext, _a)));
4794
4813
  },
4795
4814
  getUserContext: function () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coralogix/browser",
3
- "version": "2.10.0",
3
+ "version": "2.11.1",
4
4
  "description": "Official Coralogix SDK for browsers",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Coralogix",
@@ -3,11 +3,14 @@ export declare class SnapshotManager {
3
3
  private _currentSnapshot;
4
4
  private _fragmentsState;
5
5
  private _isSnapshotSentDueToRecording;
6
+ private _shouldTriggerSnapshotContext;
6
7
  constructor();
7
8
  get fragmentsState(): Set<string>;
8
9
  get currentSnapshot(): SnapshotContext;
9
10
  get isSnapshotSentDueToRecording(): boolean;
11
+ get shouldTriggerSnapshotContext(): boolean;
10
12
  set isSnapshotSentDueToRecording(value: boolean);
13
+ set shouldTriggerSnapshotContext(value: boolean);
11
14
  updateSnapshot: (overrides: Partial<SnapshotContext>) => void;
12
15
  resetSnapshot: () => void;
13
16
  }
package/src/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Attributes } from '@opentelemetry/api';
1
+ import { Attributes, TextMapPropagator } from '@opentelemetry/api';
2
2
  import { CoralogixDomainsApiUrlMap } from './constants';
3
3
  import { CoralogixLogSeverity } from './types-external';
4
4
  import { ErrorSource } from './instrumentations/CoralogixErrorInstrumentation';
@@ -88,6 +88,7 @@ export interface TraceHeaderConfiguration {
88
88
  singleHeader?: boolean;
89
89
  multiHeader?: boolean;
90
90
  };
91
+ propagateCustomTraceHeader?: TextMapPropagator;
91
92
  };
92
93
  }
93
94
  export interface CoralogixOtelWebOptionsInstrumentations {
package/src/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "2.10.0";
1
+ export declare const SDK_VERSION = "2.11.1";