Use 'tracing' framework for logs and Sentry breadcrumbs
- Sep 24, 2024
-
-
vlorentz authored
This allows linking errors to previous log events that happened. For example, if I add this to the code to the Traverse method: ``` if request.get_ref().src == ["swh:1:rev:57012c57536f8814dec92e74197ee96c3498d24e"] { use tokio::time::{sleep, Duration}; sleep(Duration::from_millis(10000)).await; tracing::error!("oh no traverse"); } ``` and send two requests to traverse, first from swh:1:rev:57012c57536f8814dec92e74197ee96c3498d24e, then from swh:1:rev:0000000000000000000000000000000000000003, this will display this in logs: ``` 2024-09-17T09:28:33.157323Z INFO request{id=0}:traverse: swh_graph_grpc_server: TraversalRequest { src: ["swh:1:rev:57012c57536f8814dec92e74197ee96c3498d24e"], direction: Forward, edges: None, max_edges: Some(1000000), min_depth: None, max_depth: None, return_nodes: None, mask: Some(FieldMask { paths: ["swhid"] }), max_matching_nodes: None } 2024-09-17T09:28:35.022307Z INFO request{id=1}:traverse: swh_graph_grpc_server: TraversalRequest { src: ["swh:1:rev:0000000000000000000000000000000000000003"], direction: Forward, edges: None, max_edges: Some(1000000), min_depth: None, max_depth: None, return_nodes: None, mask: Some(FieldMask { paths: ["swhid"] }), max_matching_nodes: None } 2024-09-17T09:28:35.022778Z INFO request{id=1}: swh_graph_grpc_server: 200 OK - http://localhost:50091/swh.graph.TraversalService/Traverse - response: 333.458µs - streaming: 325.639µs 2024-09-17T09:28:43.158810Z ERROR request{id=0}:traverse: swh_graph_grpc_server: oh no traverse 2024-09-17T09:28:43.159228Z INFO request{id=0}:traverse: swh_graph_grpc_server: error=status: NotFound, message: "Unknown SWHID: swh:1:rev:57012c57536f8814dec92e74197ee96c3498d24e", details: [], metadata: MetadataMap { headers: {} } 2024-09-17T09:28:43.159698Z INFO request{id=0}: swh_graph_grpc_server: 200 OK - http://localhost:50091/swh.graph.TraversalService/Traverse - response: 10.002514102s - streaming: 5.486µs ``` and Sentry will correctly show only `TraversalRequest { src: ["swh:1:rev:57012c57536f8814dec92e74197ee96c3498d24e"], ... }` in the breadcrumbs of the error, not `TraversalRequest { src: ["swh:1:rev:0000000000000000000000000000000000000003"], ... }`
-