diff --git a/experimental/CHANGELOG.md b/experimental/CHANGELOG.md index 32f6b55f929..e1627c9f914 100644 --- a/experimental/CHANGELOG.md +++ b/experimental/CHANGELOG.md @@ -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 diff --git a/experimental/packages/opentelemetry-exporter-prometheus/src/PrometheusExporter.ts b/experimental/packages/opentelemetry-exporter-prometheus/src/PrometheusExporter.ts index 1436b129524..e92f5a32f4c 100644 --- a/experimental/packages/opentelemetry-exporter-prometheus/src/PrometheusExporter.ts +++ b/experimental/packages/opentelemetry-exporter-prometheus/src/PrometheusExporter.ts @@ -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: '', @@ -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; diff --git a/experimental/packages/opentelemetry-exporter-prometheus/test/PrometheusExporter.test.ts b/experimental/packages/opentelemetry-exporter-prometheus/test/PrometheusExporter.test.ts index f413710505e..9c1fb98f093 100644 --- a/experimental/packages/opentelemetry-exporter-prometheus/test/PrometheusExporter.test.ts +++ b/experimental/packages/opentelemetry-exporter-prometheus/test/PrometheusExporter.test.ts @@ -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(); @@ -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(); @@ -108,6 +110,7 @@ describe('PrometheusExporter', () => { port, endpoint, }); + await exporter.startServer(); const url = `http://localhost:${port}${endpoint}`; await request(url); await exporter.shutdown(); @@ -154,6 +157,7 @@ describe('PrometheusExporter', () => { port, endpoint, }); + await exporter.startServer(); const url = `http://localhost:${port}/invalid`; await assert.rejects(request(url), { statusCode: 404 }); @@ -194,6 +198,7 @@ describe('PrometheusExporter', () => { beforeEach(async () => { exporter = new PrometheusExporter(); + await exporter.startServer(); meterProvider = new MeterProvider({ readers: [exporter], }); @@ -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], }); @@ -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'); @@ -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'); @@ -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'); @@ -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'); @@ -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'); @@ -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'); @@ -579,7 +585,7 @@ 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); @@ -587,7 +593,7 @@ describe('PrometheusExporter', () => { 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');