@@ -12,6 +12,7 @@ use std::{
1212} ;
1313
1414use crate :: config:: Config ;
15+ use tracing:: { debug, error, info, warn} ;
1516
1617pub mod header {
1718 #![ allow( clippy:: declare_interior_mutable_const) ]
@@ -35,16 +36,29 @@ pub trait HttpClient {
3536pub fn request_builder ( c : & Config ) -> anyhow:: Result < HttpRequestBuilder > {
3637 match & c. endpoint {
3738 Some ( e) => {
39+ debug ! (
40+ endpoint. url = %e. url,
41+ endpoint. timeout_ms = e. timeout_ms,
42+ telemetry. version = env!( "CARGO_PKG_VERSION" ) ,
43+ "Building telemetry request"
44+ ) ;
3845 let mut builder =
3946 e. to_request_builder ( concat ! ( "telemetry/" , env!( "CARGO_PKG_VERSION" ) ) ) ;
4047 if c. debug_enabled {
48+ debug ! (
49+ telemetry. debug_enabled = true ,
50+ "Telemetry debug mode enabled"
51+ ) ;
4152 builder = Ok ( builder?. header ( header:: DEBUG_ENABLED , "true" ) )
4253 }
4354 builder
4455 }
45- None => Err ( anyhow:: Error :: msg (
46- "no valid endpoint found, can't build the request" . to_string ( ) ,
47- ) ) ,
56+ None => {
57+ error ! ( "No valid telemetry endpoint found, cannot build request" ) ;
58+ Err ( anyhow:: Error :: msg (
59+ "no valid endpoint found, can't build the request" . to_string ( ) ,
60+ ) )
61+ }
4862 }
4963}
5064
@@ -54,6 +68,10 @@ pub fn from_config(c: &Config) -> Box<dyn HttpClient + Sync + Send> {
5468 #[ allow( clippy:: expect_used) ]
5569 let file_path = ddcommon:: decode_uri_path_in_authority ( & e. url )
5670 . expect ( "file urls should always have been encoded in authority" ) ;
71+ info ! (
72+ file. path = ?file_path,
73+ "Using file-based mock telemetry client"
74+ ) ;
5775 return Box :: new ( MockClient {
5876 #[ allow( clippy:: expect_used) ]
5977 file : Arc :: new ( Mutex :: new ( Box :: new (
@@ -65,7 +83,19 @@ pub fn from_config(c: &Config) -> Box<dyn HttpClient + Sync + Send> {
6583 ) ) ) ,
6684 } ) ;
6785 }
68- Some ( _) | None => { }
86+ Some ( e) => {
87+ info ! (
88+ endpoint. url = %e. url,
89+ endpoint. timeout_ms = e. timeout_ms,
90+ "Using HTTP telemetry client"
91+ ) ;
92+ }
93+ None => {
94+ warn ! (
95+ endpoint = "default" ,
96+ "No telemetry endpoint configured, using default HTTP client"
97+ ) ;
98+ }
6999 } ;
70100 Box :: new ( HyperClient {
71101 inner : hyper_migration:: new_client_periodic ( ) ,
@@ -78,8 +108,28 @@ pub struct HyperClient {
78108
79109impl HttpClient for HyperClient {
80110 fn request ( & self , req : hyper_migration:: HttpRequest ) -> ResponseFuture {
111+ debug ! (
112+ "Sending HTTP request via HyperClient"
113+ ) ;
81114 let resp = self . inner . request ( req) ;
82- Box :: pin ( async { Ok ( hyper_migration:: into_response ( resp. await ?) ) } )
115+ Box :: pin ( async move {
116+ match resp. await {
117+ Ok ( response) => {
118+ debug ! (
119+ http. status = response. status( ) . as_u16( ) ,
120+ "HTTP request completed successfully"
121+ ) ;
122+ Ok ( hyper_migration:: into_response ( response) )
123+ }
124+ Err ( e) => {
125+ error ! (
126+ error = %e,
127+ "HTTP request failed"
128+ ) ;
129+ Err ( e. into ( ) )
130+ }
131+ }
132+ } )
83133 }
84134}
85135
@@ -92,16 +142,35 @@ impl HttpClient for MockClient {
92142 fn request ( & self , req : hyper_migration:: HttpRequest ) -> ResponseFuture {
93143 let s = self . clone ( ) ;
94144 Box :: pin ( async move {
145+ debug ! (
146+ "MockClient writing request to file"
147+ ) ;
95148 let mut body = req. collect ( ) . await ?. to_bytes ( ) . to_vec ( ) ;
96149 body. push ( b'\n' ) ;
97150
98151 {
99152 #[ allow( clippy:: expect_used) ]
100153 let mut writer = s. file . lock ( ) . expect ( "mutex poisoned" ) ;
101154
102- writer. write_all ( body. as_ref ( ) ) ?;
155+ match writer. write_all ( body. as_ref ( ) ) {
156+ Ok ( ( ) ) => debug ! (
157+ file. bytes_written = body. len( ) ,
158+ "Successfully wrote payload to mock file"
159+ ) ,
160+ Err ( e) => {
161+ error ! (
162+ error = %e,
163+ "Failed to write to mock file"
164+ ) ;
165+ return Err ( e. into ( ) ) ;
166+ }
167+ }
103168 }
104169
170+ debug ! (
171+ http. status = 202 ,
172+ "MockClient returning success response"
173+ ) ;
105174 hyper_migration:: empty_response ( hyper:: Response :: builder ( ) . status ( 202 ) )
106175 } )
107176 }
0 commit comments