File tree Expand file tree Collapse file tree 4 files changed +46
-3
lines changed
opentelemetry-core/src/utils
opentelemetry-exporter-zipkin Expand file tree Collapse file tree 4 files changed +46
-3
lines changed Original file line number Diff line number Diff line change @@ -67,6 +67,7 @@ export type ENVIRONMENT = {
6767 OTEL_EXPORTER_JAEGER_ENDPOINT ?: string ;
6868 OTEL_EXPORTER_JAEGER_PASSWORD ?: string ;
6969 OTEL_EXPORTER_JAEGER_USER ?: string ;
70+ OTEL_EXPORTER_ZIPKIN_ENDPOINT ?: string ;
7071 OTEL_LOG_LEVEL ?: DiagLogLevel ;
7172 OTEL_RESOURCE_ATTRIBUTES ?: string ;
7273} & ENVIRONMENT_NUMBERS &
@@ -94,6 +95,7 @@ export const DEFAULT_ENVIRONMENT: Required<ENVIRONMENT> = {
9495 OTEL_EXPORTER_JAEGER_ENDPOINT : '' ,
9596 OTEL_EXPORTER_JAEGER_PASSWORD : '' ,
9697 OTEL_EXPORTER_JAEGER_USER : '' ,
98+ OTEL_EXPORTER_ZIPKIN_ENDPOINT : 'http://localhost:9411/api/v2/spans' ,
9799 OTEL_LOG_LEVEL : DiagLogLevel . INFO ,
98100 OTEL_NO_PATCH_MODULES : [ ] ,
99101 OTEL_PROPAGATORS : [ 'tracecontext' , 'baggage' ] ,
Original file line number Diff line number Diff line change 1515 */
1616
1717import { diag } from '@opentelemetry/api' ;
18- import { ExportResult , ExportResultCode } from '@opentelemetry/core' ;
18+ import { ExportResult , ExportResultCode , getEnv } from '@opentelemetry/core' ;
1919import { SpanExporter , ReadableSpan } from '@opentelemetry/tracing' ;
2020import { prepareSend } from './platform/index' ;
2121import * as zipkinTypes from './types' ;
@@ -31,7 +31,6 @@ import { prepareGetHeaders } from './utils';
3131 * Zipkin Exporter
3232 */
3333export class ZipkinExporter implements SpanExporter {
34- static readonly DEFAULT_URL = 'http://localhost:9411/api/v2/spans' ;
3534 private readonly DEFAULT_SERVICE_NAME = 'OpenTelemetry Service' ;
3635 private readonly _statusCodeTagName : string ;
3736 private readonly _statusDescriptionTagName : string ;
@@ -43,7 +42,7 @@ export class ZipkinExporter implements SpanExporter {
4342 private _sendingPromises : Promise < unknown > [ ] = [ ] ;
4443
4544 constructor ( config : zipkinTypes . ExporterConfig = { } ) {
46- this . _urlStr = config . url || ZipkinExporter . DEFAULT_URL ;
45+ this . _urlStr = config . url || getEnv ( ) . OTEL_EXPORTER_ZIPKIN_ENDPOINT ;
4746 this . _send = prepareSend ( this . _urlStr , config . headers ) ;
4847 this . _serviceName = config . serviceName ;
4948 this . _statusCodeTagName = config . statusCodeTagName || statusCodeTagName ;
Original file line number Diff line number Diff line change @@ -96,6 +96,34 @@ describe('Zipkin Exporter - web', () => {
9696 } ) ;
9797 } ) ;
9898 } ) ;
99+
100+ describe ( 'should use url defined in environment' , ( ) => {
101+ let server : any ;
102+ const endpointUrl = 'http://localhost:9412' ;
103+ beforeEach ( ( ) => {
104+ ( window . navigator as any ) . sendBeacon = false ;
105+ ( window as any ) . OTEL_EXPORTER_ZIPKIN_ENDPOINT = endpointUrl ;
106+ zipkinExporter = new ZipkinExporter ( zipkinConfig ) ;
107+ server = sinon . fakeServer . create ( ) ;
108+ } ) ;
109+ afterEach ( ( ) => {
110+ server . restore ( ) ;
111+ } ) ;
112+
113+ it ( 'should successfully send the spans using XMLHttpRequest' , done => {
114+ zipkinExporter . export ( spans , ( ) => { } ) ;
115+
116+ setTimeout ( ( ) => {
117+ const request = server . requests [ 0 ] ;
118+ assert ( request . url , endpointUrl ) ;
119+ const body = request . requestBody ;
120+ const json = JSON . parse ( body ) as any ;
121+ ensureSpanIsCorrect ( json [ 0 ] ) ;
122+
123+ done ( ) ;
124+ } ) ;
125+ } ) ;
126+ } ) ;
99127 } ) ;
100128 describe ( 'when getExportRequestHeaders is defined' , ( ) => {
101129 let server : any ;
Original file line number Diff line number Diff line change @@ -650,6 +650,20 @@ describe('Zipkin Exporter - node', () => {
650650 ) ;
651651 } ) ;
652652 } ) ;
653+
654+ it ( 'should support setting url via env' , ( ) => {
655+ process . env . OTEL_EXPORTER_ZIPKIN_ENDPOINT = 'http://localhost:9412' ;
656+ const scope = nock ( 'http://localhost:9412' ) . post ( '/' ) . reply ( 200 ) ;
657+
658+ const exporter = new ZipkinExporter ( {
659+ serviceName : 'my-service' ,
660+ } ) ;
661+
662+ exporter . export ( [ getReadableSpan ( ) ] , ( result : ExportResult ) => {
663+ scope . done ( ) ;
664+ assert . strictEqual ( result . code , ExportResultCode . SUCCESS ) ;
665+ } ) ;
666+ } ) ;
653667 } ) ;
654668
655669 describe ( 'shutdown' , ( ) => {
You can’t perform that action at this time.
0 commit comments