@@ -65,6 +65,7 @@ fn parse_headers(val: &str) -> impl Iterator<Item = (String, String)> + '_ {
65
65
s
66
66
} )
67
67
}
68
+
68
69
fn read_headers_from_env ( ) -> HashMap < String , String > {
69
70
let mut headers = HashMap :: new ( ) ;
70
71
headers. extend ( parse_headers (
@@ -75,13 +76,21 @@ fn read_headers_from_env() -> HashMap<String, String> {
75
76
) ) ;
76
77
headers
77
78
}
79
+
78
80
fn 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 ( ) ;
82
81
let maybe_protocol = std:: env:: var ( "OTEL_EXPORTER_OTLP_TRACES_PROTOCOL" )
83
82
. or_else ( |_| std:: env:: var ( "OTEL_EXPORTER_OTLP_PROTOCOL" ) )
84
83
. 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 ( ) ;
85
94
( maybe_protocol, maybe_endpoint)
86
95
}
87
96
@@ -142,7 +151,7 @@ fn infer_protocol_and_endpoint(
142
151
}
143
152
144
153
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
146
155
_ => maybe_endpoint. unwrap_or ( "http://localhost:4317" ) , //Devskim: ignore DS137138
147
156
} ;
148
157
@@ -157,8 +166,13 @@ mod tests {
157
166
use super :: * ;
158
167
159
168
#[ 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
162
176
#[ case( Some ( "grpc" ) , None , "grpc" , "http://localhost:4317" ) ] //Devskim: ignore DS137138
163
177
#[ case( None , Some ( "http://localhost:4317" ) , "grpc" , "http://localhost:4317" ) ] //Devskim: ignore DS137138
164
178
#[ cfg_attr(
@@ -181,15 +195,15 @@ mod tests {
181
195
) ]
182
196
#[ case(
183
197
Some ( "http/protobuf" ) ,
184
- Some ( "http://localhost:4318" ) , //Devskim: ignore DS137138
198
+ Some ( "http://localhost:4318/v1/traces " ) , //Devskim: ignore DS137138
185
199
"http/protobuf" ,
186
- "http://localhost:4318" //Devskim: ignore DS137138
200
+ "http://localhost:4318/v1/traces " //Devskim: ignore DS137138
187
201
) ]
188
202
#[ case(
189
203
Some ( "http/protobuf" ) ,
190
- Some ( "https://examples.com:4318" ) ,
204
+ Some ( "https://examples.com:4318/v1/traces " ) ,
191
205
"http/protobuf" ,
192
- "https://examples.com:4318"
206
+ "https://examples.com:4318/v1/traces "
193
207
) ]
194
208
#[ case(
195
209
Some ( "http/protobuf" ) ,
0 commit comments