Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(opentelemetry-exporter-prometheus): export PrometheusSerializer #3034

Merged
merged 5 commits into from
Jun 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
Expand All @@ -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;
}
Expand All @@ -236,7 +236,7 @@ export class PrometheusSerializer {
return `${help}\n${type}\n${results}`.trim();
}

serializeSingularDataPoint(name: string, type: InstrumentType, dataPoint: DataPoint<number>): string {
private _serializeSingularDataPoint(name: string, type: InstrumentType, dataPoint: DataPoint<number>): string {
let results = '';

name = enforcePrometheusNamingConvention(name, type);
Expand All @@ -252,7 +252,7 @@ export class PrometheusSerializer {
return results;
}

serializeHistogramDataPoint(name: string, type: InstrumentType, dataPoint: DataPoint<Histogram>): string {
private _serializeHistogramDataPoint(name: string, type: InstrumentType, dataPoint: DataPoint<Histogram>): string {
let results = '';

name = enforcePrometheusNamingConvention(name, type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
*/

export * from './PrometheusExporter';
export * from './PrometheusSerializer';
export * from './export/types';
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -86,7 +86,7 @@ describe('PrometheusSerializer', () => {
const pointData = metric.dataPoints as DataPoint<number>[];
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;
}

Expand Down Expand Up @@ -129,7 +129,7 @@ describe('PrometheusSerializer', () => {
const pointData = metric.dataPoints as DataPoint<Histogram>[];
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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -284,7 +284,7 @@ describe('PrometheusSerializer', () => {
const pointData = metric.dataPoints as DataPoint<number>[];
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;
}

Expand Down Expand Up @@ -323,7 +323,7 @@ describe('PrometheusSerializer', () => {
const pointData = metric.dataPoints as DataPoint<number>[];
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;
}

Expand Down