fix: only send strings (#18778)

pull/18789/head
Alex Boatwright 2020-06-29 11:00:15 -07:00 committed by GitHub
parent 9279ace825
commit 11473b905b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 30 additions and 6 deletions

View File

@ -31,6 +31,28 @@ export const updateReportingContext = (properties: KeyValue) => {
reportingTags = {...reportingTags, ...properties}
}
// NOTE: typescript can't follow the API results for flags,
// so we need to convert them to strings here
const cleanTags = (data: Point): Point => {
return {
...data,
tags: Object.entries(data.tags).reduce((acc, [key, val]) => {
if (typeof val === 'boolean') {
acc[key] = val ? 'true' : 'false'
return acc
}
if (!isNaN(parseFloat(val))) {
acc[key] = '' + val
return acc
}
acc[key] = val
return acc
}, {}),
}
}
export const reportEvent = ({
timestamp = toNano(Date.now()),
measurement,
@ -43,12 +65,14 @@ export const reportEvent = ({
fireEvent(measurement, {...reportingTags, ...tags})
reportingPoints.push({
measurement,
tags: {...reportingTags, ...tags},
fields,
timestamp,
})
reportingPoints.push(
cleanTags({
measurement,
tags: {...reportingTags, ...tags},
fields,
timestamp,
})
)
if (!!reportDecayTimeout) {
clearTimeout(reportDecayTimeout)