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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
use crate::;
///
/// Access-layer metrics façade.
///
/// WHY THIS FILE EXISTS
/// ---------------------
/// This module intentionally sits at the *access layer* boundary and serves
/// as the **only approved way** for access predicates and macro-expanded
/// endpoints to emit metrics.
///
/// It exists to enforce the following architectural invariants:
///
/// 1. **Layering discipline**
/// Access logic MUST NOT depend directly on ops/runtime metric backends.
/// All metric emission from access control flows through this façade.
///
/// 2. **Stable call surface**
/// Endpoint identity, metric kinds, and authority attribution are
/// intentionally normalized here so internal metric schemas may evolve
/// without touching callers.
///
/// 3. **Future-proofing**
/// This layer is the designated place to introduce:
/// - metric sampling or rate limiting
/// - cardinality controls
/// - backend changes (heap → stable → off-canister)
/// - lifecycle validation (attempted → completed → result)
///
/// If this file appears "thin", that is by design.
/// DO NOT bypass it by calling ops::runtime::metrics directly.
///
///
/// AccessMetrics
///
/// Access-denial metrics by predicate kind and name.
///
/// Invariants:
/// - Emitted only on denial and represent the kind where access failed.
/// - Called exactly once per denied request.
/// - Cardinality is bounded by endpoint name + kind + predicate name.
/// - Custom predicates are attributed to AccessMetricKind::Custom.
///
;
///
/// EndpointAttemptMetrics
///
/// Endpoint lifecycle metrics.
///
/// These metrics describe execution flow, not authorization:
/// attempted -> completed -> (ok | err)
///
;
///
/// EndpointResultMetrics
///
/// Endpoint result metrics (success vs failure).
///
/// These metrics intentionally exclude error causes; those belong in logs.
///
;
///
/// DelegationMetrics
///
/// Delegated authorization authority metrics.
///
/// Records which delegation authority (cert signer) was used to
/// successfully validate a delegated token.
///
/// WHY THIS LIVES HERE:
/// - Access predicates are the *only* place where delegation validity is known.
/// - Downstream layers must not infer authority from request context.
/// - This ensures cryptographic attribution remains tightly scoped.
///
/// Invariants:
/// - Called only after cryptographic verification succeeds.
/// - Must not be called on denied or partially-verified tokens.
/// - Cardinality is bounded by active delegation authorities.
///
;