@@ -41,13 +41,15 @@ pub(crate) struct ParsingInfo {
41
41
}
42
42
43
43
impl ParsingInfo {
44
+ #[ tracing:: instrument( level = "debug" , ret( skip) , skip( self , message) ) ]
44
45
pub fn append_deprecation_message ( & mut self , message : & str ) {
45
46
match self . deprecation_message . as_mut ( ) {
46
47
None => self . deprecation_message = Some ( message. to_owned ( ) ) ,
47
48
Some ( s) => ( * s) . push_str ( message) ,
48
49
}
49
50
}
50
51
52
+ #[ tracing:: instrument( level = "debug" , ret( skip) , skip( self ) ) ]
51
53
pub fn take_deprecation_message ( & mut self ) -> Option < String > {
52
54
self . deprecation_message . take ( )
53
55
}
@@ -61,6 +63,7 @@ pub(crate) struct ParsedRequest {
61
63
62
64
impl TryFrom < & Request > for ParsedRequest {
63
65
type Error = Error ;
66
+ #[ tracing:: instrument( level = "debug" , ret( skip) , skip( request) ) ]
64
67
fn try_from ( request : & Request ) -> Result < Self , Self :: Error > {
65
68
let request_uri = request. uri ( ) . get_abs_path ( ) . to_string ( ) ;
66
69
log_received_api_request ( describe (
@@ -121,21 +124,25 @@ impl TryFrom<&Request> for ParsedRequest {
121
124
}
122
125
123
126
impl ParsedRequest {
127
+ #[ tracing:: instrument( level = "debug" , ret( skip) , skip( action) ) ]
124
128
pub ( crate ) fn new ( action : RequestAction ) -> Self {
125
129
Self {
126
130
action,
127
131
parsing_info : Default :: default ( ) ,
128
132
}
129
133
}
130
134
135
+ #[ tracing:: instrument( level = "debug" , ret( skip) , skip( self ) ) ]
131
136
pub ( crate ) fn into_parts ( self ) -> ( RequestAction , ParsingInfo ) {
132
137
( self . action , self . parsing_info )
133
138
}
134
139
140
+ #[ tracing:: instrument( level = "debug" , skip( self ) ) ]
135
141
pub ( crate ) fn parsing_info ( & mut self ) -> & mut ParsingInfo {
136
142
& mut self . parsing_info
137
143
}
138
144
145
+ #[ tracing:: instrument( level = "debug" , ret( skip) , skip( body_data) ) ]
139
146
pub ( crate ) fn success_response_with_data < T > ( body_data : & T ) -> Response
140
147
where
141
148
T : ?Sized + Serialize + Debug ,
@@ -146,6 +153,7 @@ impl ParsedRequest {
146
153
response
147
154
}
148
155
156
+ #[ tracing:: instrument( level = "debug" , ret( skip) , skip( body_data) ) ]
149
157
pub ( crate ) fn success_response_with_mmds_value ( body_data : & Value ) -> Response {
150
158
info ! ( "The request was executed successfully. Status code: 200 OK." ) ;
151
159
let mut response = Response :: new ( Version :: Http11 , StatusCode :: OK ) ;
@@ -157,6 +165,7 @@ impl ParsedRequest {
157
165
response
158
166
}
159
167
168
+ #[ tracing:: instrument( level = "debug" , ret( skip) , skip( request_outcome) ) ]
160
169
pub ( crate ) fn convert_to_response (
161
170
request_outcome : & std:: result:: Result < VmmData , VmmActionError > ,
162
171
) -> Response {
@@ -206,6 +215,7 @@ impl ParsedRequest {
206
215
}
207
216
208
217
/// Helper function to avoid boiler-plate code.
218
+ #[ tracing:: instrument( level = "debug" , ret( skip) , skip( vmm_action) ) ]
209
219
pub ( crate ) fn new_sync ( vmm_action : VmmAction ) -> ParsedRequest {
210
220
ParsedRequest :: new ( RequestAction :: Sync ( Box :: new ( vmm_action) ) )
211
221
}
@@ -215,6 +225,7 @@ impl ParsedRequest {
215
225
///
216
226
/// The `info` macro is used for logging.
217
227
#[ inline]
228
+ #[ tracing:: instrument( level = "debug" , ret( skip) , skip( api_description) ) ]
218
229
fn log_received_api_request ( api_description : String ) {
219
230
info ! ( "The API server received a {}." , api_description) ;
220
231
}
@@ -226,6 +237,7 @@ fn log_received_api_request(api_description: String) {
226
237
/// * `method` - one of `GET`, `PATCH`, `PUT`
227
238
/// * `path` - path of the API request
228
239
/// * `body` - body of the API request
240
+ #[ tracing:: instrument( level = "debug" , ret( skip) , skip( method, path, body) ) ]
229
241
fn describe ( method : Method , path : & str , body : Option < & Body > ) -> String {
230
242
match ( path, body) {
231
243
( "/mmds" , Some ( _) ) | ( _, None ) => format ! ( "{:?} request on {:?}" , method, path) ,
@@ -234,6 +246,7 @@ fn describe(method: Method, path: &str, body: Option<&Body>) -> String {
234
246
}
235
247
}
236
248
249
+ #[ tracing:: instrument( level = "debug" , ret( skip) , skip( method, path, payload_value) ) ]
237
250
fn describe_with_body ( method : Method , path : & str , payload_value : & Body ) -> String {
238
251
format ! (
239
252
"{:?} request on {:?} with body {:?}" ,
@@ -246,6 +259,7 @@ fn describe_with_body(method: Method, path: &str, payload_value: &Body) -> Strin
246
259
}
247
260
248
261
/// Generates a `GenericError` for each request method.
262
+ #[ tracing:: instrument( level = "debug" , ret( skip) , skip( method) ) ]
249
263
pub ( crate ) fn method_to_error ( method : Method ) -> Result < ParsedRequest , Error > {
250
264
match method {
251
265
Method :: Get => Err ( Error :: Generic (
@@ -284,6 +298,7 @@ pub(crate) enum Error {
284
298
285
299
// It's convenient to turn errors into HTTP responses directly.
286
300
impl From < Error > for Response {
301
+ #[ tracing:: instrument( level = "debug" , ret( skip) , skip( err) ) ]
287
302
fn from ( err : Error ) -> Self {
288
303
let msg = ApiServer :: json_fault_message ( format ! ( "{}" , err) ) ;
289
304
match err {
@@ -297,6 +312,7 @@ impl From<Error> for Response {
297
312
}
298
313
299
314
// This function is supposed to do id validation for requests.
315
+ #[ tracing:: instrument( level = "debug" , ret( skip) , skip( id) ) ]
300
316
pub ( crate ) fn checked_id ( id : & str ) -> Result < & str , Error > {
301
317
// todo: are there any checks we want to do on id's?
302
318
// not allow them to be empty strings maybe?
@@ -329,6 +345,7 @@ pub mod tests {
329
345
use super :: * ;
330
346
331
347
impl PartialEq for ParsedRequest {
348
+ #[ tracing:: instrument( level = "debug" , ret( skip) , skip( self , other) ) ]
332
349
fn eq ( & self , other : & ParsedRequest ) -> bool {
333
350
if self . parsing_info . deprecation_message != other. parsing_info . deprecation_message {
334
351
return false ;
@@ -343,13 +360,15 @@ pub mod tests {
343
360
}
344
361
}
345
362
363
+ #[ tracing:: instrument( level = "debug" , ret( skip) , skip( req) ) ]
346
364
pub ( crate ) fn vmm_action_from_request ( req : ParsedRequest ) -> VmmAction {
347
365
match req. action {
348
366
RequestAction :: Sync ( vmm_action) => * vmm_action,
349
367
_ => panic ! ( "Invalid request" ) ,
350
368
}
351
369
}
352
370
371
+ #[ tracing:: instrument( level = "debug" , ret( skip) , skip( req, msg) ) ]
353
372
pub ( crate ) fn depr_action_from_req ( req : ParsedRequest , msg : Option < String > ) -> VmmAction {
354
373
let ( action_req, mut parsing_info) = req. into_parts ( ) ;
355
374
match action_req {
@@ -363,6 +382,7 @@ pub mod tests {
363
382
}
364
383
}
365
384
385
+ #[ tracing:: instrument( level = "debug" , ret( skip) , skip( body, status_code) ) ]
366
386
fn http_response ( body : & str , status_code : i32 ) -> String {
367
387
let header = format ! (
368
388
"HTTP/1.1 {} \r \n Server: Firecracker API\r \n Connection: keep-alive\r \n " ,
@@ -382,6 +402,7 @@ pub mod tests {
382
402
}
383
403
}
384
404
405
+ #[ tracing:: instrument( level = "debug" , ret( skip) , skip( request_type, endpoint, body) ) ]
385
406
fn http_request ( request_type : & str , endpoint : & str , body : Option < & str > ) -> String {
386
407
let req_no_body = format ! (
387
408
"{} {} HTTP/1.1\r \n Content-Type: application/json\r \n " ,
0 commit comments