Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shared recordings 1: exposing recording_id in Rust SDK #4383

Merged
merged 2 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(())
}
Loading