@@ -427,6 +427,19 @@ static UNSTABLE_OPS: &[&str] = &[
427427
428428use crate :: useragent;
429429
430+ // Parse a reqwest response body as JSON without serde_json's default 128-level
431+ // recursion cap. Some Datadog endpoints (e.g. /profiling/api/v1/aggregate)
432+ // return deeply-nested flame-graph trees that exceed it. serde_stacker grows
433+ // the thread stack on demand so disabling the limit can't blow it.
434+ async fn parse_response_json ( resp : reqwest:: Response ) -> anyhow:: Result < serde_json:: Value > {
435+ use serde:: Deserialize ;
436+ let bytes = resp. bytes ( ) . await ?;
437+ let mut de = serde_json:: Deserializer :: from_slice ( & bytes) ;
438+ de. disable_recursion_limit ( ) ;
439+ let de = serde_stacker:: Deserializer :: new ( & mut de) ;
440+ Ok ( serde_json:: Value :: deserialize ( de) ?)
441+ }
442+
430443#[ allow( dead_code) ]
431444#[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
432445pub enum AuthType {
@@ -838,7 +851,7 @@ pub async fn raw_get(
838851 }
839852 . into ( ) ) ;
840853 }
841- Ok ( resp. json ( ) . await ? )
854+ parse_response_json ( resp) . await
842855}
843856
844857/// Makes an authenticated PATCH request directly via reqwest.
@@ -873,7 +886,7 @@ pub async fn raw_patch(
873886 }
874887 . into ( ) ) ;
875888 }
876- Ok ( resp. json ( ) . await ? )
889+ parse_response_json ( resp) . await
877890}
878891
879892/// Makes an authenticated POST request directly via reqwest.
@@ -928,7 +941,7 @@ async fn raw_post_impl(
928941 }
929942 . into ( ) ) ;
930943 }
931- Ok ( resp. json ( ) . await ? )
944+ parse_response_json ( resp) . await
932945}
933946
934947fn apply_auth (
@@ -993,7 +1006,7 @@ pub async fn raw_post_jsonapi(
9931006 let body = resp. text ( ) . await . unwrap_or_default ( ) ;
9941007 anyhow:: bail!( "POST {url} failed (HTTP {status}): {body}" ) ;
9951008 }
996- Ok ( resp. json ( ) . await ? )
1009+ parse_response_json ( resp) . await
9971010}
9981011
9991012/// Like `raw_post`, but returns the parsed JSON body even on non-2xx responses.
@@ -1024,7 +1037,7 @@ pub async fn raw_post_lenient(
10241037 . json ( & body)
10251038 . send ( )
10261039 . await ?;
1027- Ok ( resp. json ( ) . await ? )
1040+ parse_response_json ( resp) . await
10281041}
10291042
10301043/// Makes an authenticated DELETE request directly via reqwest.
0 commit comments