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

[Jaeger-Exporter] host default env var #924

Merged
merged 3 commits into from
Apr 8, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 6 additions & 1 deletion packages/opentelemetry-exporter-jaeger/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# OpenTelemetry Jaeger Trace Exporter

[![Gitter chat][gitter-image]][gitter-url]
[![NPM Published Version][npm-img]][npm-url]
[![dependencies][dependencies-image]][dependencies-url]
Expand Down Expand Up @@ -54,6 +55,10 @@ npm install --save @opentelemetry/exporter-jaeger

Install the exporter on your application and pass the options, it must contain a service name.

Furthermore, the `host` option (which defaults to `localhost`), can instead be set by the
`JAEGER_AGENT_HOST` environment variable to reduce in-code config. If both are
set, the value set by the option in code is authoritative.

```js
import { JaegerExporter } from '@opentelemetry/exporter-jaeger';

Expand All @@ -78,8 +83,8 @@ You can use built-in `SimpleSpanProcessor` or `BatchSpanProcessor` or write your
- [SimpleSpanProcessor](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/sdk-tracing.md#simple-processor): The implementation of `SpanProcessor` that passes ended span directly to the configured `SpanExporter`.
- [BatchSpanProcessor](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/sdk-tracing.md#batching-processor): The implementation of the `SpanProcessor` that batches ended spans and pushes them to the configured `SpanExporter`. It is recommended to use this `SpanProcessor` for better performance and optimization.


## Useful links

- To know more about Jaeger, visit: https://www.jaegertracing.io/docs/latest/getting-started/
- For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
- For more about OpenTelemetry JavaScript: <https://github.com/open-telemetry/opentelemetry-js>
Expand Down
2 changes: 2 additions & 0 deletions packages/opentelemetry-exporter-jaeger/src/jaeger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export class JaegerExporter implements SpanExporter {
this._onShutdownFlushTimeout =
typeof config.flushTimeout === 'number' ? config.flushTimeout : 2000;

config.host = config.host || process.env.JAEGER_AGENT_HOST;

this._sender = new jaegerTypes.UDPSender(config);
if (this._sender._client instanceof Socket) {
// unref socket to prevent it from keeping the process running
Expand Down
31 changes: 30 additions & 1 deletion packages/opentelemetry-exporter-jaeger/test/jaeger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ import { Resource } from '@opentelemetry/resources';

describe('JaegerExporter', () => {
describe('constructor', () => {
afterEach(() => {
delete process.env.JAEGER_AGENT_HOST;
});

it('should construct an exporter', () => {
const exporter = new JaegerExporter({ serviceName: 'opentelemetry' });
assert.ok(typeof exporter.export === 'function');
Expand All @@ -38,7 +42,7 @@ describe('JaegerExporter', () => {
it('should construct an exporter with host, port, logger and tags', () => {
const exporter = new JaegerExporter({
serviceName: 'opentelemetry',
host: 'localhost',
host: 'remotehost',
port: 8080,
logger: new NoopLogger(),
tags: [{ key: 'opentelemetry-exporter-jaeger', value: '0.1.0' }],
Expand All @@ -47,13 +51,38 @@ describe('JaegerExporter', () => {
assert.ok(typeof exporter.shutdown === 'function');

const process: ThriftProcess = exporter['_sender']._process;
assert.strictEqual(exporter['_sender']._host, 'remotehost');
assert.strictEqual(process.serviceName, 'opentelemetry');
assert.strictEqual(process.tags.length, 1);
assert.strictEqual(process.tags[0].key, 'opentelemetry-exporter-jaeger');
assert.strictEqual(process.tags[0].vType, 'STRING');
assert.strictEqual(process.tags[0].vStr, '0.1.0');
});

it('should default to localhost if no host is configured', () => {
const exporter = new JaegerExporter({
serviceName: 'opentelemetry',
});
assert.strictEqual(exporter['_sender']._host, 'localhost');
});

it('should respect jaeger host env variable', () => {
process.env.JAEGER_AGENT_HOST = 'env-set-host';
const exporter = new JaegerExporter({
serviceName: 'test-service',
});
assert.strictEqual(exporter['_sender']._host, 'env-set-host');
});

it('should prioritize host option over env variable', () => {
process.env.JAEGER_AGENT_HOST = 'env-set-host';
const exporter = new JaegerExporter({
serviceName: 'test-service',
host: 'option-set-host',
});
assert.strictEqual(exporter['_sender']._host, 'option-set-host');
});

it('should construct an exporter with flushTimeout', () => {
const exporter = new JaegerExporter({
serviceName: 'opentelemetry',
Expand Down