From d28a1e4dd02df8b9ccb55c1505d1297dee8d6bae Mon Sep 17 00:00:00 2001 From: Kudlaty Date: Wed, 17 Feb 2021 15:17:37 +0100 Subject: [PATCH 1/3] fix(exporter-collector): proper data types for int and double --- .../opentelemetry-exporter-collector/src/transform.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/opentelemetry-exporter-collector/src/transform.ts b/packages/opentelemetry-exporter-collector/src/transform.ts index bdaaaa2290a..7080713ff77 100644 --- a/packages/opentelemetry-exporter-collector/src/transform.ts +++ b/packages/opentelemetry-exporter-collector/src/transform.ts @@ -32,6 +32,9 @@ import { CollectorExporterConfigBase, } from './types'; +const MAX_INTEGER_VALUE = 2147483647; +const MIN_INTEGER_VALUE = -2147483648; + /** * Converts attributes to KeyValue array * @param attributes @@ -95,8 +98,14 @@ export function toCollectorAnyValue( anyValue.stringValue = value; } else if (typeof value === 'boolean') { anyValue.boolValue = value; + } else if ( + typeof value === 'number' && + value <= MAX_INTEGER_VALUE && + value >= MIN_INTEGER_VALUE && + Number.isInteger(value) + ) { + anyValue.intValue = value; } else if (typeof value === 'number') { - // all numbers will be treated as double anyValue.doubleValue = value; } else if (Array.isArray(value)) { anyValue.arrayValue = toCollectorArrayValue(value); From d7ec0b1c899f393155f7821d41822cc2852a64ac Mon Sep 17 00:00:00 2001 From: Kudlaty Date: Wed, 17 Feb 2021 15:44:03 +0100 Subject: [PATCH 2/3] test(exporter-collector): add test for converting number to int and double --- .../test/common/transform.test.ts | 15 ++++++++++++--- .../test/helper.ts | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/opentelemetry-exporter-collector/test/common/transform.test.ts b/packages/opentelemetry-exporter-collector/test/common/transform.test.ts index 3bcb5e8acec..f212a7774a4 100644 --- a/packages/opentelemetry-exporter-collector/test/common/transform.test.ts +++ b/packages/opentelemetry-exporter-collector/test/common/transform.test.ts @@ -37,12 +37,21 @@ describe('transform', () => { ]); }); - it('should convert attribute integer', () => { + it('should convert attribute integer to integer', () => { const attributes: SpanAttributes = { foo: 13, }; assert.deepStrictEqual(transform.toCollectorAttributes(attributes), [ - { key: 'foo', value: { doubleValue: 13 } }, + { key: 'foo', value: { intValue: 13 } }, + ]); + }); + + it('should convert attribute integer to double', () => { + const attributes: SpanAttributes = { + foo: 2247483647, + }; + assert.deepStrictEqual(transform.toCollectorAttributes(attributes), [ + { key: 'foo', value: { doubleValue: 2247483647 } }, ]); }); @@ -118,7 +127,7 @@ describe('transform', () => { }, { key: 'version', - value: { doubleValue: 1 }, + value: { intValue: 1 }, }, { key: 'success', value: { boolValue: true } }, ], diff --git a/packages/opentelemetry-exporter-collector/test/helper.ts b/packages/opentelemetry-exporter-collector/test/helper.ts index 710e1d99d56..b38785daab9 100644 --- a/packages/opentelemetry-exporter-collector/test/helper.ts +++ b/packages/opentelemetry-exporter-collector/test/helper.ts @@ -540,7 +540,7 @@ export function ensureWebResourceIsCorrect( { key: 'version', value: { - doubleValue: 1, + intValue: 1, }, }, { From 28dcf39cc7721f6880994271eed4dcba54c86c16 Mon Sep 17 00:00:00 2001 From: Kudlaty Date: Wed, 17 Feb 2021 17:26:46 +0100 Subject: [PATCH 3/3] test(exporter-collector-grpc): fix tests after changes in transform in exporter-collector --- packages/opentelemetry-exporter-collector-grpc/test/helper.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/opentelemetry-exporter-collector-grpc/test/helper.ts b/packages/opentelemetry-exporter-collector-grpc/test/helper.ts index 049697892a4..607a8ad7292 100644 --- a/packages/opentelemetry-exporter-collector-grpc/test/helper.ts +++ b/packages/opentelemetry-exporter-collector-grpc/test/helper.ts @@ -422,8 +422,8 @@ export function ensureResourceIsCorrect( { key: 'version', value: { - doubleValue: 1, - value: 'doubleValue', + intValue: '1', + value: 'intValue', }, }, {