@@ -65,6 +65,7 @@ fn parse_headers(val: &str) -> impl Iterator<Item = (String, String)> + '_ {
6565 s
6666 } )
6767}
68+
6869fn read_headers_from_env ( ) -> HashMap < String , String > {
6970 let mut headers = HashMap :: new ( ) ;
7071 headers. extend ( parse_headers (
@@ -75,13 +76,21 @@ fn read_headers_from_env() -> HashMap<String, String> {
7576 ) ) ;
7677 headers
7778}
79+
7880fn read_protocol_and_endpoint_from_env ( ) -> ( Option < String > , Option < String > ) {
79- let maybe_endpoint = std:: env:: var ( "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT" )
80- . or_else ( |_| std:: env:: var ( "OTEL_EXPORTER_OTLP_ENDPOINT" ) )
81- . ok ( ) ;
8281 let maybe_protocol = std:: env:: var ( "OTEL_EXPORTER_OTLP_TRACES_PROTOCOL" )
8382 . or_else ( |_| std:: env:: var ( "OTEL_EXPORTER_OTLP_PROTOCOL" ) )
8483 . ok ( ) ;
84+ let maybe_endpoint = std:: env:: var ( "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT" )
85+ . or_else ( |_| {
86+ std:: env:: var ( "OTEL_EXPORTER_OTLP_ENDPOINT" ) . map ( |endpoint| match & maybe_protocol {
87+ Some ( protocol) if protocol. contains ( "http" ) => {
88+ format ! ( "{endpoint}/v1/traces" )
89+ }
90+ _ => endpoint,
91+ } )
92+ } )
93+ . ok ( ) ;
8594 ( maybe_protocol, maybe_endpoint)
8695}
8796
@@ -142,7 +151,7 @@ fn infer_protocol_and_endpoint(
142151 }
143152
144153 let endpoint = match protocol {
145- "http/protobuf" => maybe_endpoint. unwrap_or ( "http://localhost:4318" ) , //Devskim: ignore DS137138
154+ "http/protobuf" => maybe_endpoint. unwrap_or ( "http://localhost:4318/v1/traces " ) , //Devskim: ignore DS137138
146155 _ => maybe_endpoint. unwrap_or ( "http://localhost:4317" ) , //Devskim: ignore DS137138
147156 } ;
148157
@@ -157,8 +166,13 @@ mod tests {
157166 use super :: * ;
158167
159168 #[ rstest]
160- #[ case( None , None , "http/protobuf" , "http://localhost:4318" ) ] //Devskim: ignore DS137138
161- #[ case( Some ( "http/protobuf" ) , None , "http/protobuf" , "http://localhost:4318" ) ] //Devskim: ignore DS137138
169+ #[ case( None , None , "http/protobuf" , "http://localhost:4318/v1/traces" ) ] //Devskim: ignore DS137138
170+ #[ case(
171+ Some ( "http/protobuf" ) ,
172+ None ,
173+ "http/protobuf" ,
174+ "http://localhost:4318/v1/traces"
175+ ) ] //Devskim: ignore DS137138
162176 #[ case( Some ( "grpc" ) , None , "grpc" , "http://localhost:4317" ) ] //Devskim: ignore DS137138
163177 #[ case( None , Some ( "http://localhost:4317" ) , "grpc" , "http://localhost:4317" ) ] //Devskim: ignore DS137138
164178 #[ cfg_attr(
@@ -181,15 +195,15 @@ mod tests {
181195 ) ]
182196 #[ case(
183197 Some ( "http/protobuf" ) ,
184- Some ( "http://localhost:4318" ) , //Devskim: ignore DS137138
198+ Some ( "http://localhost:4318/v1/traces " ) , //Devskim: ignore DS137138
185199 "http/protobuf" ,
186- "http://localhost:4318" //Devskim: ignore DS137138
200+ "http://localhost:4318/v1/traces " //Devskim: ignore DS137138
187201 ) ]
188202 #[ case(
189203 Some ( "http/protobuf" ) ,
190- Some ( "https://examples.com:4318" ) ,
204+ Some ( "https://examples.com:4318/v1/traces " ) ,
191205 "http/protobuf" ,
192- "https://examples.com:4318"
206+ "https://examples.com:4318/v1/traces "
193207 ) ]
194208 #[ case(
195209 Some ( "http/protobuf" ) ,
0 commit comments