diff --git a/packages/rum-core/src/common/utils.js b/packages/rum-core/src/common/utils.js index 6f53397bc..03120a339 100644 --- a/packages/rum-core/src/common/utils.js +++ b/packages/rum-core/src/common/utils.js @@ -134,17 +134,15 @@ function isPlatformSupported() { } /** - * Convert values of the Tag/Label to be string to be compatible - * with the apm server prior to <6.7 version - * - * TODO: Remove string conversion in the next major release since - * support for boolean and number in the APM server has landed in 6.7 - * https://github.com/elastic/apm-server/pull/1712/ + * Support for boolean and number in the APM server landed in 6.7 + * therefore, we keep these values unchange but convert any other + * type to string. */ function setLabel(key, value, obj) { if (!obj || !key) return - var skey = removeInvalidChars(key) - if (value) { + const skey = removeInvalidChars(key) + let valueType = typeof value + if (value != undefined && valueType !== 'boolean' && valueType !== 'number') { value = String(value) } obj[skey] = value diff --git a/packages/rum-core/test/common/config-service.spec.js b/packages/rum-core/test/common/config-service.spec.js index d0fd5d2c2..591dce43f 100644 --- a/packages/rum-core/test/common/config-service.spec.js +++ b/packages/rum-core/test/common/config-service.spec.js @@ -223,7 +223,7 @@ describe('ConfigService', function() { const contextLabels = configService.get('context.tags') expect(contextLabels).toEqual({ test: 'test', - no: '1', + no: 1, test_test: 'test', obj: '[object Object]', date: String(date) diff --git a/packages/rum-core/test/common/utils.spec.js b/packages/rum-core/test/common/utils.spec.js index 128a6f9f3..1cb587fdf 100644 --- a/packages/rum-core/test/common/utils.spec.js +++ b/packages/rum-core/test/common/utils.spec.js @@ -222,17 +222,23 @@ describe('lib/utils', function() { utils.setLabel(undefined, 'value', labels) utils.setLabel('test', 'test', labels) utils.setLabel('no', 1, labels) + utils.setLabel('bool_false', false, labels) + utils.setLabel('bool_true', true, labels) utils.setLabel('test.test', 'passed', labels) utils.setLabel('date', date, labels) utils.setLabel() utils.setLabel('removed', undefined, labels) + utils.setLabel('removed_null', null, labels) utils.setLabel('obj', {}, labels) expect(labels).toEqual({ test: 'test', - no: '1', + no: 1, + bool_false: false, + bool_true: true, test_test: 'passed', date: String(date), removed: undefined, + removed_null: null, obj: '[object Object]' }) })