Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(exporter-jaeger): add env variable for agent port #2754

Merged
merged 4 commits into from
Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/opentelemetry-core/src/utils/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -109,6 +110,7 @@ export const DEFAULT_ENVIRONMENT: Required<ENVIRONMENT> = {
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: '',
Expand Down
2 changes: 2 additions & 0 deletions packages/opentelemetry-core/test/utils/environment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions packages/opentelemetry-exporter-jaeger/src/jaeger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
9 changes: 7 additions & 2 deletions packages/opentelemetry-exporter-jaeger/test/jaeger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [{
Expand All @@ -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: [{
Expand All @@ -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', () => {
Expand Down