@@ -12,6 +12,7 @@ use std::{
12
12
} ;
13
13
14
14
use crate :: config:: Config ;
15
+ use tracing:: { debug, error, info, warn} ;
15
16
16
17
pub mod header {
17
18
#![ allow( clippy:: declare_interior_mutable_const) ]
@@ -35,16 +36,29 @@ pub trait HttpClient {
35
36
pub fn request_builder ( c : & Config ) -> anyhow:: Result < HttpRequestBuilder > {
36
37
match & c. endpoint {
37
38
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
+ ) ;
38
45
let mut builder =
39
46
e. to_request_builder ( concat ! ( "telemetry/" , env!( "CARGO_PKG_VERSION" ) ) ) ;
40
47
if c. debug_enabled {
48
+ debug ! (
49
+ telemetry. debug_enabled = true ,
50
+ "Telemetry debug mode enabled"
51
+ ) ;
41
52
builder = Ok ( builder?. header ( header:: DEBUG_ENABLED , "true" ) )
42
53
}
43
54
builder
44
55
}
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
+ }
48
62
}
49
63
}
50
64
@@ -54,6 +68,10 @@ pub fn from_config(c: &Config) -> Box<dyn HttpClient + Sync + Send> {
54
68
#[ allow( clippy:: expect_used) ]
55
69
let file_path = ddcommon:: decode_uri_path_in_authority ( & e. url )
56
70
. 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
+ ) ;
57
75
return Box :: new ( MockClient {
58
76
#[ allow( clippy:: expect_used) ]
59
77
file : Arc :: new ( Mutex :: new ( Box :: new (
@@ -65,7 +83,19 @@ pub fn from_config(c: &Config) -> Box<dyn HttpClient + Sync + Send> {
65
83
) ) ) ,
66
84
} ) ;
67
85
}
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
+ }
69
99
} ;
70
100
Box :: new ( HyperClient {
71
101
inner : hyper_migration:: new_client_periodic ( ) ,
@@ -78,8 +108,28 @@ pub struct HyperClient {
78
108
79
109
impl HttpClient for HyperClient {
80
110
fn request ( & self , req : hyper_migration:: HttpRequest ) -> ResponseFuture {
111
+ debug ! (
112
+ "Sending HTTP request via HyperClient"
113
+ ) ;
81
114
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
+ } )
83
133
}
84
134
}
85
135
@@ -92,16 +142,35 @@ impl HttpClient for MockClient {
92
142
fn request ( & self , req : hyper_migration:: HttpRequest ) -> ResponseFuture {
93
143
let s = self . clone ( ) ;
94
144
Box :: pin ( async move {
145
+ debug ! (
146
+ "MockClient writing request to file"
147
+ ) ;
95
148
let mut body = req. collect ( ) . await ?. to_bytes ( ) . to_vec ( ) ;
96
149
body. push ( b'\n' ) ;
97
150
98
151
{
99
152
#[ allow( clippy:: expect_used) ]
100
153
let mut writer = s. file . lock ( ) . expect ( "mutex poisoned" ) ;
101
154
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
+ }
103
168
}
104
169
170
+ debug ! (
171
+ http. status = 202 ,
172
+ "MockClient returning success response"
173
+ ) ;
105
174
hyper_migration:: empty_response ( hyper:: Response :: builder ( ) . status ( 202 ) )
106
175
} )
107
176
}
0 commit comments