Problem Statement campaign uses raw env.events().publish for client-visible state. There is no internal framework for log lines, error breadcrumbs, or counters. On a faulty production deployment, debugging requires painstakingly reading on-chain events.
Why it matters Soroban hostside tracing is unavailable in production (no eprintln!); internal observability is best expressed through additional public events and typed structs.
Expected Outcome Add a structured event diagnostics_emit (off-by-default, gated behind a feature flag) that captures:
- Latency budget used per call.
- CPU/memory envelope per call.
- Error code on panic.
Also, a public metrics_view(env) -> CampaignMetrics entrypoint that returns diagnostic counters (counters for donate_received_total, donate_panicked_total_by_code, etc.) if a feature flag is enabled.
Acceptance Criteria
- New feature flag
diag (default off).
- New event variant
diagnostics_emit (gated by the flag).
- New view entrypoint
metrics_view.
- Test exercises flag-off (no events emitted) and flag-on (events emitted).
- Documentation in
docs/observability.md includes a user-facing JSON schema.
Implementation Notes
- The flag toggle must be cheap; use
#[cfg(feature = "diag")].
Affected Files / Modules
campaign/src/lib.rs
campaign/Cargo.toml (feature)
- New:
docs/observability.md
Dependencies — None.
Problem Statement
campaignuses rawenv.events().publishfor client-visible state. There is no internal framework for log lines, error breadcrumbs, or counters. On a faulty production deployment, debugging requires painstakingly reading on-chain events.Why it matters Soroban hostside tracing is unavailable in production (no
eprintln!); internal observability is best expressed through additional public events and typed structs.Expected Outcome Add a structured event
diagnostics_emit(off-by-default, gated behind a feature flag) that captures:Also, a public
metrics_view(env) -> CampaignMetricsentrypoint that returns diagnostic counters (counters fordonate_received_total,donate_panicked_total_by_code, etc.) if a feature flag is enabled.Acceptance Criteria
diag(default off).diagnostics_emit(gated by the flag).metrics_view.docs/observability.mdincludes a user-facing JSON schema.Implementation Notes
#[cfg(feature = "diag")].Affected Files / Modules
campaign/src/lib.rscampaign/Cargo.toml(feature)docs/observability.mdDependencies — None.