@@ -17,6 +17,7 @@ use crate::dsn;
1717
1818/// Several headers should not be forwarded as they can cause data truncation, or incorrect behavior.
1919const NO_COPY_HEADERS : [ & str ; 3 ] = [ "host" , "x-forwarded-for" , "content-length" ] ;
20+ const INGEST_PATH_SEGMENTS : [ & str ; 3 ] = [ "envelope" , "store" , "integration" ] ;
2021
2122/// Copy the relevant parts from `uri` and `headers` into a new request that can be sent
2223/// to the outbound DSN. This function returns `RequestBuilder` because the body types
@@ -30,7 +31,10 @@ pub fn make_outbound_request(
3031 // Update project id in the path
3132 let mut new_path = uri. path ( ) . to_string ( ) ;
3233 let path_parts: Vec < _ > = uri. path ( ) . split ( '/' ) . filter ( |i| !i. is_empty ( ) ) . collect ( ) ;
33- if path_parts. len ( ) == 3 && path_parts[ 0 ] == "api" {
34+ if path_parts. len ( ) >= 3
35+ && path_parts[ 0 ] == "api"
36+ && INGEST_PATH_SEGMENTS . contains ( & path_parts[ 2 ] )
37+ {
3438 let original_projectid = path_parts[ 1 ] ;
3539 let new_project_id = outbound. project_id . clone ( ) ;
3640 new_path = new_path. replace ( original_projectid, & new_project_id) ;
@@ -391,6 +395,29 @@ mod tests {
391395 assert_eq ! ( uri, "https://o789.ingest.sentry.io/api/6789/envelope/" ) ;
392396 }
393397
398+ #[ test]
399+ fn make_outbound_request_replace_project_id_oltp_url ( ) {
400+ let config = Arc :: new ( ConfigData :: default ( ) ) ;
401+ let outbound
: dsn
:: Dsn =
"https://[email protected] /6789" 402+ . parse ( )
403+ . unwrap ( ) ;
404+ let uri: Uri = "https://o123.ingest.sentry.io/api/123/integration/oltp/v1/traces/"
405+ . parse ( )
406+ . unwrap ( ) ;
407+
408+ let headers = HeaderMap :: new ( ) ;
409+ let builder = make_outbound_request ( & config, & uri, & headers, & outbound) ;
410+ let res = builder. body ( "" ) ;
411+
412+ assert ! ( res. is_ok( ) ) ;
413+ let req = res. unwrap ( ) ;
414+ let uri = req. uri ( ) ;
415+ assert_eq ! (
416+ uri,
417+ "https://o789.ingest.sentry.io/api/6789/integration/oltp/v1/traces/"
418+ ) ;
419+ }
420+
394421 #[ test]
395422 fn make_outbound_request_content_encoding_header ( ) {
396423 let config = Arc :: new ( ConfigData :: default ( ) ) ;
0 commit comments