diff --git a/experimental/CHANGELOG.md b/experimental/CHANGELOG.md index 205dd3123c..b2bb38c924 100644 --- a/experimental/CHANGELOG.md +++ b/experimental/CHANGELOG.md @@ -12,6 +12,7 @@ All notable changes to experimental packages in this project will be documented * feat(opentelemetry-instrumentation-fetch): optionally ignore network events #3028 @gregolsen * feat(http-instrumentation): record exceptions in http instrumentation #3008 @luismiramirez +* feat(opentelemetry-exporter-prometheus): export PrometheusSerializer #3034 @matschaffer ### :bug: (Bug Fix) diff --git a/experimental/packages/opentelemetry-exporter-prometheus/src/PrometheusSerializer.ts b/experimental/packages/opentelemetry-exporter-prometheus/src/PrometheusSerializer.ts index 4608562df3..1b84efe08b 100644 --- a/experimental/packages/opentelemetry-exporter-prometheus/src/PrometheusSerializer.ts +++ b/experimental/packages/opentelemetry-exporter-prometheus/src/PrometheusSerializer.ts @@ -179,20 +179,20 @@ export class PrometheusSerializer { serialize(resourceMetrics: ResourceMetrics): string { let str = ''; for (const scopeMetrics of resourceMetrics.scopeMetrics) { - str += this.serializeScopeMetrics(scopeMetrics); + str += this._serializeScopeMetrics(scopeMetrics); } return str; } - serializeScopeMetrics(scopeMetrics: ScopeMetrics) { + private _serializeScopeMetrics(scopeMetrics: ScopeMetrics) { let str = ''; for (const metric of scopeMetrics.metrics) { - str += this.serializeMetricData(metric) + '\n'; + str += this._serializeMetricData(metric) + '\n'; } return str; } - serializeMetricData(metricData: MetricData) { + private _serializeMetricData(metricData: MetricData) { let name = sanitizePrometheusMetricName( escapeString(metricData.descriptor.name) ); @@ -218,13 +218,13 @@ export class PrometheusSerializer { switch (dataPointType) { case DataPointType.SINGULAR: { results = metricData.dataPoints - .map(it => this.serializeSingularDataPoint(name, metricData.descriptor.type, it)) + .map(it => this._serializeSingularDataPoint(name, metricData.descriptor.type, it)) .join(''); break; } case DataPointType.HISTOGRAM: { results = metricData.dataPoints - .map(it => this.serializeHistogramDataPoint(name, metricData.descriptor.type, it)) + .map(it => this._serializeHistogramDataPoint(name, metricData.descriptor.type, it)) .join(''); break; } @@ -236,7 +236,7 @@ export class PrometheusSerializer { return `${help}\n${type}\n${results}`.trim(); } - serializeSingularDataPoint(name: string, type: InstrumentType, dataPoint: DataPoint): string { + private _serializeSingularDataPoint(name: string, type: InstrumentType, dataPoint: DataPoint): string { let results = ''; name = enforcePrometheusNamingConvention(name, type); @@ -252,7 +252,7 @@ export class PrometheusSerializer { return results; } - serializeHistogramDataPoint(name: string, type: InstrumentType, dataPoint: DataPoint): string { + private _serializeHistogramDataPoint(name: string, type: InstrumentType, dataPoint: DataPoint): string { let results = ''; name = enforcePrometheusNamingConvention(name, type); diff --git a/experimental/packages/opentelemetry-exporter-prometheus/src/index.ts b/experimental/packages/opentelemetry-exporter-prometheus/src/index.ts index bcf661b337..20041cda13 100644 --- a/experimental/packages/opentelemetry-exporter-prometheus/src/index.ts +++ b/experimental/packages/opentelemetry-exporter-prometheus/src/index.ts @@ -15,4 +15,5 @@ */ export * from './PrometheusExporter'; +export * from './PrometheusSerializer'; export * from './export/types'; diff --git a/experimental/packages/opentelemetry-exporter-prometheus/test/PrometheusSerializer.test.ts b/experimental/packages/opentelemetry-exporter-prometheus/test/PrometheusSerializer.test.ts index 5f8656cbe5..f0dc004e25 100644 --- a/experimental/packages/opentelemetry-exporter-prometheus/test/PrometheusSerializer.test.ts +++ b/experimental/packages/opentelemetry-exporter-prometheus/test/PrometheusSerializer.test.ts @@ -27,7 +27,7 @@ import { Histogram, } from '@opentelemetry/sdk-metrics-base'; import * as sinon from 'sinon'; -import { PrometheusSerializer } from '../src/PrometheusSerializer'; +import { PrometheusSerializer } from '../src'; import { mockedHrTimeMs, mockHrTime } from './util'; const attributes = { @@ -86,7 +86,7 @@ describe('PrometheusSerializer', () => { const pointData = metric.dataPoints as DataPoint[]; assert.strictEqual(pointData.length, 1); - const result = serializer.serializeSingularDataPoint(metric.descriptor.name, metric.descriptor.type, pointData[0]); + const result = serializer['_serializeSingularDataPoint'](metric.descriptor.name, metric.descriptor.type, pointData[0]); return result; } @@ -129,7 +129,7 @@ describe('PrometheusSerializer', () => { const pointData = metric.dataPoints as DataPoint[]; assert.strictEqual(pointData.length, 1); - const result = serializer.serializeHistogramDataPoint(metric.descriptor.name, metric.descriptor.type, pointData[0]); + const result = serializer['_serializeHistogramDataPoint'](metric.descriptor.name, metric.descriptor.type, pointData[0]); return result; } @@ -184,7 +184,7 @@ describe('PrometheusSerializer', () => { assert.strictEqual(resourceMetrics.scopeMetrics[0].metrics.length, 1); const scopeMetrics = resourceMetrics.scopeMetrics[0]; - const result = serializer.serializeScopeMetrics(scopeMetrics); + const result = serializer['_serializeScopeMetrics'](scopeMetrics); return result; } @@ -236,7 +236,7 @@ describe('PrometheusSerializer', () => { assert.strictEqual(resourceMetrics.scopeMetrics[0].metrics.length, 1); const scopeMetrics = resourceMetrics.scopeMetrics[0]; - const result = serializer.serializeScopeMetrics(scopeMetrics); + const result = serializer['_serializeScopeMetrics'](scopeMetrics); return result; } @@ -284,7 +284,7 @@ describe('PrometheusSerializer', () => { const pointData = metric.dataPoints as DataPoint[]; assert.strictEqual(pointData.length, 1); - const result = serializer.serializeSingularDataPoint(metric.descriptor.name, metric.descriptor.type, pointData[0]); + const result = serializer['_serializeSingularDataPoint'](metric.descriptor.name, metric.descriptor.type, pointData[0]); return result; } @@ -323,7 +323,7 @@ describe('PrometheusSerializer', () => { const pointData = metric.dataPoints as DataPoint[]; assert.strictEqual(pointData.length, 1); - const result = serializer.serializeSingularDataPoint(metric.descriptor.name, metric.descriptor.type, pointData[0]); + const result = serializer['_serializeSingularDataPoint'](metric.descriptor.name, metric.descriptor.type, pointData[0]); return result; }