@@ -29,6 +29,8 @@ const V5_TRACE_ENDPOINT_PATH: &str = "/v0.5/traces";
2929const STATS_ENDPOINT_PATH : & str = "/v0.6/stats" ;
3030const DSM_ENDPOINT_PATH : & str = "/api/v0.1/pipeline_stats" ;
3131const DSM_AGENT_PATH : & str = "/v0.1/pipeline_stats" ;
32+ const PROFILING_ENDPOINT_PATH : & str = "/profiling/v1/input" ;
33+ const PROFILING_BACKEND_PATH : & str = "/api/v2/profile" ;
3234const INFO_ENDPOINT_PATH : & str = "/info" ;
3335const TRACER_PAYLOAD_CHANNEL_BUFFER_SIZE : usize = 10 ;
3436const STATS_PAYLOAD_CHANNEL_BUFFER_SIZE : usize = 10 ;
@@ -217,6 +219,15 @@ impl TraceAgent {
217219 ) ,
218220 }
219221 }
222+ ( & Method :: POST | & Method :: PUT , PROFILING_ENDPOINT_PATH ) => {
223+ match Self :: handle_profiling_proxy ( config, req) . await {
224+ Ok ( result) => Ok ( result) ,
225+ Err ( err) => log_and_create_http_response (
226+ & format ! ( "Profiling endpoint error: {err}" ) ,
227+ StatusCode :: INTERNAL_SERVER_ERROR ,
228+ ) ,
229+ }
230+ }
220231 ( _, INFO_ENDPOINT_PATH ) => match Self :: info_handler ( ) {
221232 Ok ( result) => Ok ( result) ,
222233 Err ( err) => log_and_create_http_response (
@@ -302,6 +313,7 @@ impl TraceAgent {
302313 V4_TRACE_ENDPOINT_PATH ,
303314 STATS_ENDPOINT_PATH ,
304315 DSM_AGENT_PATH ,
316+ PROFILING_ENDPOINT_PATH ,
305317 INFO_ENDPOINT_PATH
306318 ] ,
307319 "client_drop_p0s" : true ,
@@ -312,9 +324,13 @@ impl TraceAgent {
312324 . body ( Body :: from ( response_json. to_string ( ) ) )
313325 }
314326
315- async fn handle_dsm_proxy (
327+ /// Generic proxy handler for forwarding requests to Datadog backends
328+ async fn handle_proxy (
316329 config : Arc < config:: Config > ,
317330 req : Request < Body > ,
331+ backend_domain : & str ,
332+ backend_path : & str ,
333+ error_context : & str ,
318334 ) -> http:: Result < Response < Body > > {
319335 let ( parts, body) = req. into_parts ( ) ;
320336
@@ -330,7 +346,7 @@ impl TraceAgent {
330346 }
331347 } ;
332348
333- let target_url = format ! ( "https://trace.agent. {}{}" , config. site, DSM_ENDPOINT_PATH ) ;
349+ let target_url = format ! ( "https://{}. {}{}" , backend_domain , config. site, backend_path ) ;
334350 let client = http_client:: get_client ( config. clone ( ) ) ;
335351 let mut request_builder = client. post ( & target_url) ;
336352
@@ -350,7 +366,7 @@ impl TraceAgent {
350366 Ok ( resp) => resp,
351367 Err ( err) => {
352368 return log_and_create_http_response (
353- & format ! ( "Error sending request to DSM backend: {err}" ) ,
369+ & format ! ( "Error sending request to {} backend: {err}" , error_context ) ,
354370 StatusCode :: BAD_GATEWAY ,
355371 ) ;
356372 }
@@ -373,7 +389,7 @@ impl TraceAgent {
373389 Ok ( bytes) => bytes,
374390 Err ( err) => {
375391 return log_and_create_http_response (
376- & format ! ( "Error reading response from DSM backend: {err}" ) ,
392+ & format ! ( "Error reading response from {} backend: {err}" , error_context ) ,
377393 StatusCode :: BAD_GATEWAY ,
378394 ) ;
379395 }
@@ -382,6 +398,20 @@ impl TraceAgent {
382398 builder. body ( Body :: from ( response_body) )
383399 }
384400
401+ async fn handle_dsm_proxy (
402+ config : Arc < config:: Config > ,
403+ req : Request < Body > ,
404+ ) -> http:: Result < Response < Body > > {
405+ Self :: handle_proxy ( config, req, "trace.agent" , DSM_ENDPOINT_PATH , "DSM" ) . await
406+ }
407+
408+ async fn handle_profiling_proxy (
409+ config : Arc < config:: Config > ,
410+ req : Request < Body > ,
411+ ) -> http:: Result < Response < Body > > {
412+ Self :: handle_proxy ( config, req, "intake.profile" , PROFILING_BACKEND_PATH , "profiling" ) . await
413+ }
414+
385415 #[ must_use]
386416 pub fn get_sender_copy ( & self ) -> Sender < SendData > {
387417 self . tx . clone ( )
0 commit comments