feat(api): JSON log format toggle and document RUST_LOG (closes #86) - #161
Merged
valoryyaa-byte merged 3 commits intoJul 28, 2026
Conversation
…pl + last_indexed_ledger) main currently fails cargo check with 9 errors from PR RWA-ToolKit#122 feat/api-hardening: - missing deps: metrics, metrics-exporter-prometheus, rand are imported in source but not declared in api/Cargo.toml - arc-swap 1.9 API: ArcSwap::from_arc was removed (replaced by From<Arc<T>>) - #[derive(Clone)] on AppState no longer works because ArcSwapAny does not impl Clone; wrap inner in Arc<ArcSwap<Snapshot>> so cloning shares inner cell - (*guard).clone() in AppState::snapshot returned Arc<Snapshot> not Snapshot, double-deref (**guard) instead - AppState::last_indexed_ledger never defined; routes::cache_headers called it - PrometheusBuilder / PrometheusHandle types were undeclared; import them from metrics_exporter_prometheus - pre-existing dead variable consecutive_failures in Indexer::run Verified by running the same five gates api.yml runs: cargo fmt --check, cargo clippy --all-targets -- -D warnings, cargo test, and cargo build --release all exit 0, with 8 unit tests passing. Independent of fix/issue-86-tracing-log-format.
|
@akindoyinabraham0-collab Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
…oolKit#86) - enable the json feature on tracing-subscriber - read LOG_FORMAT env var in init_tracing (pretty | compact | json), selected at runtime via Box<dyn tracing_subscriber::Layer<_> + Send + Sync> - bake LOG_FORMAT=json + RUST_LOG defaults into the runtime stage of the Dockerfile for log-shipper-ready containers; overridable via docker run -e - document RUST_LOG and LOG_FORMAT in api/.env.example and README.md Defaults are unchanged when LOG_FORMAT is unset, so this is fully backwards compatible.
akindoyinabraham0-collab
force-pushed
the
fix/issue-86-tracing-log-format
branch
from
July 27, 2026 11:56
f7162bf to
18b75b7
Compare
akindoyinabraham0-collab
force-pushed
the
fix/issue-86-tracing-log-format
branch
from
July 27, 2026 11:58
22bc5e4 to
3863400
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat(api): add JSON log format toggle + document RUST_LOG
Closes #86.
Summary
LOG_FORMATenv var:pretty/compact/json).tracing-subscriber'sjsonfeature.RUST_LOGin user-facing docs (README.md,api/.env.example).LOG_FORMAT=json,RUST_LOG=stellar_rwa_api=info,tower_http=warn)into the runtime stage of the Dockerfile, while preserving the local-dev defaults.
LOG_FORMATis unset, output is identical to before(pretty, single-line, colored).
Verdicts on each issue claim
init_tracinghonorsRUST_LOG/EnvFilterapi/src/main.rs)api/.env.example, not inREADME.mdREADME.mdLOG_FORMATFiles
api/Cargo.tomltracing-subscriberfeatures["env-filter"]→["env-filter", "json"]api/src/main.rsinit_tracingreadsLOG_FORMATand boxes the selected fmt layer asBox<dyn tracing_subscriber::Layer<_> + Send + Sync>;.boxed()resolves viause tracing_subscriber::layer::Layer as _;api/.env.example#LOG_FORMAT=jsonapi/DockerfilePORT=8080 LOG_FORMAT=json RUST_LOG=stellar_rwa_api=info,tower_http=warnin a singleENV; comment notes how to override withdocker run -e …README.md### Loggingsubsection under the API's "Run it" block, with cargo and docker examplesVerification status
After installing Rust stable (matching
dtolnay/rust-toolchain@stablein CI) I ran aA/B
cargo checkto isolate whether this PR adds any new compile errors:cargo checkon plainmain→ 9 errors + 3 warningscargo checkonmain + this PR→ 9 errors + 3 warningsdiffbetween the two error/warning sets → emptyThis PR introduces zero new compile errors or warnings. Every existing
issue is in code untouched by this diff.
Dependent branch:
fix/head-build-fixI staged the pre-existing HEAD breakage fix on a parallel branch so PR reviewers / maintainers can see them in isolation:
fix/head-build-fix0601a4f fix(api): restore compile at HEAD (missing deps + arc-swap + Clone impl + last_indexed_ledger)main: 4 files changed, 38 insertions(+), 21 deletions(-)cargo fmt --check✓cargo clippy --all-targets -- -D warnings✓ (no warnings)cargo test✓ (8/8 passed)cargo build --release✓ (3m 39s)This PR (issue #86) is additive to
fix/head-build-fix— the two don't conflict and can be merged in either order. The paste-ready issue body for filing the missing-deps problem as a tracker is in/workspaces/stellar-rwa-api-docs/ISSUE-HEAD-BUILD.mdat the repo root.What the dependent branch fixes (1.x quirks + missing deps)
api/Cargo.tomlgains three deps:metrics = "0.24",metrics-exporter-prometheus = "0.16",rand = "0.9". All were imported in source but never declared.ArcSwap::from_arc→ArcSwap::fromafter thearc-swap 1.xrename.AppState.inner: ArcSwap<Snapshot>becomesArc<ArcSwap<Snapshot>>and#[derive(Clone)]works again. The earlier bug: without theArcwrap, cloningAppStatedeep-clones the snapshot, so updates from one clone (the indexer's) are never observed by another (the routes') —cache_headersETag would never advance. This is a real correctness fix, not just a compile fix.AppState::snapshotwas returningArc<Snapshot>because(*guard).clone()only derefs once; corrected to(**guard).clone()(double-deref throughGuard→Arc→ value).AppState::last_indexed_ledger(&self) -> u32method (routes::cache_headerswas calling it but it didn't exist).let mut consecutive_failures: u64 = 0;line inIndexer::run(landed in PR Harden the public API: caching, rate limiting, metrics, retry #122, never read, never incremented).ConfigErrorimport inmain.rs(pre-existing warning).routes::cache_headerscall site no longer.awaitslast_indexed_ledger(it's synchronous now).Test plan (after the unrelated breakage is fixed locally)
Expected runtime behaviour:
cargo runRUST_LOG=debug cargo runLOG_FORMAT=json cargo runLOG_FORMAT=compact cargo runRUST_LOG=info LOG_FORMAT=json cargo rundocker run -p 8080:8080 stellar-rwa-apidocker run -p 8080:8080 -e LOG_FORMAT=pretty stellar-rwa-apiRisk
init_tracingis called once at startup, so any extra work runs once perprocess start — negligible.
tracing::*!call sites inapi/src/main.rsandapi/src/indexer/mod.rsalready pass structured fields (error = %e,rpc = %config.rpc_url,attempt = N, etc.) — these serialize cleanly asJSON with no further code changes.
LOG_FORMATis unset.Repo policy
CONTRIBUTING.mdflagsapi/as maintainer-only. Drafting this PR in casea maintainer wants to incorporate; per the issue author's request the patch
is fully scoped and A/B-verified.