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

feat(zipkin): allow to configure url via environment #1675 #2097

Merged
merged 1 commit into from
Apr 14, 2021
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
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 @@ -67,6 +67,7 @@ export type ENVIRONMENT = {
OTEL_EXPORTER_JAEGER_ENDPOINT?: string;
OTEL_EXPORTER_JAEGER_PASSWORD?: string;
OTEL_EXPORTER_JAEGER_USER?: string;
OTEL_EXPORTER_ZIPKIN_ENDPOINT?: string;
OTEL_LOG_LEVEL?: DiagLogLevel;
OTEL_RESOURCE_ATTRIBUTES?: string;
} & ENVIRONMENT_NUMBERS &
Expand Down Expand Up @@ -94,6 +95,7 @@ export const DEFAULT_ENVIRONMENT: Required<ENVIRONMENT> = {
OTEL_EXPORTER_JAEGER_ENDPOINT: '',
OTEL_EXPORTER_JAEGER_PASSWORD: '',
OTEL_EXPORTER_JAEGER_USER: '',
OTEL_EXPORTER_ZIPKIN_ENDPOINT: 'http://localhost:9411/api/v2/spans',
OTEL_LOG_LEVEL: DiagLogLevel.INFO,
OTEL_NO_PATCH_MODULES: [],
OTEL_PROPAGATORS: ['tracecontext', 'baggage'],
Expand Down
5 changes: 2 additions & 3 deletions packages/opentelemetry-exporter-zipkin/src/zipkin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import { diag } from '@opentelemetry/api';
import { ExportResult, ExportResultCode } from '@opentelemetry/core';
import { ExportResult, ExportResultCode, getEnv } from '@opentelemetry/core';
import { SpanExporter, ReadableSpan } from '@opentelemetry/tracing';
import { prepareSend } from './platform/index';
import * as zipkinTypes from './types';
Expand All @@ -31,7 +31,6 @@ import { prepareGetHeaders } from './utils';
* Zipkin Exporter
*/
export class ZipkinExporter implements SpanExporter {
static readonly DEFAULT_URL = 'http://localhost:9411/api/v2/spans';
private readonly DEFAULT_SERVICE_NAME = 'OpenTelemetry Service';
private readonly _statusCodeTagName: string;
private readonly _statusDescriptionTagName: string;
Expand All @@ -43,7 +42,7 @@ export class ZipkinExporter implements SpanExporter {
private _sendingPromises: Promise<unknown>[] = [];

constructor(config: zipkinTypes.ExporterConfig = {}) {
this._urlStr = config.url || ZipkinExporter.DEFAULT_URL;
this._urlStr = config.url || getEnv().OTEL_EXPORTER_ZIPKIN_ENDPOINT;
this._send = prepareSend(this._urlStr, config.headers);
this._serviceName = config.serviceName;
this._statusCodeTagName = config.statusCodeTagName || statusCodeTagName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,34 @@ describe('Zipkin Exporter - web', () => {
});
});
});

describe('should use url defined in environment', () => {
let server: any;
const endpointUrl = 'http://localhost:9412';
beforeEach(() => {
(window.navigator as any).sendBeacon = false;
(window as any).OTEL_EXPORTER_ZIPKIN_ENDPOINT = endpointUrl;
zipkinExporter = new ZipkinExporter(zipkinConfig);
server = sinon.fakeServer.create();
});
afterEach(() => {
server.restore();
});

it('should successfully send the spans using XMLHttpRequest', done => {
zipkinExporter.export(spans, () => {});

setTimeout(() => {
const request = server.requests[0];
assert(request.url, endpointUrl);
const body = request.requestBody;
const json = JSON.parse(body) as any;
ensureSpanIsCorrect(json[0]);

done();
});
});
});
});
describe('when getExportRequestHeaders is defined', () => {
let server: any;
Expand Down
14 changes: 14 additions & 0 deletions packages/opentelemetry-exporter-zipkin/test/node/zipkin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,20 @@ describe('Zipkin Exporter - node', () => {
);
});
});

it('should support setting url via env', () => {
process.env.OTEL_EXPORTER_ZIPKIN_ENDPOINT = 'http://localhost:9412';
const scope = nock('http://localhost:9412').post('/').reply(200);

const exporter = new ZipkinExporter({
serviceName: 'my-service',
});

exporter.export([getReadableSpan()], (result: ExportResult) => {
scope.done();
assert.strictEqual(result.code, ExportResultCode.SUCCESS);
});
});
});

describe('shutdown', () => {
Expand Down