@coralogix/browser 3.7.1 → 3.8.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 3.8.0 (2026-04-27)
2
+
3
+ ### 🚀 Features
4
+
5
+ - Add support for excluding specific instrumentations from session sampling
6
+
1
7
  ## 3.7.1 (2026-04-26)
2
8
 
3
9
  ### 🩹 Fixes
package/README.md CHANGED
@@ -9,7 +9,8 @@
9
9
 
10
10
  - [Basic Sampling](#1-basic-sampling---sample--of-all-sessions)
11
11
  - [Advanced Sampling](#2-advanced-sampling---sample--of-sessions-but-always-track-sessions-with-errors)
12
- - [Only Sessions with Errors](#3-only-sessions-with-errors)
12
+ - [Exclude Specific Instrumentations from Sampling](#3-exclude-specific-instrumentations-from-sampling)
13
+ - [Only Sessions with Errors](#4-only-sessions-with-errors)
13
14
 
14
15
  6. [Sending Custom Logs](#sending-custom-logs)
15
16
  7. [Instrumentations](#instrumentations)
@@ -162,7 +163,21 @@ CoralogixRum.init({
162
163
  });
163
164
  ```
164
165
 
165
- #### 3. Only Sessions with Errors
166
+ #### 3. Exclude Specific Instrumentations from Sampling
167
+
168
+ Keep specific instrumentations running at 100% even when sessions are sampled out. This is useful when you want to reduce data volume with sampling but still capture all errors or custom logs.
169
+
170
+ ```javascript
171
+ CoralogixRum.init({
172
+ // ...
173
+ sessionConfig: {
174
+ sessionSampleRate: 20, // Only 20% of sessions are fully tracked
175
+ excludeFromSampling: ['custom'], // These will run at 100% regardless of sampling
176
+ },
177
+ });
178
+ ```
179
+
180
+ #### 4. Only Sessions with Errors
166
181
 
167
182
  Track only sessions with errors, and send specific instrumentation data immediately even if error is not occurred.
168
183
  From Session recording perspective, the SDK will record approximately 10–60s(according to maxRecordTime property) before the error occurred.
package/index.esm2.js CHANGED
@@ -220,6 +220,7 @@ var DEFAULT_SESSION_CONFIG = {
220
220
  onlyWithErrorConfig: {
221
221
  enable: false,
222
222
  },
223
+ excludeFromSampling: [],
223
224
  };
224
225
  var SESSION_IDLE_TIME = 15 * millisecondsPerMinute;
225
226
  var SESSION_EXPIRATION_TIME = MILLISECONDS_PER_HOUR;
@@ -3390,13 +3391,19 @@ var Request = (function () {
3390
3391
  return Request;
3391
3392
  }());
3392
3393
 
3394
+ var PROPAGATE_ONLY = { decision: SamplingDecision.RECORD };
3395
+ var EXPORT = { decision: SamplingDecision.RECORD_AND_SAMPLED };
3393
3396
  var CxCustomSampler = (function () {
3394
3397
  function CxCustomSampler() {
3395
3398
  }
3396
- CxCustomSampler.prototype.shouldSample = function () {
3397
- return {
3398
- decision: SamplingDecision.RECORD,
3399
- };
3399
+ CxCustomSampler.prototype.shouldSample = function (_context, _traceId, _spanName, _spanKind, attributes) {
3400
+ var _a, _b;
3401
+ var excluded = (_b = (_a = getSdkConfig().sessionConfig) === null || _a === void 0 ? void 0 : _a.excludeFromSampling) !== null && _b !== void 0 ? _b : [];
3402
+ var isHttpSpan = Boolean(attributes['http.method']);
3403
+ if (isHttpSpan) {
3404
+ return excluded.includes('fetch') || excluded.includes('xhr') ? EXPORT : PROPAGATE_ONLY;
3405
+ }
3406
+ return excluded.length > 0 ? EXPORT : PROPAGATE_ONLY;
3400
3407
  };
3401
3408
  return CxCustomSampler;
3402
3409
  }());
@@ -3446,28 +3453,61 @@ var isSessionWithError = function () {
3446
3453
  var _a = getSessionManager(), onlySessionWithErrorMode = _a.onlySessionWithErrorMode, cachedLogsSent = _a.cachedLogsSent;
3447
3454
  return onlySessionWithErrorMode && !cachedLogsSent;
3448
3455
  };
3449
- function getResolvedSampler(resolvedOptions) {
3450
- var sampler = new AlwaysOnSampler();
3451
- var sessionSampleRate = resolvedOptions.sessionSampleRate, sessionConfig = resolvedOptions.sessionConfig, debug = resolvedOptions.debug, sessionRecordingConfig = resolvedOptions.sessionRecordingConfig;
3456
+ function getResolvedSampler() {
3457
+ var config = getSdkConfig();
3458
+ var sessionSampleRate = config.sessionSampleRate, sessionConfig = config.sessionConfig;
3452
3459
  var shouldNotTrackSession = !isSamplingOn(sessionSampleRate) ||
3453
3460
  !isSamplingOn(sessionConfig.sessionSampleRate);
3454
3461
  if (shouldNotTrackSession) {
3455
- var shouldAlwaysTrackSessionsWithErrors = sessionConfig === null || sessionConfig === void 0 ? void 0 : sessionConfig.alwaysTrackSessionsWithErrors;
3456
- if (shouldAlwaysTrackSessionsWithErrors) {
3457
- sessionConfig.onlyWithErrorConfig = __assign(__assign({}, sessionConfig.onlyWithErrorConfig), { enable: true });
3462
+ if (sessionConfig === null || sessionConfig === void 0 ? void 0 : sessionConfig.alwaysTrackSessionsWithErrors) {
3463
+ return enableErrorOnlyMode();
3458
3464
  }
3459
- else {
3460
- if (debug) {
3461
- console.debug('CoralogixRum: Session tracking is disabled due to sampling rate');
3462
- }
3463
- sampler = new CxCustomSampler();
3464
- if (sessionRecordingConfig) {
3465
- sessionRecordingConfig.enable = false;
3466
- }
3467
- resolvedOptions.instrumentations = __assign(__assign({}, resolvedOptions.instrumentations), { errors: false, custom: false, web_vitals: false, interactions: false, long_tasks: false, resources: false });
3465
+ return handleDroppedSession();
3466
+ }
3467
+ return new AlwaysOnSampler();
3468
+ }
3469
+ function enableErrorOnlyMode() {
3470
+ var sessionConfig = getSdkConfig().sessionConfig;
3471
+ if (sessionConfig) {
3472
+ sessionConfig.onlyWithErrorConfig = __assign(__assign({}, sessionConfig.onlyWithErrorConfig), { enable: true });
3473
+ }
3474
+ return new AlwaysOnSampler();
3475
+ }
3476
+ function handleDroppedSession() {
3477
+ var e_1, _a;
3478
+ var _b, _c;
3479
+ var config = getSdkConfig();
3480
+ var sessionRecordingConfig = config.sessionRecordingConfig, sessionConfig = config.sessionConfig, debug = config.debug;
3481
+ if (debug) {
3482
+ console.log('CoralogixRum: Session tracking is disabled due to sampling rate');
3483
+ }
3484
+ if (sessionRecordingConfig) {
3485
+ sessionRecordingConfig.enable = false;
3486
+ }
3487
+ var excluded = (_b = sessionConfig === null || sessionConfig === void 0 ? void 0 : sessionConfig.excludeFromSampling) !== null && _b !== void 0 ? _b : [];
3488
+ var nonHttpInstrumentations = [
3489
+ 'errors',
3490
+ 'custom',
3491
+ 'web_vitals',
3492
+ 'interactions',
3493
+ 'long_tasks',
3494
+ 'resources',
3495
+ ];
3496
+ (_c = config.instrumentations) !== null && _c !== void 0 ? _c : (config.instrumentations = {});
3497
+ try {
3498
+ for (var nonHttpInstrumentations_1 = __values$1(nonHttpInstrumentations), nonHttpInstrumentations_1_1 = nonHttpInstrumentations_1.next(); !nonHttpInstrumentations_1_1.done; nonHttpInstrumentations_1_1 = nonHttpInstrumentations_1.next()) {
3499
+ var key = nonHttpInstrumentations_1_1.value;
3500
+ config.instrumentations[key] = excluded.includes(key);
3501
+ }
3502
+ }
3503
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
3504
+ finally {
3505
+ try {
3506
+ if (nonHttpInstrumentations_1_1 && !nonHttpInstrumentations_1_1.done && (_a = nonHttpInstrumentations_1.return)) _a.call(nonHttpInstrumentations_1);
3468
3507
  }
3508
+ finally { if (e_1) throw e_1.error; }
3469
3509
  }
3470
- return sampler;
3510
+ return new CxCustomSampler();
3471
3511
  }
3472
3512
 
3473
3513
  function isProcessorShouldStop(isActive) {
@@ -4230,7 +4270,7 @@ function resolveUrlBlueprinters(urlBlueprinters) {
4230
4270
  return resolvedUrlBlueprinters;
4231
4271
  }
4232
4272
 
4233
- var SDK_VERSION = '3.7.1';
4273
+ var SDK_VERSION = '3.8.0';
4234
4274
 
4235
4275
  function shouldDropEvent(cxRumEvent, options) {
4236
4276
  if (isDocumentErrorWithoutMessage(cxRumEvent)) {
@@ -4846,7 +4886,7 @@ var CoralogixRum = {
4846
4886
  }
4847
4887
  CxGlobal[USER_AGENT_KEY] = parseUserAgent(navigator.userAgent);
4848
4888
  CxGlobal[SDK_CONFIG_KEY] = resolvedOptions_1;
4849
- var sampler = getResolvedSampler(resolvedOptions_1);
4889
+ var sampler = getResolvedSampler();
4850
4890
  if (!resolvedOptions_1.debug && !resolvedOptions_1.public_key) {
4851
4891
  console.warn('rumAuth will be required in the future');
4852
4892
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coralogix/browser",
3
- "version": "3.7.1",
3
+ "version": "3.8.0",
4
4
  "description": "Official Coralogix SDK for browsers",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Coralogix",
package/src/index.d.ts CHANGED
@@ -3,3 +3,4 @@ export { CoralogixLogSeverity } from './types-external';
3
3
  export { UrlBasedLabelProvider } from './label-providers/url-based-label-provider';
4
4
  export * from './types';
5
5
  export { SessionRecordingEventType, type RecordEvent, type RecordPluginEvent, } from './session/session.model';
6
+ export type { ExcludableInstrumentation } from './session/session.consts';
@@ -1,4 +1,5 @@
1
+ import { Attributes } from '@opentelemetry/api';
1
2
  import { Sampler, SamplingResult } from '@opentelemetry/sdk-trace-base';
2
3
  export declare class CxCustomSampler implements Sampler {
3
- shouldSample(): SamplingResult;
4
+ shouldSample(_context: unknown, _traceId: string, _spanName: string, _spanKind: unknown, attributes: Attributes): SamplingResult;
4
5
  }
@@ -1,4 +1,5 @@
1
1
  import { SessionConfig } from './session.model';
2
+ import { CoralogixOtelWebOptionsInstrumentations } from '../types';
2
3
  export declare const MAX_BATCH_TIME_MS: number;
3
4
  export declare const SESSION_RECORDING_DEFAULT_HEADERS: Record<string, string>;
4
5
  export declare const SESSION_RECORDING_DEFAULT_ERROR_MESSAGE: string;
@@ -9,6 +10,7 @@ export declare const SESSION_KEY: string;
9
10
  export declare const PREV_SESSION_KEY: string;
10
11
  export declare const MUTATION_LIMIT: number;
11
12
  export declare const DEFAULT_SESSION_CONFIG: SessionConfig;
13
+ export type ExcludableInstrumentation = keyof CoralogixOtelWebOptionsInstrumentations;
12
14
  export declare const SESSION_IDLE_TIME: number;
13
15
  export declare const SESSION_EXPIRATION_TIME: number;
14
16
  export declare const SESSION_MANAGER_KEY = "rumSessionManager";
@@ -1,8 +1,7 @@
1
1
  import { SessionConfig, SessionRecordingConfig } from './session.model';
2
- import { CoralogixBrowserSdkConfig } from '../types';
3
2
  import { AlwaysOnSampler, Sampler } from '@opentelemetry/sdk-trace-base';
4
3
  export declare function resolveSessionConfig(config: SessionConfig | undefined): SessionConfig;
5
4
  export declare function resolveSessionRecordingConfig(config: SessionRecordingConfig | undefined): SessionRecordingConfig | undefined;
6
5
  export declare function isSamplingOn(threshold: number): boolean;
7
6
  export declare const isSessionWithError: () => boolean;
8
- export declare function getResolvedSampler(resolvedOptions: CoralogixBrowserSdkConfig): AlwaysOnSampler | Sampler;
7
+ export declare function getResolvedSampler(): AlwaysOnSampler | Sampler;
@@ -2,6 +2,7 @@ import { eventWithTime } from '../cx-rrweb/rrweb-types';
2
2
  import { SlimDOMOptions } from '../cx-rrweb/rrweb-snapshot';
3
3
  import { CoralogixEventType } from '../types';
4
4
  import { recordOptions } from '../cx-rrweb/rrweb';
5
+ import type { ExcludableInstrumentation } from './session.consts';
5
6
  export interface SessionRecordingConfig extends Omit<recordOptions<eventWithTime>, 'emit' | 'packFn' | 'plugins' | 'hooks' | 'slimDOMOptions'> {
6
7
  enable: boolean;
7
8
  autoStartSessionRecording: boolean;
@@ -23,6 +24,7 @@ export interface SessionConfig {
23
24
  alwaysTrackSessionsWithErrors?: boolean;
24
25
  onlyWithErrorConfig?: SessionWithErrorConfig;
25
26
  keepSessionAfterReload?: boolean;
27
+ excludeFromSampling?: ExcludableInstrumentation[];
26
28
  }
27
29
  export type RecordEvent = eventWithTime;
28
30
  export type RecordPluginEvent<T = any> = {
package/src/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "3.7.1";
1
+ export declare const SDK_VERSION = "3.8.0";