Skip to main content

browser_commander/traces/
mod.rs

1//! Privacy-aware portable traces (issue #87).
2//!
3//! A trace is one versioned directory holding a manifest, an ordered timeline,
4//! per-checkpoint DOM snapshots and the mutation batches between them.
5//!
6//! Rust records traces natively (issue #108): [`start_trace`] writes the same
7//! bundle JavaScript writes, record for record, [`write_trace_viewer`] adds the
8//! same offline viewer, and [`TraceOptions::links`] streams the same Links
9//! Notation export. [`record_scenario`] keeps a bundle only when the work it
10//! wraps fails, as `retain-on-failure` does in the JavaScript test runner.
11//! Every in-page function comes from the shared `assets.json`,
12//! so the page runs the very code JavaScript runs. Rust reads traces too. See
13//! `docs/feature-parity.md` for the current state of each language.
14//!
15//! # Example
16//!
17//! ```rust,no_run
18//! use std::sync::Arc;
19//!
20//! use browser_commander::core::EngineAdapter;
21//! use browser_commander::traces::{
22//!     read_trace, start_trace, write_trace_viewer, AdapterTracePage, TraceLinksOptions,
23//!     TraceOptions,
24//! };
25//!
26//! # async fn run(page: Arc<dyn EngineAdapter>) -> Result<(), Box<dyn std::error::Error>> {
27//! let mut options = TraceOptions::new("./traces/run");
28//! options.mode = "continuous".into();
29//! options.links = Some(TraceLinksOptions {
30//!     output: "./traces/run.lino".into(),
31//!     include: None,
32//! });
33//! let recorder = start_trace(Arc::new(AdapterTracePage::new(page)), options).await?;
34//! recorder.checkpoint("after-login").await?;
35//! let result = recorder.stop().await?;
36//! write_trace_viewer(&result.path)?;
37//!
38//! let trace = read_trace(&result.path)?;
39//! for checkpoint in &trace.checkpoints {
40//!     println!("{:?}", checkpoint.name);
41//! }
42//! # Ok(())
43//! # }
44//! ```
45
46pub mod assets;
47pub mod bundle;
48pub mod identity;
49pub mod jsonfmt;
50pub mod links;
51pub mod mutation_stream;
52pub mod page;
53mod raw_reader;
54pub mod reader;
55pub mod recorder;
56mod recorder_options;
57pub mod redaction;
58pub mod retention;
59pub mod schema;
60pub mod viewer;
61
62pub use reader::{
63    diff_control_state, parse_ndjson, read_trace, ControlChange, ControlChangeKind, ParsedNdjson,
64    Trace, TraceCheckpoint, TraceError,
65};
66pub use schema::{
67    assert_readable_manifest, sequence_name, TraceCheckpointReason, TraceCounts, TraceDropReason,
68    TraceEvent, TraceFiles, TraceLiveState, TraceManifest, TraceMode, TraceMutationKind,
69    TraceOutcome, TraceReplaySupport, TRACE_EVENT_SOURCES, TRACE_FORMAT, TRACE_SCHEMA_VERSION,
70};
71
72pub use bundle::{iso_timestamp, TraceClock, TraceLimits, TraceProblem, TraceRecordError};
73pub use identity::reset_trace_identity_counters;
74pub use jsonfmt::{Json, JsonObject};
75pub use links::{trace_links, write_trace_links, TraceExportError, TraceLinksOptions};
76pub use page::{AdapterTracePage, TracePage};
77pub use recorder::{
78    start_trace, TraceCheckpointOptions, TraceDomOptions, TraceFailure, TraceInitialCheckpoint,
79    TraceOptions, TraceRecorder, TraceResult, TraceScreenshots, TraceStopOptions,
80    DEFAULT_CAPTURE_TIMEOUT_MS,
81};
82pub use redaction::{
83    normalize_privacy_options, redact_url, redact_value, NormalizedPrivacy, RedactCallback,
84    RedactContext, TracePrivacyOptions, REDACTED,
85};
86pub use retention::{
87    finish_scenario_trace, record_scenario, resolve_trace_setting, scenario_trace_options,
88    start_scenario_trace, trace_output_path, ScenarioRun, ScenarioTrace, TraceSetting,
89    TEST_TRACE_MODES, TRACE_BUNDLE_SUFFIX,
90};
91pub use viewer::{render_trace_viewer, write_trace_viewer, DEFAULT_MAX_INLINE_BYTES};