ahri_tre_app/
browser_observation.rs1use ahri_tre_observability::{CorrelationContext, FailureCategory, Outcome, Stage};
3use ahri_tre_protocol::{ProtocolError, ProtocolErrorCode};
4
5pub fn observe_browser_workflow<T>(
7 context: &CorrelationContext,
8 workflow: impl FnOnce(&CorrelationContext) -> Result<T, Box<ProtocolError>>,
9) -> Result<T, Box<ProtocolError>> {
10 let span = context.span(Stage::Application);
11 let result = workflow(&span.context());
12 let (outcome, category) = match result.as_ref().err().map(|error| error.code) {
13 None => (Outcome::Success, None),
14 Some(ProtocolErrorCode::Unauthorized) => {
15 (Outcome::Rejected, Some(FailureCategory::Authentication))
16 }
17 Some(ProtocolErrorCode::Forbidden) => {
18 (Outcome::Rejected, Some(FailureCategory::Authorization))
19 }
20 Some(ProtocolErrorCode::OperationFailed) => {
21 (Outcome::Unavailable, Some(FailureCategory::Dependency))
22 }
23 Some(ProtocolErrorCode::Internal) => {
24 (Outcome::InternalFailure, Some(FailureCategory::Internal))
25 }
26 Some(_) => (Outcome::Rejected, None),
27 };
28 span.finish(outcome, category);
29 result
30}