diff --git a/docs/reference/configuration.md b/docs/reference/configuration.md index d4f63eba8..d499e2a59 100644 --- a/docs/reference/configuration.md +++ b/docs/reference/configuration.md @@ -368,3 +368,9 @@ If APM Server is deployed in an origin different than the page’s origin, you w :::: +### `recordEmptyTransactions` [record-empty-transactions] + +* **Type:** Boolean +* **Default:** `false` + +If you are interested also for transactions that have no spans you can set this configuration option to true. Bear in mind that sampling rate still applies even if this setting is set to `true`. diff --git a/packages/rum-core/src/common/config-service.js b/packages/rum-core/src/common/config-service.js index a11a52677..f9bae4db1 100644 --- a/packages/rum-core/src/common/config-service.js +++ b/packages/rum-core/src/common/config-service.js @@ -95,7 +95,8 @@ class Config { context: {}, session: false, apmRequest: null, - sendCredentials: false + sendCredentials: false, + recordEmptyTransactions: false } this.events = new EventHandler() diff --git a/packages/rum-core/src/performance-monitoring/performance-monitoring.js b/packages/rum-core/src/performance-monitoring/performance-monitoring.js index fc7fa60ac..226120922 100644 --- a/packages/rum-core/src/performance-monitoring/performance-monitoring.js +++ b/packages/rum-core/src/performance-monitoring/performance-monitoring.js @@ -361,7 +361,8 @@ export default class PerformanceMonitoring { return false } - if (tr.sampled && tr.spans.length === 0) { + const recordEmpty = this._configService.get('recordEmptyTransactions') + if (tr.sampled && tr.spans.length === 0 && !recordEmpty) { if (__DEV__) { this._logginService.debug( `transaction(${tr.id}, ${tr.name}) was discarded! Transaction does not have any spans` diff --git a/packages/rum-core/test/performance-monitoring/performance-monitoring.spec.js b/packages/rum-core/test/performance-monitoring/performance-monitoring.spec.js index 047f4e094..11f92d1c3 100644 --- a/packages/rum-core/test/performance-monitoring/performance-monitoring.spec.js +++ b/packages/rum-core/test/performance-monitoring/performance-monitoring.spec.js @@ -127,6 +127,20 @@ describe('PerformanceMonitoring', function () { ) }) + it('should allow transactions with no spans if enabled by configuration', () => { + spyOn(logger, 'debug').and.callThrough() + configService.setConfig({ ...agentConfig, recordEmptyTransactions: true }) + const transaction1 = new Transaction('transaction', 'custom', { + id: 1, + startTime: 0, + managed: true + }) + transaction1.end(600) + expect(transaction1.duration()).toBe(600) + expect(performanceMonitoring.filterTransaction(transaction1)).toBe(true) + expect(logger.debug).not.toHaveBeenCalled() + }) + it('should initialize and add transaction to the queue', async () => { performanceMonitoring.init() spyOn(apmServer, 'addTransaction')