Skip to content

Commit 31380ac

Browse files
authored
fix(exporter-jaeger): add env variable for agent port (#2754)
1 parent 0dc4c3d commit 31380ac

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

packages/opentelemetry-core/src/utils/environment.ts

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const ENVIRONMENT_NUMBERS_KEYS = [
3434
'OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT',
3535
'OTEL_SPAN_EVENT_COUNT_LIMIT',
3636
'OTEL_SPAN_LINK_COUNT_LIMIT',
37+
'OTEL_EXPORTER_JAEGER_AGENT_PORT',
3738
] as const;
3839

3940
type ENVIRONMENT_NUMBERS = {
@@ -109,6 +110,7 @@ export const DEFAULT_ENVIRONMENT: Required<ENVIRONMENT> = {
109110
OTEL_BSP_MAX_QUEUE_SIZE: 2048,
110111
OTEL_BSP_SCHEDULE_DELAY: 5000,
111112
OTEL_EXPORTER_JAEGER_AGENT_HOST: '',
113+
OTEL_EXPORTER_JAEGER_AGENT_PORT: 6832,
112114
OTEL_EXPORTER_JAEGER_ENDPOINT: '',
113115
OTEL_EXPORTER_JAEGER_PASSWORD: '',
114116
OTEL_EXPORTER_JAEGER_USER: '',

packages/opentelemetry-core/test/utils/environment.test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ describe('environment', () => {
7878
OTEL_BSP_MAX_EXPORT_BATCH_SIZE: 40,
7979
OTEL_BSP_SCHEDULE_DELAY: 50,
8080
OTEL_EXPORTER_JAEGER_AGENT_HOST: 'host.domain.com',
81+
OTEL_EXPORTER_JAEGER_AGENT_PORT: 1234,
8182
OTEL_EXPORTER_JAEGER_ENDPOINT: 'https://example.com/endpoint',
8283
OTEL_EXPORTER_JAEGER_PASSWORD: 'secret',
8384
OTEL_EXPORTER_JAEGER_USER: 'whoami',
@@ -112,6 +113,7 @@ describe('environment', () => {
112113
env.OTEL_EXPORTER_JAEGER_AGENT_HOST,
113114
'host.domain.com'
114115
);
116+
assert.strictEqual(env.OTEL_EXPORTER_JAEGER_AGENT_PORT, 1234);
115117
assert.strictEqual(
116118
env.ECS_CONTAINER_METADATA_URI_V4,
117119
'https://ecs.uri/v4'

packages/opentelemetry-exporter-jaeger/src/jaeger.ts

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export class JaegerExporter implements SpanExporter {
5353
localConfig.password =
5454
localConfig.password || env.OTEL_EXPORTER_JAEGER_PASSWORD;
5555
localConfig.host = localConfig.host || env.OTEL_EXPORTER_JAEGER_AGENT_HOST;
56+
localConfig.port = localConfig.port || env.OTEL_EXPORTER_JAEGER_AGENT_PORT;
5657

5758
this._localConfig = localConfig;
5859

packages/opentelemetry-exporter-jaeger/test/jaeger.test.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,9 @@ describe('JaegerExporter', () => {
116116
assert.strictEqual(sender._host, 'localhost');
117117
});
118118

119-
it('should respect jaeger host env variable', () => {
119+
it('should respect jaeger host and port env variable', () => {
120120
process.env.OTEL_EXPORTER_JAEGER_AGENT_HOST = 'env-set-host';
121+
process.env.OTEL_EXPORTER_JAEGER_AGENT_PORT = '1234';
121122
const exporter = new JaegerExporter();
122123
const sender = exporter['_getSender']({
123124
tags: [{
@@ -126,12 +127,15 @@ describe('JaegerExporter', () => {
126127
}]
127128
} as any);
128129
assert.strictEqual(sender._host, 'env-set-host');
130+
assert.strictEqual(sender._port, 1234);
129131
});
130132

131-
it('should prioritize host option over env variable', () => {
133+
it('should prioritize host and port option over env variable', () => {
132134
process.env.OTEL_EXPORTER_JAEGER_AGENT_HOST = 'env-set-host';
135+
process.env.OTEL_EXPORTER_JAEGER_AGENT_PORT = '1234';
133136
const exporter = new JaegerExporter({
134137
host: 'option-set-host',
138+
port: 5678
135139
});
136140
const sender = exporter['_getSender']({
137141
tags: [{
@@ -140,6 +144,7 @@ describe('JaegerExporter', () => {
140144
}]
141145
} as any);
142146
assert.strictEqual(sender._host, 'option-set-host');
147+
assert.strictEqual(sender._port, 5678);
143148
});
144149

145150
it('should construct an exporter with flushTimeout', () => {

0 commit comments

Comments
 (0)