@@ -23,8 +23,11 @@ const ENV_AGENT_HOST: &str = "OTEL_EXPORTER_JAEGER_AGENT_HOST";
2323/// e.g. 6832
2424const ENV_AGENT_PORT : & str = "OTEL_EXPORTER_JAEGER_AGENT_PORT" ;
2525
26- /// Default agent endpoint if none is provided
27- const DEFAULT_AGENT_ENDPOINT : & str = "127.0.0.1:6831" ;
26+ /// Default agent host if none is provided
27+ const DEFAULT_AGENT_ENDPOINT_HOST : & str = "127.0.0.1" ;
28+
29+ /// Default agent port if none is provided
30+ const DEFAULT_AGENT_ENDPOINT_PORT : & str = "6831" ;
2831
2932/// AgentPipeline config and build a exporter targeting a jaeger agent using UDP as transport layer protocol.
3033///
@@ -84,16 +87,26 @@ impl Default for AgentPipeline {
8487 transformation_config : Default :: default ( ) ,
8588 trace_config : Default :: default ( ) ,
8689 batch_config : Some ( Default :: default ( ) ) ,
87- agent_endpoint : Ok ( vec ! [ DEFAULT_AGENT_ENDPOINT . parse( ) . unwrap( ) ] ) ,
90+ agent_endpoint : Ok ( vec ! [ format!(
91+ "{DEFAULT_AGENT_ENDPOINT_HOST}:{DEFAULT_AGENT_ENDPOINT_PORT}"
92+ )
93+ . parse( )
94+ . unwrap( ) ] ) ,
8895 max_packet_size : UDP_PACKET_MAX_LENGTH ,
8996 auto_split_batch : false ,
9097 } ;
9198
92- if let ( Ok ( host) , Ok ( port) ) = ( env:: var ( ENV_AGENT_HOST ) , env:: var ( ENV_AGENT_PORT ) ) {
93- pipeline = pipeline. with_endpoint ( format ! ( "{}:{}" , host. trim( ) , port. trim( ) ) ) ;
94- } else if let Ok ( port) = env:: var ( ENV_AGENT_PORT ) {
95- pipeline = pipeline. with_endpoint ( format ! ( "127.0.0.1:{}" , port. trim( ) ) )
99+ let endpoint = match ( env:: var ( ENV_AGENT_HOST ) , env:: var ( ENV_AGENT_PORT ) ) {
100+ ( Ok ( host) , Ok ( port) ) => Some ( format ! ( "{}:{}" , host. trim( ) , port. trim( ) ) ) ,
101+ ( Ok ( host) , _) => Some ( format ! ( "{}:{DEFAULT_AGENT_ENDPOINT_PORT}" , host. trim( ) ) ) ,
102+ ( _, Ok ( port) ) => Some ( format ! ( "{DEFAULT_AGENT_ENDPOINT_HOST}:{}" , port. trim( ) ) ) ,
103+ ( _, _) => None ,
104+ } ;
105+
106+ if let Some ( endpoint) = endpoint {
107+ pipeline = pipeline. with_endpoint ( endpoint) ;
96108 }
109+
97110 pipeline
98111 }
99112}
0 commit comments