1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//! Helpers for surfacing inbound DIDComm problem-reports in the logs.
//!
//! Problem-reports arrive as ordinary DIDComm messages; without explicit
//! handling they fall into the generic "unknown message type" bucket and
//! the diagnostic information they carry (`code`, `comment`, `args`,
//! `pthid`) is silently discarded. This module gives every DID Hosting service a
//! consistent way to log them.
use affinidi_tdk::didcomm::Message;
use tracing::warn;
/// True if `msg_type` is either the standard DIDComm v2 `report-problem`
/// type (`https://didcomm.org/report-problem/2.0/problem-report`) or a
/// WebVH-specific `*/problem-report` variant.
pub fn is_problem_report(msg_type: &str) -> bool {
msg_type.contains("/problem-report") || msg_type.contains("/report-problem/")
}
/// Log an inbound problem-report at WARN with all useful diagnostic fields.
///
/// `service` is the short name of the receiving service (e.g. `"server"`,
/// `"control"`, `"witness"`) so multi-service log streams are easy to
/// disambiguate. Returns `true` if the message was a problem-report (and
/// was logged), so callers can short-circuit their fallback handler.
pub fn log_problem_report(service: &str, sender: Option<&str>, message: &Message) -> bool {
if !is_problem_report(&message.typ) {
return false;
}
let code = message
.body
.get("code")
.and_then(|v| v.as_str())
.unwrap_or("(none)");
let comment = message
.body
.get("comment")
.and_then(|v| v.as_str())
.unwrap_or("(none)");
let args = message
.body
.get("args")
.map(|v| v.to_string())
.unwrap_or_else(|| "(none)".into());
let escalate_to = message
.body
.get("escalate_to")
.and_then(|v| v.as_str())
.unwrap_or("(none)");
warn!(
service,
msg_type = %message.typ,
sender = sender.unwrap_or("unknown"),
msg_id = %message.id,
thid = message.thid.as_deref().unwrap_or("(none)"),
pthid = message.pthid.as_deref().unwrap_or("(none)"),
code = code,
comment = comment,
args = %args,
escalate_to = escalate_to,
"DIDComm problem-report received"
);
true
}