AXIAM C++ SDK 1.0.0-alpha8
Authentication, authorization, JWKS & route guards (REST + mTLS)
Loading...
Searching...
No Matches
telemetry.hpp
Go to the documentation of this file.
1// axiam telemetry hooks — CONTRACT.md §19.
2//
3// An optional callback surface so a caller can wire OpenTelemetry, Prometheus
4// or a log line WITHOUT this library depending on any of them. Install one with
5// `Client::Builder::telemetry_hook`; with none installed the cost is a single
6// empty-std::function check per request.
7//
8// Two of §19.2's rules are enforced by the shape of this header rather than left
9// to documentation:
10//
11// * No secrets, ever (rule 3). `TelemetryEvent` is a `std::variant` over the
12// five structs below, each with a fixed member list and no map. The variant
13// is closed by construction — a caller cannot add a sixth alternative — so
14// "there is nowhere to put a token in a payload bound for a metrics backend"
15// is checkable by reading one declaration rather than trusting a review.
16// * No cost when uninstalled (rule 1). Nothing here allocates; building an
17// event is a handful of string copies taken only when a hook exists.
18#pragma once
19
20#include <chrono>
21#include <cstdint>
22#include <functional>
23#include <optional>
24#include <string>
25#include <variant>
26
27namespace axiam {
28
30enum class Outcome {
35};
36
38enum class RefreshRole {
40 kLeader,
43};
44
48 std::string operation;
50 std::string method;
53 std::string path_template;
55 int attempt = 1;
56};
57
60 std::string operation;
61 std::string method;
62 std::string path_template;
63 int attempt = 1;
65 std::optional<long> status;
67 std::chrono::milliseconds duration{0};
69};
70
76struct RetryEvent {
77 std::string operation;
79 int attempt = 1;
81 std::chrono::milliseconds delay{0};
84 std::string reason;
85};
86
90 std::chrono::milliseconds duration{0};
91};
92
108 std::string setting;
110 std::string requested;
112 std::string effective;
115};
116
125
134using TelemetryHook = std::function<void(const TelemetryEvent&)>;
135
136} // namespace axiam
Definition authenticator.hpp:40
std::variant< RequestStartEvent, RequestEndEvent, RetryEvent, RefreshEvent, ConfigClampedEvent > TelemetryEvent
One §19.1 event.
Definition telemetry.hpp:124
Outcome
Why a request finished.
Definition telemetry.hpp:30
@ kFailure
The call failed, at any layer.
@ kSuccess
The call returned a usable response.
RefreshRole
Whether this caller performed a §9 refresh or waited on another thread's.
Definition telemetry.hpp:38
@ kFollower
This caller waited on another thread's refresh.
@ kLeader
This caller performed the refresh.
std::function< void(const TelemetryEvent &)> TelemetryHook
A caller-supplied telemetry sink (§19).
Definition telemetry.hpp:134
Emitted at client construction, once per caller-supplied setting the SDK clamped (§19....
Definition telemetry.hpp:106
std::string contract_reference
The §-reference for the limit, e.g. §17.1 rule 2.
Definition telemetry.hpp:114
std::string effective
The value actually in force, rendered.
Definition telemetry.hpp:112
std::string setting
The builder setting's name, e.g. decision_memo_ttl.
Definition telemetry.hpp:108
std::string requested
The value the caller asked for, rendered.
Definition telemetry.hpp:110
Emitted around a §9 single-flight refresh.
Definition telemetry.hpp:88
RefreshRole role
Definition telemetry.hpp:89
std::chrono::milliseconds duration
Definition telemetry.hpp:90
Emitted after a call completes, success or failure.
Definition telemetry.hpp:59
std::chrono::milliseconds duration
Wall-clock time this attempt took.
Definition telemetry.hpp:67
Outcome outcome
Definition telemetry.hpp:68
std::string operation
Definition telemetry.hpp:60
std::optional< long > status
HTTP status, or std::nullopt when the call never got a response.
Definition telemetry.hpp:65
std::string path_template
Definition telemetry.hpp:62
std::string method
Definition telemetry.hpp:61
int attempt
Definition telemetry.hpp:63
Emitted before an outbound call leaves the SDK.
Definition telemetry.hpp:46
std::string operation
Canonical operation name, e.g. check_access.
Definition telemetry.hpp:48
int attempt
1 for the first try, incrementing per §16 retry.
Definition telemetry.hpp:55
std::string method
HTTP method.
Definition telemetry.hpp:50
std::string path_template
The route CONSTANT — /api/v1/authz/check, never a URL with ids substituted in.
Definition telemetry.hpp:53
Emitted before each §16 retry wait.
Definition telemetry.hpp:76
std::string reason
A redacted description of the failure.
Definition telemetry.hpp:84
std::chrono::milliseconds delay
The wait about to be taken, after jitter and any Retry-After.
Definition telemetry.hpp:81
int attempt
The attempt that just failed.
Definition telemetry.hpp:79
std::string operation
Definition telemetry.hpp:77