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, + }, ]); }); }); }); +