Skip to content
Open
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 @@ For notes on migrating to 2.x / 0.200.x see [the upgrade guide](doc/upgrade-to-2

* feat(otlp-transformer): replace protobufjs trace serialization with custom implementation [#6625](https://github.com/open-telemetry/opentelemetry-js/pull/6625) @pichlermarc
* feat(configuration): auto-generate TypeScript types from OTel declarative config JSON schema (stable v1.0.0) using `json-schema-to-typescript` and `ajv` [#6533](https://github.com/open-telemetry/opentelemetry-js/pull/6533) @MikeGoldsmith
* feat(opentelemetry-exporter-prometheus): add translation strategy support [#6653](https://github.com/open-telemetry/opentelemetry-js/pull/6653) @cjihrig

### :bug: Bug Fixes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
import type { IncomingMessage, Server, ServerResponse } from 'http';
import { createServer } from 'http';
import type { ExporterConfig } from './export/types';
import { TranslationStrategy } from './export/types';
import type { TranslationStrategyOptions } from './PrometheusSerializer';
import { PrometheusSerializer } from './PrometheusSerializer';
/** Node.js v8.x compat */
import { URL } from 'url';
Expand All @@ -24,6 +26,7 @@ export class PrometheusExporter extends MetricReader {
endpoint: '/metrics',
prefix: '',
appendTimestamp: false,
translationStrategy: TranslationStrategy.UnderscoreEscapingWithSuffixes,
withResourceConstantLabels: undefined,
withoutScopeInfo: false,
withoutTargetInfo: false,
Expand All @@ -36,6 +39,7 @@ export class PrometheusExporter extends MetricReader {
private readonly _server: Server;
private readonly _prefix?: string;
private readonly _appendTimestamp: boolean;
private readonly _translationStrategy: TranslationStrategyOptions;
private _serializer: PrometheusSerializer;
private _startServerPromise: Promise<void> | undefined;

Expand Down Expand Up @@ -84,6 +88,22 @@ export class PrometheusExporter extends MetricReader {
const _withoutTargetInfo =
config.withoutTargetInfo ||
PrometheusExporter.DEFAULT_OPTIONS.withoutTargetInfo;
const _translationStrategy =
config.translationStrategy ||
PrometheusExporter.DEFAULT_OPTIONS.translationStrategy;

this._translationStrategy = {
escape:
_translationStrategy ===
TranslationStrategy.UnderscoreEscapingWithSuffixes ||
_translationStrategy ===
TranslationStrategy.UnderscoreEscapingWithoutSuffixes,
suffixes:
_translationStrategy ===
TranslationStrategy.UnderscoreEscapingWithSuffixes ||
_translationStrategy === TranslationStrategy.NoUTF8EscapingWithSuffixes,
};

// unref to prevent prometheus exporter from holding the process open on exit
this._server = createServer(this._requestHandler).unref();
this._serializer = new PrometheusSerializer(
Expand Down Expand Up @@ -220,7 +240,12 @@ export class PrometheusExporter extends MetricReader {
...errors
);
}
response.end(this._serializer.serialize(resourceMetrics));
// Translation strategy options are passed to the serlialize() method
// because in the future, these options may also be influenced by the
// content negotiation process of the incoming request.
response.end(
this._serializer.serialize(resourceMetrics, this._translationStrategy)
);
},
err => {
response.end(`# failed to export metrics: ${err}`);
Expand Down
Loading
Loading