Native API - Option to dump Rust tracing to file#458
Open
cwshugg wants to merge 10 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds opt-in, file-based tracing initialization for the native API, controlled via environment variables, and documents how to enable/consume that output.
Changes:
- Introduce a one-time, env-var-driven tracing subscriber that writes structured events to a file.
- Initialize tracing on first ABI entrypoint execution to cover the full native API call path.
- Add diagnostics documentation and wire up
tracing-subscriberdependency/features.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| api/native/src/tracing.rs | New module that installs a global tracing_subscriber writing to a configured file |
| api/native/src/lib.rs | Calls tracing init from abi_boundary and adds the new module |
| api/native/doc/chapter_11_diagnostics.md | Documents env vars, filter syntax, examples, and behavior notes |
| api/native/Cargo.toml | Adds tracing-subscriber dependency with required features |
| open-enum.workspace = true | ||
| parking_lot.workspace = true | ||
| tracing.workspace = true | ||
| tracing-subscriber = { features = ["env-filter", "fmt"], workspace = true } |
Author
There was a problem hiding this comment.
I am not seeing issues with compilation locally - but I expect the cargo xtask ... checks done on this PR should catch anything I missed.
| pub(crate) fn abi_boundary<F: FnOnce() -> Result<(), AzihsmStatus> + UnwindSafe>( | ||
| f: F, | ||
| ) -> AzihsmStatus { | ||
| let _ = std::panic::catch_unwind(trace_file::init_trace_file); |
Comment on lines
+88
to
+99
| // Attempt to open/create the trace file. | ||
| let mut opts = std::fs::OpenOptions::new(); | ||
| opts.create(true).write(true); | ||
| if append { | ||
| opts.append(true); | ||
| } else { | ||
| opts.truncate(true); | ||
| } | ||
| let file = match opts.open(&trace_path) { | ||
| Ok(f) => f, | ||
| Err(_) => return, | ||
| }; |
…r/connorshugg/trace_capturing
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.
Hi - This PR implements a basic tracing subscriber that is toggled via an environment variable:
AZIHSM_NATIVEAPI_TRACE_FILE. If set, the native API's logs will be dumped to the provided file path.I implemented this with the goal of making the trace logs accessible. I needed a way to extract the logs from the native API to debug an issue and saw no existing way to do so. (Though, if I missed one, please point me to and I'll be happy to try it out + close this PR if necessary.)
By default (if
AZIHSM_NATIVEAPI_TRACE_FILEis not set), or if the trace subscriber fails to initialize (for one reason or another) there is no change in behavior to the native API, and no performance impact. When tracing is enabled, there may be slight performance impacts depending on the workload, as the subscriber is shared across the process and protected by a mutex lock.