From 9b5c3261a1f70b34735daabba88e43cf57ad3633 Mon Sep 17 00:00:00 2001 From: Mayur Kale Date: Fri, 8 Nov 2019 14:37:13 -0800 Subject: [PATCH] fix: review comments --- .../src/export/ConsoleMetricExporter.ts | 12 +++++++++++- .../test/export/ConsoleMetricExporter.test.ts | 12 +++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/packages/opentelemetry-metrics/src/export/ConsoleMetricExporter.ts b/packages/opentelemetry-metrics/src/export/ConsoleMetricExporter.ts index 7553aa9d325..5702d7258b7 100644 --- a/packages/opentelemetry-metrics/src/export/ConsoleMetricExporter.ts +++ b/packages/opentelemetry-metrics/src/export/ConsoleMetricExporter.ts @@ -33,9 +33,19 @@ export class ConsoleMetricExporter implements MetricExporter { name: descriptor.name, description: descriptor.description, }); + for (const ts of timeseries) { + const labels = descriptor.labelKeys + .map((k, i) => [k, ts.labelValues[i]]) + .reduce( + (p, c) => ({ + ...p, + [c[0] as string]: typeof c[1] === 'string' ? c[1] : c[1].value, + }), + {} + ); for (const point of ts.points) { - console.log({ labels: ts.labelValues, value: point.value }); + console.log({ labels, value: point.value }); } } } diff --git a/packages/opentelemetry-metrics/test/export/ConsoleMetricExporter.test.ts b/packages/opentelemetry-metrics/test/export/ConsoleMetricExporter.test.ts index b56409eed0f..acd2a93d53b 100644 --- a/packages/opentelemetry-metrics/test/export/ConsoleMetricExporter.test.ts +++ b/packages/opentelemetry-metrics/test/export/ConsoleMetricExporter.test.ts @@ -40,17 +40,23 @@ describe('ConsoleMetricExporter', () => { meter.addExporter(consoleExporter); const gauge = meter.createGauge('gauge', { description: 'a test description', - labelKeys: ['key1'], + labelKeys: ['key1', 'key2'], }) as GaugeMetric; - const handle = gauge.getHandle(['labelValue1']); + const handle = gauge.getHandle( + meter.labels({ key1: 'labelValue1', key2: 'labelValue2' }) + ); handle.set(10); const [descriptor, timeseries] = spyConsole.args; assert.deepStrictEqual(descriptor, [ { description: 'a test description', name: 'gauge' }, ]); assert.deepStrictEqual(timeseries, [ - { labels: [{ value: 'labelValue1' }], value: 10 }, + { + labels: { key1: 'labelValue1', key2: 'labelValue2' }, + value: 10, + }, ]); }); }); }); +