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

refactor(exporter-prometheus): promisify prometheus tests #4431

Merged
merged 4 commits into from
Jan 25, 2024
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
8 changes: 4 additions & 4 deletions doc/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const {
getNodeAutoInstrumentations,
} = require("@opentelemetry/auto-instrumentations-node");

const prometheusExporter = new PrometheusExporter({ startServer: true });
const prometheusExporter = new PrometheusExporter();

const sdk = new opentelemetry.NodeSDK({
// Optional - If omitted, the metrics SDK will not be initialized
Expand Down Expand Up @@ -147,7 +147,7 @@ const {
getNodeAutoInstrumentations,
} = require("@opentelemetry/auto-instrumentations-node");

const prometheusExporter = new PrometheusExporter({ startServer: true });
const prometheusExporter = new PrometheusExporter();

const sdk = new opentelemetry.NodeSDK({
// Optional - If omitted, the metrics SDK will not be initialized
Expand Down Expand Up @@ -499,8 +499,8 @@ to use the Prometheus exporter `PrometheusExporter` which is included in the
const { PrometheusExporter } = require('@opentelemetry/exporter-prometheus');
const { MeterProvider } = require('@opentelemetry/sdk-metrics');

// Add your port and startServer to the Prometheus options
const options = { port: 9464, startServer: true };
// Add your port to the Prometheus options
const options = { port: 9464 };
const exporter = new PrometheusExporter(options);

// Creates MeterProvider and installs the exporter as a MetricReader
Expand Down
3 changes: 3 additions & 0 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ All notable changes to experimental packages in this project will be documented

### :bug: (Bug Fix)

* fix(exporter-prometheus): avoid invoking callback synchronously [#4431](https://github.com/open-telemetry/opentelemetry-js/pull/4431) @legendecas
* fix(exporter-logs-otlp-grpc): set User-Agent header [#4398](https://github.com/open-telemetry/opentelemetry-js/pull/4398) @Vunovati
* fix(exporter-logs-otlp-http): set User-Agent header [#4398](https://github.com/open-telemetry/opentelemetry-js/pull/4398) @Vunovati
* fix(exporter-logs-otlp-proto): set User-Agent header [#4398](https://github.com/open-telemetry/opentelemetry-js/pull/4398) @Vunovati
Expand All @@ -24,6 +25,8 @@ All notable changes to experimental packages in this project will be documented

### :house: (Internal)

* refactor(exporter-prometheus): promisify prometheus tests [#4431](https://github.com/open-telemetry/opentelemetry-js/pull/4431) @legendecas

## 0.47.0

### :boom: Breaking Change
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export class PrometheusExporter extends MetricReader {
private readonly _prefix?: string;
private readonly _appendTimestamp: boolean;
private _serializer: PrometheusSerializer;
private _startServerPromise: Promise<void> | undefined;

// This will be required when histogram is implemented. Leaving here so it is not forgotten
// Histogram cannot have a attribute named 'le'
Expand Down Expand Up @@ -95,7 +96,8 @@ export class PrometheusExporter extends MetricReader {
callback(err);
});
} else if (callback) {
callback();
// Do not invoke callback immediately to avoid zalgo problem.
queueMicrotask(callback);
}
}

Expand Down Expand Up @@ -142,7 +144,7 @@ export class PrometheusExporter extends MetricReader {
* Starts the Prometheus export server
*/
startServer(): Promise<void> {
return new Promise((resolve, reject) => {
this._startServerPromise ??= new Promise((resolve, reject) => {
this._server.once('error', reject);
this._server.listen(
{
Expand All @@ -157,6 +159,8 @@ export class PrometheusExporter extends MetricReader {
}
);
});

return this._startServerPromise;
}

/**
Expand Down
Loading