Skip to content

Commit

Permalink
Shared recordings 1: exposing recording_id in Rust SDK (#4383)
Browse files Browse the repository at this point in the history
We already exposed a way of configuring the `StoreId`, but this is an
internal concept that we have never communicated anywhere and is very
likely to be unstable as the way we do blueprint recordings evolve (also
it's been known to confuse users).

This adds a simple, straightforward way of configuring the
`recording_id`, akin to what we have in the Python SDK.

---

Part of a PR series to fix #4055 once and for all:
- #4383
- #4384
- #4385
  • Loading branch information
teh-cmc authored Nov 30, 2023
1 parent b33cbc4 commit e81f44d
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

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

17 changes: 17 additions & 0 deletions crates/re_sdk/src/recording_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,23 @@ impl RecordingStreamBuilder {
self
}

/// Set the `RecordingId` for this context.
///
/// If you're logging from multiple processes and want all the messages to end up in the same
/// recording, you must make sure that they all set the same `RecordingId` using this function.
///
/// Note that many stores can share the same [`ApplicationId`], but they all have
/// unique `RecordingId`s.
///
/// The default is to use a random `RecordingId`.
pub fn recording_id(mut self, recording_id: impl Into<String>) -> Self {
self.store_id = Some(StoreId::from_string(
StoreKind::Recording,
recording_id.into(),
));
self
}

/// Set the [`StoreId`] for this context.
///
/// If you're logging from multiple processes and want all the messages to end up as the same
Expand Down
10 changes: 10 additions & 0 deletions examples/rust/shared_recording/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "shared_recording"
version = "0.12.0-alpha.1+dev"
edition = "2021"
rust-version = "1.72"
license = "MIT OR Apache-2.0"
publish = false

[dependencies]
rerun = { path = "../../../crates/rerun" }
19 changes: 19 additions & 0 deletions examples/rust/shared_recording/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
title: Shared Recording
rust: https://github.com/rerun-io/rerun/tree/latest/examples/python/shared_recording/main.py?speculative-link
---

<picture>
<img src="https://static.rerun.io/shared_recording/c3da85f1d4c158b8c7afb6bd3278db000b58049d/full.png" alt="">
<source media="(max-width: 480px)" srcset="https://static.rerun.io/shared_recording/c3da85f1d4c158b8c7afb6bd3278db000b58049d/480w.png">
<source media="(max-width: 768px)" srcset="https://static.rerun.io/shared_recording/c3da85f1d4c158b8c7afb6bd3278db000b58049d/768w.png">
<source media="(max-width: 1024px)" srcset="https://static.rerun.io/shared_recording/c3da85f1d4c158b8c7afb6bd3278db000b58049d/1024w.png">
<source media="(max-width: 1200px)" srcset="https://static.rerun.io/shared_recording/c3da85f1d4c158b8c7afb6bd3278db000b58049d/1200w.png">
</picture>

This example demonstrates how to use `RecordingId`s to create a single shared recording across multiple processes.

Run the following multiple times, and you'll see that each invocation adds data to the existing recording rather than creating a new one:
```bash
cargo run
```
14 changes: 14 additions & 0 deletions examples/rust/shared_recording/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//! Demonstrates how to use `RecordingId`s to build a single recording from multiple processes.
fn main() -> Result<(), Box<dyn std::error::Error>> {
let rec = rerun::RecordingStreamBuilder::new("rerun_example_shared_recording")
.recording_id("my_shared_recording")
.spawn()?;

rec.log(
"updates",
&rerun::TextLog::new(format!("hello from process #{}", std::process::id())),
)?;

Ok(())
}

0 comments on commit e81f44d

Please sign in to comment.