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 @@ -11,6 +11,7 @@ For notes on migrating to 2.x / 0.200.x see [the upgrade guide](doc/upgrade-to-2
* feat(sdk-logs)!: add required `forceFlush()` to `LogRecordExporter` interface [#6356](https://github.com/open-telemetry/opentelemetry-js/pull/6356) @pichlermarc
* (user-facing): `LogRecordExporter` interface now requires a `forceFlush()` method to be implemented. Custom exporters will need to implement this method to continue working with the Logs SDK.
* feat(api-logs, sdk-logs)!: add Logger#enabled() [#6371](https://github.com/open-telemetry/opentelemetry-js/pull/6371) @david-luna
* fix(opentelemetry-exporter-prometheus)!: default exporter host to localhost [#6599](https://github.com/open-telemetry/opentelemetry-js/pull/6599) @cjihrig

### :rocket: Features

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { URL } from 'url';

export class PrometheusExporter extends MetricReader {
static readonly DEFAULT_OPTIONS = {
host: undefined,
host: 'localhost',
port: 9464,
endpoint: '/metrics',
prefix: '',
Expand All @@ -29,7 +29,7 @@ export class PrometheusExporter extends MetricReader {
withoutTargetInfo: false,
};

private readonly _host?: string;
private readonly _host: string;
private readonly _port: number;
private readonly _baseUrl: string;
private readonly _endpoint: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ describe('PrometheusExporter', () => {
describe('constructor', () => {
it('should construct an exporter', async () => {
const exporter = new PrometheusExporter();
await exporter.startServer();
assert.ok(typeof exporter.startServer === 'function');
assert.ok(typeof exporter.shutdown === 'function');
await exporter.shutdown();
Expand Down Expand Up @@ -95,6 +96,7 @@ describe('PrometheusExporter', () => {
const port = PrometheusExporter.DEFAULT_OPTIONS.port;
const endpoint = PrometheusExporter.DEFAULT_OPTIONS.endpoint;
const exporter = new PrometheusExporter();
await exporter.startServer();
const url = `http://localhost:${port}${endpoint}`;
await request(url);
await exporter.shutdown();
Expand All @@ -108,6 +110,7 @@ describe('PrometheusExporter', () => {
port,
endpoint,
});
await exporter.startServer();
const url = `http://localhost:${port}${endpoint}`;
await request(url);
await exporter.shutdown();
Expand Down Expand Up @@ -154,6 +157,7 @@ describe('PrometheusExporter', () => {
port,
endpoint,
});
await exporter.startServer();
const url = `http://localhost:${port}/invalid`;

await assert.rejects(request(url), { statusCode: 404 });
Expand Down Expand Up @@ -194,6 +198,7 @@ describe('PrometheusExporter', () => {

beforeEach(async () => {
exporter = new PrometheusExporter();
await exporter.startServer();
meterProvider = new MeterProvider({
readers: [exporter],
});
Expand Down Expand Up @@ -459,7 +464,8 @@ describe('PrometheusExporter', () => {
let counter: Counter;
let exporter: PrometheusExporter;

function setup(reader: PrometheusExporter) {
async function setup(reader: PrometheusExporter) {
await reader.startServer();
meterProvider = new MeterProvider({
readers: [exporter],
});
Expand All @@ -477,7 +483,7 @@ describe('PrometheusExporter', () => {
exporter = new PrometheusExporter({
prefix: 'test_prefix',
});
setup(exporter);
await setup(exporter);
const body = await request('http://localhost:9464/metrics');
const lines = body.split('\n');

Expand All @@ -495,7 +501,7 @@ describe('PrometheusExporter', () => {
port: 8080,
});

setup(exporter);
await setup(exporter);
const body = await request('http://localhost:8080/metrics');
const lines = body.split('\n');

Expand All @@ -513,7 +519,7 @@ describe('PrometheusExporter', () => {
endpoint: '/test',
});

setup(exporter);
await setup(exporter);
const body = await request('http://localhost:9464/test');
const lines = body.split('\n');

Expand All @@ -530,7 +536,7 @@ describe('PrometheusExporter', () => {
exporter = new PrometheusExporter({
appendTimestamp: true,
});
setup(exporter);
await setup(exporter);
const body = await request('http://localhost:9464/metrics');
const lines = body.split('\n');

Expand All @@ -547,7 +553,7 @@ describe('PrometheusExporter', () => {
exporter = new PrometheusExporter({
withResourceConstantLabels: /.*/,
});
setup(exporter);
await setup(exporter);
const body = await request('http://localhost:9464/metrics');
const lines = body.split('\n');

Expand All @@ -564,7 +570,7 @@ describe('PrometheusExporter', () => {
exporter = new PrometheusExporter({
withResourceConstantLabels: /telemetry.sdk.language|telemetry.sdk.name/,
});
setup(exporter);
await setup(exporter);
const body = await request('http://localhost:9464/metrics');
const lines = body.split('\n');

Expand All @@ -579,15 +585,15 @@ describe('PrometheusExporter', () => {

it('should omit target_info if withoutTargetInfo is true', async () => {
exporter = new PrometheusExporter({ withoutTargetInfo: true });
setup(exporter);
await setup(exporter);
const body = await request('http://localhost:9464/metrics');

assert.deepStrictEqual(body.includes('target_info'), false);
});

it('should omit scope labels if withoutScopeInfo is true', async () => {
exporter = new PrometheusExporter({ withoutScopeInfo: true });
setup(exporter);
await setup(exporter);
const body = await request('http://localhost:9464/metrics');
const lines = body.split('\n');

Expand Down
Loading