Skip to content

Commit

Permalink
feat: add prometheus exporter host and port env vars
Browse files Browse the repository at this point in the history
Signed-off-by: naseemkullah <[email protected]>
  • Loading branch information
naseemkullah committed Jan 24, 2021
1 parent a78bb80 commit fb1810e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packages/opentelemetry-core/src/utils/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 &
Expand All @@ -85,6 +87,8 @@ export const DEFAULT_ENVIRONMENT: Required<ENVIRONMENT> = {
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: '',
Expand Down
4 changes: 4 additions & 0 deletions packages/opentelemetry-core/test/utils/environment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: '<attrs>',
Expand All @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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,
};
Expand Down

0 comments on commit fb1810e

Please sign in to comment.