cloud_sdk/diagnostics/
event.rs1use crate::operation::{OperationId, OperationImpact, PreparedRequest};
2use crate::transport::StatusCode;
3use crate::{ProviderId, ServiceId};
4
5use super::{DiagnosticErrorCategory, DiagnosticRequestId, DiagnosticRetryCategory};
6
7#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
9pub struct DiagnosticContext {
10 provider: ProviderId,
11 service: ServiceId,
12 operation: Option<OperationId>,
13 impact: OperationImpact,
14 retry: DiagnosticRetryCategory,
15}
16
17impl DiagnosticContext {
18 pub(crate) const fn new(
19 provider: ProviderId,
20 service: ServiceId,
21 operation: Option<OperationId>,
22 impact: OperationImpact,
23 retry: DiagnosticRetryCategory,
24 ) -> Self {
25 Self {
26 provider,
27 service,
28 operation,
29 impact,
30 retry,
31 }
32 }
33
34 pub(crate) fn from_prepared(prepared: &PreparedRequest<'_>) -> Self {
35 let service = prepared.service();
36 Self::new(
37 service.provider_id(),
38 service.service_id(),
39 prepared.operation_id(),
40 prepared.metadata().impact(),
41 prepared.metadata().retry_eligibility().into(),
42 )
43 }
44
45 #[must_use]
47 pub const fn provider(self) -> ProviderId {
48 self.provider
49 }
50
51 #[must_use]
53 pub const fn service(self) -> ServiceId {
54 self.service
55 }
56
57 #[must_use]
59 pub const fn operation(self) -> Option<OperationId> {
60 self.operation
61 }
62
63 #[must_use]
65 pub const fn impact(self) -> OperationImpact {
66 self.impact
67 }
68
69 #[must_use]
71 pub const fn retry(self) -> DiagnosticRetryCategory {
72 self.retry
73 }
74}
75
76#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
78pub struct DiagnosticResponse {
79 status: StatusCode,
80 request_id: DiagnosticRequestId,
81}
82
83impl DiagnosticResponse {
84 pub(crate) const fn new(status: StatusCode, request_id: DiagnosticRequestId) -> Self {
85 Self { status, request_id }
86 }
87
88 #[must_use]
90 pub const fn status(self) -> StatusCode {
91 self.status
92 }
93
94 #[must_use]
96 pub const fn request_id(self) -> DiagnosticRequestId {
97 self.request_id
98 }
99}
100
101#[derive(Clone, Copy, Debug, Eq, PartialEq)]
103pub enum DiagnosticEvent {
104 PreparationStarted,
106 PreparationFailed {
108 error: DiagnosticErrorCategory,
110 },
111 RequestPrepared {
113 context: DiagnosticContext,
115 },
116 DispatchStarted {
118 context: DiagnosticContext,
120 },
121 ExecutionFailed {
123 context: DiagnosticContext,
125 error: DiagnosticErrorCategory,
127 },
128 ResponseReceived {
130 context: DiagnosticContext,
132 response: DiagnosticResponse,
134 },
135 DecodeFailed {
137 context: DiagnosticContext,
139 response: Option<DiagnosticResponse>,
141 error: DiagnosticErrorCategory,
143 },
144 Completed {
146 context: DiagnosticContext,
148 response: Option<DiagnosticResponse>,
150 },
151}