diff --git a/packages/opentelemetry-core/src/utils/environment.ts b/packages/opentelemetry-core/src/utils/environment.ts index 7df0be698c..e3bcfd8623 100644 --- a/packages/opentelemetry-core/src/utils/environment.ts +++ b/packages/opentelemetry-core/src/utils/environment.ts @@ -34,6 +34,7 @@ const ENVIRONMENT_NUMBERS_KEYS = [ 'OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT', 'OTEL_SPAN_EVENT_COUNT_LIMIT', 'OTEL_SPAN_LINK_COUNT_LIMIT', + 'OTEL_EXPORTER_JAEGER_AGENT_PORT', ] as const; type ENVIRONMENT_NUMBERS = { @@ -109,6 +110,7 @@ export const DEFAULT_ENVIRONMENT: Required = { OTEL_BSP_MAX_QUEUE_SIZE: 2048, OTEL_BSP_SCHEDULE_DELAY: 5000, OTEL_EXPORTER_JAEGER_AGENT_HOST: '', + OTEL_EXPORTER_JAEGER_AGENT_PORT: 6832, OTEL_EXPORTER_JAEGER_ENDPOINT: '', OTEL_EXPORTER_JAEGER_PASSWORD: '', OTEL_EXPORTER_JAEGER_USER: '', diff --git a/packages/opentelemetry-core/test/utils/environment.test.ts b/packages/opentelemetry-core/test/utils/environment.test.ts index 4ab3518645..e336eeeca5 100644 --- a/packages/opentelemetry-core/test/utils/environment.test.ts +++ b/packages/opentelemetry-core/test/utils/environment.test.ts @@ -78,6 +78,7 @@ describe('environment', () => { OTEL_BSP_MAX_EXPORT_BATCH_SIZE: 40, OTEL_BSP_SCHEDULE_DELAY: 50, OTEL_EXPORTER_JAEGER_AGENT_HOST: 'host.domain.com', + OTEL_EXPORTER_JAEGER_AGENT_PORT: 1234, OTEL_EXPORTER_JAEGER_ENDPOINT: 'https://example.com/endpoint', OTEL_EXPORTER_JAEGER_PASSWORD: 'secret', OTEL_EXPORTER_JAEGER_USER: 'whoami', @@ -112,6 +113,7 @@ describe('environment', () => { env.OTEL_EXPORTER_JAEGER_AGENT_HOST, 'host.domain.com' ); + assert.strictEqual(env.OTEL_EXPORTER_JAEGER_AGENT_PORT, 1234); assert.strictEqual( env.ECS_CONTAINER_METADATA_URI_V4, 'https://ecs.uri/v4' diff --git a/packages/opentelemetry-exporter-jaeger/src/jaeger.ts b/packages/opentelemetry-exporter-jaeger/src/jaeger.ts index ec9634793e..0ba979db04 100644 --- a/packages/opentelemetry-exporter-jaeger/src/jaeger.ts +++ b/packages/opentelemetry-exporter-jaeger/src/jaeger.ts @@ -53,6 +53,7 @@ export class JaegerExporter implements SpanExporter { localConfig.password = localConfig.password || env.OTEL_EXPORTER_JAEGER_PASSWORD; localConfig.host = localConfig.host || env.OTEL_EXPORTER_JAEGER_AGENT_HOST; + localConfig.port = localConfig.port || env.OTEL_EXPORTER_JAEGER_AGENT_PORT; this._localConfig = localConfig; diff --git a/packages/opentelemetry-exporter-jaeger/test/jaeger.test.ts b/packages/opentelemetry-exporter-jaeger/test/jaeger.test.ts index 6193796268..738f9b9ce7 100644 --- a/packages/opentelemetry-exporter-jaeger/test/jaeger.test.ts +++ b/packages/opentelemetry-exporter-jaeger/test/jaeger.test.ts @@ -116,8 +116,9 @@ describe('JaegerExporter', () => { assert.strictEqual(sender._host, 'localhost'); }); - it('should respect jaeger host env variable', () => { + it('should respect jaeger host and port env variable', () => { process.env.OTEL_EXPORTER_JAEGER_AGENT_HOST = 'env-set-host'; + process.env.OTEL_EXPORTER_JAEGER_AGENT_PORT = '1234'; const exporter = new JaegerExporter(); const sender = exporter['_getSender']({ tags: [{ @@ -126,12 +127,15 @@ describe('JaegerExporter', () => { }] } as any); assert.strictEqual(sender._host, 'env-set-host'); + assert.strictEqual(sender._port, 1234); }); - it('should prioritize host option over env variable', () => { + it('should prioritize host and port option over env variable', () => { process.env.OTEL_EXPORTER_JAEGER_AGENT_HOST = 'env-set-host'; + process.env.OTEL_EXPORTER_JAEGER_AGENT_PORT = '1234'; const exporter = new JaegerExporter({ host: 'option-set-host', + port: 5678 }); const sender = exporter['_getSender']({ tags: [{ @@ -140,6 +144,7 @@ describe('JaegerExporter', () => { }] } as any); assert.strictEqual(sender._host, 'option-set-host'); + assert.strictEqual(sender._port, 5678); }); it('should construct an exporter with flushTimeout', () => {