Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
cf16418
Add request phase timing design spec and implementation plan (#1069)
jevansnyc Aug 25, 2026
052eada
Add RequestTimings phase collection and Server-Timing rendering
jevansnyc Aug 25, 2026
7505fb8
Add observability settings and decouple tinybird access and auction e…
jevansnyc Aug 25, 2026
4ce413f
Add test coverage for the access_enabled without tinybird.enabled rej…
jevansnyc Aug 25, 2026
f83092a
Emit Server-Timing at the send freeze point on conclusively private r…
jevansnyc Aug 25, 2026
4b19c44
Record filter and geo spans and dedupe the per-request geo lookup
jevansnyc Aug 25, 2026
ce295f1
Record origin, template cache, and KV phase spans in core
jevansnyc Aug 25, 2026
c222ae2
Capture stream duration, auction wait placement, and response bytes
jevansnyc Aug 25, 2026
8b028bb
Add access telemetry snapshot, route classes, and coarse route templates
jevansnyc Aug 25, 2026
48acd81
Emit confirmed access telemetry rows after pull-sync post-send
jevansnyc Aug 25, 2026
72d5755
Extend access_logs_raw with phase columns and a non-null sorting key
jevansnyc Aug 25, 2026
c50be03
Widen time_elapsed_ms to nullable so dropped snapshots cannot quarant…
jevansnyc Aug 25, 2026
0aead79
Emit Server-Timing from the Axum terminal layer with adapter-specific…
jevansnyc Aug 25, 2026
e9cf5b9
Document the observability and access telemetry configuration surface
jevansnyc Aug 25, 2026
7942c74
Normalize telemetry method, guard zero sample rate, and mirror geo wr…
jevansnyc Aug 26, 2026
d8fcb5e
Add a local dev config envelope generator example
jevansnyc Aug 26, 2026
7cf7d86
Add JSONPaths and expression sorting key to the access datasource
jevansnyc Aug 26, 2026
600746f
Use web_time Instant on request timing paths
jevansnyc Aug 26, 2026
3d7e697
Reject opaque identifier segments in publisher route templates
jevansnyc Aug 26, 2026
38043d7
Address access telemetry review feedback
jevansnyc Aug 26, 2026
2ef7635
Reject single-segment publisher paths in route templates
jevansnyc Aug 28, 2026
082461d
Sample access rows with real randomness at the snapshot rate
jevansnyc Aug 28, 2026
f3ee473
Drop the origin span before error-path auction telemetry
jevansnyc Aug 28, 2026
46b3c7f
Address remaining review feedback on timing surfaces and docs
jevansnyc Aug 28, 2026
a0a3af5
Merge remote-tracking branch 'origin/main' into feat/request-phase-ti…
ChristianPavilonis Aug 31, 2026
c6235b9
Enforce access telemetry body limit
ChristianPavilonis Aug 31, 2026
6f133cc
Merge origin/main into feat/request-phase-timing
jevansnyc Sep 8, 2026
bcc1475
Bound route templates by allowlist and harden the telemetry config su…
jevansnyc Sep 8, 2026
a152367
Address round-3 telemetry robustness findings
jevansnyc Sep 8, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions crates/trusted-server-adapter-axum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ path = "src/main.rs"

[dependencies]
async-trait = { workspace = true }
axum = { workspace = true }
edgezero-adapter-axum = { workspace = true, features = ["axum"] }
edgezero-core = { workspace = true }
error-stack = { workspace = true }
futures = { workspace = true }
log = { workspace = true }
reqwest = { workspace = true }
simple_logger = { workspace = true }
tokio = { workspace = true, features = ["rt-multi-thread", "macros", "sync", "time"] }
tokio = { workspace = true, features = ["rt-multi-thread", "macros", "net", "signal", "sync", "time"] }
tower = { workspace = true, features = ["util"] }
trusted-server-core = { workspace = true }

[dev-dependencies]
axum = { workspace = true }
base64 = { workspace = true }
temp-env = { workspace = true }
tokio = { workspace = true, features = ["rt-multi-thread", "macros"] }
tower = { workspace = true, features = ["util"] }
49 changes: 40 additions & 9 deletions crates/trusted-server-adapter-axum/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use core::future::Future;
use std::sync::Arc;

use edgezero_adapter_axum::service::EdgeZeroAxumService;
use edgezero_core::app::Hooks;
use edgezero_core::context::RequestContext;
use edgezero_core::error::EdgeError;
Expand Down Expand Up @@ -565,15 +566,7 @@ impl Hooks for TrustedServerApp {
}

fn routes() -> RouterService {
let state = match build_state() {
Ok(s) => s,
Err(ref e) => {
log::error!("failed to build application state: {:?}", e);
return startup_error_router(e);
}
};

build_router(&state)
Self::routes_with_server_timing_flag().0
Comment thread
aram356 marked this conversation as resolved.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 thinkingroutes() now discards the flag via .0, and dev_server_service() is the only path that wires TimingService. That is documented, but it does mean the framework's own entry point — edgezero_adapter_axum::dev_server::run_app::<A>(), which drives the app through Hooks — would produce a server with no Server-Timing at all, and nothing fails loudly if a future caller reaches for the trait method instead.

Latent rather than live, since main.rs is currently the sole caller of dev_server_service. Worth a line on Hooks::routes saying it exists for trait conformance and is not the serving path, so the next person wiring this adapter doesn't pick the wrong constructor and quietly lose the header.

}
}

Expand All @@ -594,6 +587,44 @@ impl TrustedServerApp {
let state = build_state_with_settings(settings)?;
Ok(build_router(&state))
}

/// The dev server's fully configured tower service: the application
/// router wrapped in the terminal timing layer
/// ([`crate::timing::TimingService`]), with `server_timing_enabled`
/// read from the same settings snapshot that built the router.
///
/// This is the standard construction path for serving this adapter.
/// [`Hooks::routes`] satisfies the `Hooks` trait contract and returns
/// the bare router without the timing layer; callers who serve traffic
/// should use this instead so `server_timing_enabled` is never
/// silently discarded.
#[must_use]
pub fn dev_server_service() -> crate::timing::TimingService<EdgeZeroAxumService> {
let (router, server_timing_enabled) = Self::routes_with_server_timing_flag();
crate::timing::TimingService::new(EdgeZeroAxumService::new(router), server_timing_enabled)
}

/// Build the router alongside whether `Server-Timing` emission is
/// enabled, read from the same settings snapshot used to build the
/// router.
///
/// The Axum dev server's terminal timing layer ([`crate::timing`]) needs
/// this flag once at startup: unlike the Fastly adapter, which rebuilds
/// `Settings` per request, the Axum dev server builds its application
/// state once and reuses the same [`RouterService`] for every request.
#[must_use]
fn routes_with_server_timing_flag() -> (RouterService, bool) {
let state = match build_state() {
Ok(s) => s,
Err(ref e) => {
log::error!("failed to build application state: {:?}", e);
return (startup_error_router(e), false);
}
};

let server_timing_enabled = state.settings.observability.server_timing_enabled;
Comment thread
aram356 marked this conversation as resolved.
(build_router(&state), server_timing_enabled)
}
}

fn build_router(state: &Arc<AppState>) -> RouterService {
Expand Down
3 changes: 3 additions & 0 deletions crates/trusted-server-adapter-axum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ pub mod app;
pub mod middleware;
/// Platform-trait implementations backed by env vars and `reqwest`.
pub mod platform;
/// Terminal timing layer wrapping the Axum dev server's tower `Service`
/// boundary with the request-phase `Server-Timing` freeze point.
pub mod timing;
67 changes: 63 additions & 4 deletions crates/trusted-server-adapter-axum/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
use edgezero_adapter_axum::dev_server::{AxumDevServer, AxumDevServerConfig};
use edgezero_core::app::Hooks as _;
use std::net::SocketAddr;

use axum::Router;
use edgezero_adapter_axum::dev_server::AxumDevServerConfig;
use edgezero_adapter_axum::service::EdgeZeroAxumService;
use tokio::net::TcpListener;
use tokio::runtime::Builder as RuntimeBuilder;
use tokio::signal;
use tower::Service as _;
use tower::service_fn;
use trusted_server_adapter_axum::app::TrustedServerApp;
use trusted_server_adapter_axum::timing::TimingService;

#[allow(clippy::print_stderr)]
fn main() {
Expand All @@ -20,13 +29,63 @@ fn main() {
};

log::info!("Listening on http://{}", config.addr);
let router = TrustedServerApp::routes();
if let Err(err) = AxumDevServer::with_config(router, config).run() {
let service = TrustedServerApp::dev_server_service();
if let Err(err) = run(service, config) {
log::error!("trusted-server-adapter-axum failed: {err}");
std::process::exit(1);
}
}

/// Runs the Axum dev server with the request-phase timing terminal layer

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📌 out of scope — I compared this against edgezero-adapter-axum v0.0.7's AxumDevServer::run_async + serve_with_stores, and the behavior does match for this caller: same multi-thread runtime with enable_all, same fallback_service + into_make_service_with_connect_info::<SocketAddr>(), same conditional ctrl-c shutdown. Upstream binds via StdTcpListener then set_nonblocking(true) + from_std, which is equivalent to the tokio bind here. Upstream also wires optional config/KV/secret store handles, but the previous AxumDevServer::with_config(router, config) call left those as Stores::default(), so nothing is lost today.

The cost is ownership rather than correctness: this fork exists only because upstream has no seam for an outer tower layer, and it now has to track upstream's serve loop by hand — including that store-wiring seam, if this adapter ever needs a KV handle.

Worth an upstream issue asking for a layer/service hook on AxumDevServer (something like with_layer, or accepting a tower::Layer) so this can go back to using the helper. No change requested in this PR.

/// ([`trusted_server_adapter_axum::timing::TimingService`]) wrapped around
/// `EdgeZeroAxumService`, ahead of `axum::serve`.
///
/// This does not use `edgezero_adapter_axum::dev_server::AxumDevServer::run`:
/// that helper only accepts a bare [`RouterService`] and builds its own
/// `EdgeZeroAxumService` and `axum::Router` internally, with no seam for an
/// outer service wrapper. Router-generated 404/405 responses bypass
/// `RouterBuilder::middleware` (see `trusted_server_adapter_axum::timing`),
/// so the freeze point has to wrap the tower `Service` boundary itself.
/// Driving `axum::serve` directly here mirrors that helper's own internal
/// bind/wrap/serve/shutdown sequence closely enough to keep behavior
/// identical for callers (`PORT` env var, ctrl-c graceful shutdown).
///
/// # Errors
///
/// Returns an error if the Tokio runtime fails to start, the listener fails
/// to bind, or the underlying serve loop errors.
fn run(
service: TimingService<EdgeZeroAxumService>,
config: AxumDevServerConfig,
) -> std::io::Result<()> {
let runtime = RuntimeBuilder::new_multi_thread().enable_all().build()?;
runtime.block_on(serve(service, config))
}

async fn serve(
service: TimingService<EdgeZeroAxumService>,
config: AxumDevServerConfig,
) -> std::io::Result<()> {
let listener = TcpListener::bind(config.addr).await?;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick — The upstream helper this replaces wrapped the bind with .with_context(|| format!("failed to bind dev server to {}", config.addr)). This propagates the bare io::Error, so the most common dev-server failure now logs trusted-server-adapter-axum failed: Address already in use (os error 48) with no indication of which port.

Suggested change
let listener = TcpListener::bind(config.addr).await?;
let listener = TcpListener::bind(config.addr).await.map_err(|error| {
std::io::Error::new(
error.kind(),
format!("failed to bind dev server to {}: {error}", config.addr),
)
})?;

(verified with cargo fmt --all -- --check, cargo clippy-axum, and cargo test-axum — 25 passed — in an isolated worktree at this head.)


let axum_router = Router::new().fallback_service(service_fn(move |req| {
let mut svc = service.clone();
async move { svc.call(req).await }
}));
let make_service = axum_router.into_make_service_with_connect_info::<SocketAddr>();

let server = axum::serve(listener, make_service);
if config.enable_ctrl_c {
server
.with_graceful_shutdown(async {
let _ctrl_c = signal::ctrl_c().await;
})
.await
} else {
server.await
}
}

/// Read a port number from the `PORT` environment variable.
///
/// Returns `None` when the variable is unset. Exits non-zero if the value
Expand Down
Loading
Loading