Skip to content

Commit

Permalink
BREAKING CHANGE: add support for boolean and number values in addLabe…
Browse files Browse the repository at this point in the history
…ls (elastic#697)

* BREAKING CHANGE: add support for boolean and number values in addLabels

* address review

* simplify if statement
  • Loading branch information
jahtalab authored and v1v committed Apr 6, 2020
1 parent a985ee5 commit 1770f14
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
14 changes: 6 additions & 8 deletions packages/rum-core/src/common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/rum-core/test/common/config-service.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion packages/rum-core/test/common/utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]'
})
})
Expand Down

0 comments on commit 1770f14

Please sign in to comment.