|
36 | 36 | const path_to_root = "../"; |
37 | 37 | const default_light_theme = "light"; |
38 | 38 | const default_dark_theme = "navy"; |
39 | | - window.path_to_searchindex_js = "../searchindex-af852796.js"; |
| 39 | + window.path_to_searchindex_js = "../searchindex-b8492182.js"; |
40 | 40 | </script> |
41 | 41 | <!-- Start loading toc.js asap --> |
42 | 42 | <script src="../toc-5ece1d58.js"></script> |
@@ -196,6 +196,7 @@ <h2 id="feature-flags"><a class="header" href="#feature-flags">Feature Flags</a> |
196 | 196 | <tr><td><code>cors</code></td><td><code>CorsLayer</code></td></tr> |
197 | 197 | <tr><td><code>csrf</code></td><td><code>CsrfLayer</code>, <code>CsrfToken</code> extractor</td></tr> |
198 | 198 | <tr><td><code>audit</code></td><td><code>AuditStore</code>, <code>AuditLogger</code></td></tr> |
| 199 | +<tr><td><code>insight</code></td><td><code>InsightLayer</code>, <code>InsightStore</code></td></tr> |
199 | 200 | <tr><td><code>rate-limit</code></td><td><code>RateLimitLayer</code></td></tr> |
200 | 201 | </tbody> |
201 | 202 | </table> |
@@ -258,6 +259,34 @@ <h2 id="audit-logging"><a class="header" href="#audit-logging">Audit Logging</a> |
258 | 259 | ); |
259 | 260 | } |
260 | 261 | <span class="boring">}</span></code></pre> |
| 262 | +<h2 id="traffic-insight"><a class="header" href="#traffic-insight">Traffic Insight</a></h2> |
| 263 | +<p>The <code>insight</code> feature provides powerful real-time traffic analysis and debugging capabilities without external dependencies. It is designed to be low-overhead and privacy-conscious.</p> |
| 264 | +<pre><code class="language-toml">[dependencies] |
| 265 | +rustapi-extras = { version = "0.1", features = ["insight"] } |
| 266 | +</code></pre> |
| 267 | +<h3 id="setup"><a class="header" href="#setup">Setup</a></h3> |
| 268 | +<pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)] |
| 269 | +</span><span class="boring">fn main() { |
| 270 | +</span>use rustapi_extras::insight::{InsightLayer, InMemoryInsightStore, InsightConfig}; |
| 271 | +use std::sync::Arc; |
| 272 | + |
| 273 | +let store = Arc::new(InMemoryInsightStore::new()); |
| 274 | +let config = InsightConfig::default(); |
| 275 | + |
| 276 | +let app = RustApi::new() |
| 277 | + .layer(InsightLayer::new(config, store.clone())); |
| 278 | +<span class="boring">}</span></code></pre> |
| 279 | +<h3 id="accessing-data"><a class="header" href="#accessing-data">Accessing Data</a></h3> |
| 280 | +<p>You can inspect the collected data (e.g., via an admin dashboard):</p> |
| 281 | +<pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)] |
| 282 | +</span><span class="boring">fn main() { |
| 283 | +</span>#[rustapi_rs::get("/admin/insights")] |
| 284 | +async fn get_insights(State(store): State<Arc<InMemoryInsightStore>>) -> Json<InsightStats> { |
| 285 | + // Returns aggregated stats like req/sec, error rates, p99 latency |
| 286 | + Json(store.get_stats().await) |
| 287 | +} |
| 288 | +<span class="boring">}</span></code></pre> |
| 289 | +<p>The <code>InsightStore</code> trait allows you to implement custom backends (e.g., ClickHouse or Elasticsearch) if you need long-term retention.</p> |
261 | 290 |
|
262 | 291 | </main> |
263 | 292 |
|
|
0 commit comments