Scoop API

scoop:scoop.http.client:0.1.0

src/observability/api.scoop

Selected production source · src/observability/api.scoop

1package scoop.http.client
3import scoop.http.HttpVersion
4import scoop.time.Instant
5import scoop.time.TimeMark
7/**
8 * A suspend observer of immutable call-event snapshots. Callbacks run outside the shared HTTP/2
9 * driver; callback failures participate in call failure and cleanup.
10 */
11public class HttpObserver public constructor(internal val onEvent: suspend (HttpCallEvent) -> Unit)
13/**
14 * The stage or progress change reported to the observer.
15 */
16public enum HttpCallEventKind {
17 /**
18 * A concrete request attempt has begun.
19 */
20 AttemptStarted,
21 /**
22 * A reusable or newly established connection has been acquired.
23 */
24 ConnectionAcquired,
25 /**
26 * Request headers reached their recorded send point.
27 */
28 RequestHeaders,
29 /**
30 * Outgoing body progress changed.
31 */
32 RequestProgress,
33 /**
34 * Informational, final, or cached response headers were received.
35 */
36 ResponseHeaders,
37 /**
38 * Incoming body progress changed.
39 */
40 ResponseProgress,
41 /**
42 * The attempt and its required cleanup completed or failed.
43 */
44 Completed
47/**
48 * Stable call identity for observers, with method, a redacted URL display, and a monotonic start
49 * mark.
50 */
51public class HttpCallInfo internal constructor(request: HttpRequest,
52 /**
53 * The monotonic start mark.
54 */
55 public val startedAt: TimeMark) {
56 /**
57 * The case-sensitive request method.
58 */
59 public val method: String = request.method
60 /**
61 * The origin followed by a redacted path marker; query, fragment, and user information are
62 * omitted.
63 */
64 public val urlDisplay: String = clientObservedUrl(request)
67/**
68 * Monotonic phase start and optional finish marks; unfinished phases retain None.
69 */
70public class HttpPhaseTiming internal constructor(
71 /**
72 * The monotonic start mark.
73 */
74 public val startedAt: TimeMark,
75 /**
76 * The monotonic completion mark, or None while still active.
77 */
78 public val finishedAt: TimeMark? = None)
80/**
81 * An immutable snapshot of actual attempt phases, connection facts, response status, and body-byte
82 * counters. Unperformed phases remain None.
83 */
84public class HttpAttemptMetrics internal constructor(call: ClientCall, observation: ClientObservation) {
85 /**
86 * The observed attempt number.
87 */
88 public val number: Long = observation.number
89 /**
90 * Why this attempt was made.
91 */
92 public val reason: HttpAttemptReason = observation.reason
93 /**
94 * The case-sensitive request method.
95 */
96 public val method: String = call.request.method
97 /**
98 * The origin followed by a redacted path marker; query, fragment, and user information are
99 * omitted.
100 */
101 public val urlDisplay: String = clientObservedUrl(call.request)
102 /**
103 * The monotonic start mark.
104 */
105 public val startedAt: TimeMark = observation.startedAt
106 /**
107 * The wall-clock timestamp sampled at the start of this attempt.
108 */
109 public val startedAtUtc: Instant = observation.startedAtUtc
110 /**
111 * The monotonic completion mark, or None while still active.
112 */
113 public val finishedAt: TimeMark? = observation.finishedAt
114 /**
115 * The wall-clock timestamp sampled at completion, or None while active.
116 */
117 public val finishedAtUtc: Instant? = observation.finishedAtUtc
118 /**
119 * Actual pool-capacity wait timing, when performed.
120 */
121 public val queue: HttpPhaseTiming? = observation.queue
122 /**
123 * Actual name-resolution timing, when performed.
124 */
125 public val resolve: HttpPhaseTiming? = observation.resolve
126 /**
127 * Actual TCP establishment timing, when performed.
128 */
129 public val connect: HttpPhaseTiming? = observation.connect
130 /**
131 * TLS timing for an HTTPS proxy, when performed.
132 */
133 public val proxyTls: HttpPhaseTiming? = observation.proxyTls
134 /**
135 * CONNECT or SOCKS5 handshake timing, when performed.
136 */
137 public val proxyHandshake: HttpPhaseTiming? = observation.proxyHandshake
138 /**
139 * TLS timing for the origin connection, when performed.
140 */
141 public val originTls: HttpPhaseTiming? = observation.originTls
142 /**
143 * The recorded outgoing-header milestone.
144 */
145 public val requestHeadersAt: TimeMark? = observation.requestHeadersAt
146 /**
147 * The wall-clock timestamp sampled when request headers reached the protocol layer.
148 */
149 public val requestHeadersAtUtc: Instant? = observation.requestHeadersAtUtc
150 /**
151 * The most recent informational, final, or cached response-header milestone.
152 */
153 public val responseHeadersAt: TimeMark? = observation.responseHeadersAt
154 /**
155 * The wall-clock timestamp of the most recent response-header milestone.
156 */
157 public val responseHeadersAtUtc: Instant? = observation.responseHeadersAtUtc
158 /**
159 * The network final-response-header milestone, excluding informational and cached heads.
160 */
161 public val finalResponseHeadersAt: TimeMark? = observation.finalResponseHeadersAt
162 /**
163 * The wall-clock timestamp of the network final-response-header milestone.
164 */
165 public val finalResponseHeadersAtUtc: Instant? = observation.finalResponseHeadersAtUtc
166 /**
167 * The first recorded incoming-response-byte milestone. Protocol sampling requires a client
168 * observer; request-only observation can leave this None on a shared connection.
169 */
170 public val firstResponseByteAt: TimeMark? = observation.firstResponseByteAt
171 /**
172 * The selected HTTP protocol version, once known.
173 */
174 public val version: HttpVersion? = observation.version
175 /**
176 * Whether an existing connection was reused, once known.
177 */
178 public val connectionReused: Boolean? = observation.connectionReused
179 /**
180 * The most recent informational, final, or cached response status, once available.
181 */
182 public val status: UInt? = observation.status
183 /**
184 * The response's cache/network origin.
185 */
186 public val cacheStatus: HttpCacheStatus = call.cacheStatus
187 /**
188 * Outgoing request body bytes transferred so far.
189 */
190 public val requestBodyBytes: Long = call.requestBodyBytes
191 /**
192 * Incoming body bytes before content decoding.
193 */
194 public val encodedResponseBodyBytes: Long = call.encodedResponseBodyBytes
195 /**
196 * Body bytes delivered after content decoding.
197 */
198 public val responseBodyBytes: Long = call.responseBodyBytes
201/**
202 * An observer event combining stable call information, an attempt snapshot, and any failure.
203 */
204public class HttpCallEvent internal constructor(
205 /**
206 * The event's phase or progress category.
207 */
208 public val kind: HttpCallEventKind,
209 /**
210 * Stable information about the logical call.
211 */
212 public val call: HttpCallInfo,
213 /**
214 * The immutable attempt snapshot at this event.
215 */
216 public val metrics: HttpAttemptMetrics,
217 /**
218 * The failure associated with the event, if any.
219 */
220 public val failure: Throwable?) {
221 /**
222 * Formats a compact summary using redacted URL information and observed metrics.
223 */
224 public fun formatSummary(): String = formatClientCallEvent(this)