diff --git a/packages/opentelemetry-core/src/utils/environment.ts b/packages/opentelemetry-core/src/utils/environment.ts index 2088772ca27..751c8d935bc 100644 --- a/packages/opentelemetry-core/src/utils/environment.ts +++ b/packages/opentelemetry-core/src/utils/environment.ts @@ -62,6 +62,8 @@ export type ENVIRONMENT = { OTEL_EXPORTER_JAEGER_ENDPOINT?: string; OTEL_EXPORTER_JAEGER_PASSWORD?: string; OTEL_EXPORTER_JAEGER_USER?: string; + OTEL_EXPORTER_PROMETHEUS_HOST?: string; + OTEL_EXPORTER_PROMETHEUS_PORT?: number; OTEL_LOG_LEVEL?: LogLevel; OTEL_RESOURCE_ATTRIBUTES?: string; } & ENVIRONMENT_NUMBERS & @@ -85,6 +87,8 @@ export const DEFAULT_ENVIRONMENT: Required = { OTEL_EXPORTER_JAEGER_ENDPOINT: '', OTEL_EXPORTER_JAEGER_PASSWORD: '', OTEL_EXPORTER_JAEGER_USER: '', + OTEL_EXPORTER_PROMETHEUS_HOST: '', + OTEL_EXPORTER_PROMETHEUS_PORT: 9464, OTEL_LOG_LEVEL: LogLevel.INFO, OTEL_NO_PATCH_MODULES: [], OTEL_RESOURCE_ATTRIBUTES: '', diff --git a/packages/opentelemetry-core/test/utils/environment.test.ts b/packages/opentelemetry-core/test/utils/environment.test.ts index 35c9bdcb5ab..ca993dc20d1 100644 --- a/packages/opentelemetry-core/test/utils/environment.test.ts +++ b/packages/opentelemetry-core/test/utils/environment.test.ts @@ -86,6 +86,8 @@ describe('environment', () => { OTEL_EXPORTER_JAEGER_ENDPOINT: 'https://example.com/endpoint', OTEL_EXPORTER_JAEGER_PASSWORD: 'secret', OTEL_EXPORTER_JAEGER_USER: 'whoami', + OTEL_EXPORTER_PROMETHEUS_HOST: '1.2.3.4', + OTEL_EXPORTER_PROMETHEUS_PORT: 1234, OTEL_LOG_LEVEL: 'ERROR', OTEL_NO_PATCH_MODULES: 'a,b,c', OTEL_RESOURCE_ATTRIBUTES: '', @@ -111,6 +113,8 @@ describe('environment', () => { env.OTEL_EXPORTER_JAEGER_AGENT_HOST, 'host.domain.com' ); + assert.strictEqual(env.OTEL_EXPORTER_PROMETHEUS_HOST, '1.2.3.4'); + assert.strictEqual(env.OTEL_EXPORTER_PROMETHEUS_PORT, 1234); assert.strictEqual( env.ECS_CONTAINER_METADATA_URI_V4, 'https://ecs.uri/v4' diff --git a/packages/opentelemetry-exporter-prometheus/src/PrometheusExporter.ts b/packages/opentelemetry-exporter-prometheus/src/PrometheusExporter.ts index d47745980ca..65b5402a6fe 100644 --- a/packages/opentelemetry-exporter-prometheus/src/PrometheusExporter.ts +++ b/packages/opentelemetry-exporter-prometheus/src/PrometheusExporter.ts @@ -19,6 +19,7 @@ import { ExportResult, globalErrorHandler, ExportResultCode, + getEnv, } from '@opentelemetry/core'; import { MetricExporter, MetricRecord } from '@opentelemetry/metrics'; import { createServer, IncomingMessage, Server, ServerResponse } from 'http'; @@ -27,10 +28,11 @@ import { ExporterConfig } from './export/types'; import { PrometheusSerializer } from './PrometheusSerializer'; import { PrometheusLabelsBatcher } from './PrometheusLabelsBatcher'; +const env = getEnv(); export class PrometheusExporter implements MetricExporter { static readonly DEFAULT_OPTIONS = { - port: 9464, - endpoint: '/metrics', + port: env.OTEL_EXPORTER_PROMETHEUS_PORT, + endpoint: `${env.OTEL_EXPORTER_PROMETHEUS_HOST}/metrics`, prefix: '', appendTimestamp: true, };