@@ -3,6 +3,7 @@ use crate::syftbox::storage::WritePolicy;
33use crate :: syftbox:: types:: { RpcRequest , RpcResponse } ;
44use anyhow:: { anyhow, bail, Context , Result } ;
55use std:: path:: { Path , PathBuf } ;
6+ use tracing:: instrument;
67
78/// Request with its file path
89pub type RequestWithPath = ( PathBuf , RpcRequest ) ;
@@ -19,6 +20,7 @@ pub struct Endpoint {
1920
2021impl Endpoint {
2122 /// Create a new endpoint for a SyftBox app
23+ #[ instrument( skip( app) , fields( component = "rpc" , endpoint = %name) , err) ]
2224 pub fn new ( app : & SyftBoxApp , name : & str ) -> Result < Self > {
2325 let path = app. register_endpoint ( name) ?;
2426
@@ -31,13 +33,15 @@ impl Endpoint {
3133
3234 /// Check for request files in this endpoint (your own folder only)
3335 /// Requests are written by others TO you in datasites/your-email/app_data/<app>/rpc/<endpoint>/
36+ #[ instrument( skip( self ) , fields( component = "rpc" , endpoint = %self . name) , err) ]
3437 pub fn check_requests ( & self ) -> Result < Vec < ( PathBuf , RpcRequest ) > > {
3538 // Only check your own endpoint folder - this is where others write requests TO you
3639 self . check_requests_in_folder ( & self . path )
3740 }
3841
3942 /// Check for request files and return both successes and failures
4043 /// Returns (successful_requests, failed_requests)
44+ #[ instrument( skip( self ) , fields( component = "rpc" , endpoint = %self . name) , err) ]
4145 pub fn check_requests_with_failures (
4246 & self ,
4347 ) -> Result < ( Vec < RequestWithPath > , Vec < FailedRequest > ) > {
@@ -109,6 +113,12 @@ impl Endpoint {
109113 }
110114
111115 /// Send a response for a request
116+ #[ instrument( skip( self , request, response) , fields(
117+ component = "rpc" ,
118+ endpoint = %self . name,
119+ request_id = %request. id,
120+ status = %response. status_code
121+ ) , err) ]
112122 pub fn send_response (
113123 & self ,
114124 request_path : & Path ,
@@ -160,6 +170,13 @@ impl Endpoint {
160170 }
161171
162172 /// Create a request file (for sending requests to others)
173+ #[ instrument( skip( self , request) , fields(
174+ component = "rpc" ,
175+ endpoint = %self . name,
176+ request_id = %request. id,
177+ method = %request. method,
178+ recipient = %request. url
179+ ) , err) ]
163180 pub fn create_request ( & self , request : & RpcRequest ) -> Result < PathBuf > {
164181 let request_filename = format ! ( "{}.request" , request. id) ;
165182 let request_path = self . path . join ( request_filename) ;
@@ -183,6 +200,7 @@ impl Endpoint {
183200 /// Check for response files (when we sent a request and are waiting for response)
184201 /// Responses are in OTHER identity folders (where you wrote requests), NOT your own folder
185202 /// You write requests to datasites/their-email/, they write responses back there
203+ #[ instrument( skip( self ) , fields( component = "rpc" , endpoint = %self . name) , err) ]
186204 pub fn check_responses ( & self ) -> Result < Vec < ( PathBuf , RpcResponse ) > > {
187205 let mut responses = Vec :: new ( ) ;
188206
@@ -294,6 +312,7 @@ impl Endpoint {
294312 }
295313
296314 /// Clean up a response file after processing
315+ #[ instrument( skip( self ) , fields( component = "rpc" , endpoint = %self . name) , err) ]
297316 pub fn cleanup_response ( & self , response_path : & Path ) -> Result < ( ) > {
298317 self . app . storage . remove_path ( response_path) ?;
299318 Ok ( ( ) )
0 commit comments