This page covers where logged data goes.
It starts with sinks, the destinations that receive your data, and then covers the operating modes (spawn, connect_grpc, serve_grpc, save, stdout) that set up sinks for you.
Sinks
Sinks control where your Rerun data goes. They are the output destinations for your logged data.
Data can go to a live Viewer, a file on disk, memory, or several destinations at once.
Available sink types
Rerun provides these built-in sink types:
GrpcSink
Streams data to a Rerun Viewer over gRPC. This is the most common sink for live visualization.
"""Create and set a GRPC sink."""
import rerun as rr
rr.init("rerun_example_grpc_sink")
# The default URL is `rerun+http://127.0.0.1:9876/proxy`
# This can be used to connect to a viewer on a different machine
rr.set_sinks(rr.GrpcSink("rerun+http://127.0.0.1:9876/proxy"))
FileSink
Writes data to .rrd files on disk.
"""Create and set a file sink."""
import rerun as rr
rr.init("rerun_example_file_sink")
rr.set_sinks(rr.FileSink("recording.rrd"))
Multiple sinks (Tee pattern)
Pass several sinks to set_sinks to send data to all of them at once.
For example, a GrpcSink and a FileSink let you view data live and save it to disk in the same run:
"""Log some data to a file and a Viewer at the same time."""
import numpy as np
import rerun as rr
# Initialize the SDK and give our recording a unique name
rr.init("rerun_example_set_sinks")
rr.set_sinks(
# Connect to an existing local Viewer or gRPC server.
rr.GrpcSink(),
# To host a gRPC server instead, replace the sink above with:
# rr.GrpcServerSink(),
# Write data to a `data.rrd` file in the current directory
rr.FileSink("data.rrd"),
)
# Create some data
SIZE = 10
pos_grid = np.meshgrid(*[np.linspace(-10, 10, SIZE)] * 3)
positions = np.vstack([d.reshape(-1) for d in pos_grid]).T
col_grid = np.meshgrid(*[np.linspace(0, 255, SIZE)] * 3)
colors = np.vstack([c.reshape(-1) for c in col_grid]).astype(np.uint8).T
# Log the data
rr.log(
# name under which this entity is logged (known as "entity path")
"my_points",
# log data as a 3D point cloud archetype
rr.Points3D(positions, colors=colors, radii=0.5),
)
You can also stream to several Viewers or save to several files.
Calling rr.spawn(), rr.connect_grpc(), or rr.save() replaces all existing sinks.
To start a Viewer without touching your sinks, call rr.spawn(connect=False): it only starts the Viewer process, and your GrpcSink can then connect to it.
rr.init("rerun_example_spawn_and_save")
rr.spawn(connect=False) # Start a Viewer, but leave the sinks alone.
rr.set_sinks(rr.GrpcSink(), rr.FileSink("data.rrd"))Connection lifecycle
These rules apply to the gRPC sink (connect_grpc, spawn, and GrpcSink):
- Connecting: the SDK connects in the background and retries forever, with a backoff of up to one second between attempts. You can start logging before the Viewer is running: data is queued until the connection is up. If the queue fills up before a connection is made, log calls block.
- Flushing:
flushwaits for queued data to be sent. If the SDK has not connected yet,flushgives up after about 5 seconds. In Python, userec.flush(timeout_sec=…)on aRecordingStream(for example the one returned byrr.get_global_data_recording()) to limit how long it waits; it raises an error on timeout. - Shutdown: at shutdown, the SDK waits at most about 5 seconds for a final connection attempt. If it still cannot connect, the queued data is dropped and an error is logged.
- Disconnects: if an established connection fails (for example because the Viewer was closed), the SDK does not reconnect.
Data logged after that is lost for this sink.
If you need the data, also log to a
FileSink. - Status: only the Rust SDK exposes the connection state, through the experimental
GrpcSink::status.
If the Viewer cannot start because its port is taken, run rerun --port auto (or rerun --new) to start a new Viewer on a free port, and connect to the port it prints.
Operating modes
There are many different ways of sending data to the Rerun Viewer depending on what you're trying to achieve and whether the Viewer is running in the same process as your code, in another process, or even as a separate web application.
In the official examples, these different modes of operation are exposed via a standardized set of flags that we'll cover below. We will also demonstrate how you can achieve the same behavior in your own code.
Before reading this section, you might want to familiarize yourself with the Rerun application model.
The Rerun SDK provides multiple modes of operation: spawn, connect_grpc, serve_grpc, save, and stdout.
All of them are optional: when none of these modes are active, the client will simply buffer the logged data in memory, waiting for one of these modes to be enabled so that it can flush it.
spawn
This is the default behavior you get when running all of our Python/Rust/C++ examples, and is generally the most convenient when you're experimenting.
Call rr.spawn once at the start of your program to start a Rerun Viewer in an external process and stream all the data to it via gRPC. If an external Viewer was already running, spawn will connect to that one instead of spawning a new one.
RecordingStream::spawn spawns a new Rerun Viewer process using an executable available in your PATH, then streams all the data to it via gRPC. If an external Viewer was already running, spawn will connect to that one instead of spawning a new one.
RecordingStream::spawn spawns a new Rerun Viewer process using an executable available in your PATH, then streams all the data to it via gRPC. If an external Viewer was already running, spawn will connect to that one instead of spawning a new one.
connect_grpc
Connects to a remote Rerun Viewer and streams all the data via gRPC.
You will need to start a stand-alone Viewer first by typing rerun in your terminal.
serve_grpc
Calling serve_grpc will start a Rerun gRPC server in your process, and stream logged data to it.
This gRPC server can then be connected to from the Rerun Viewer, e.g. by running rerun --connect.
The gRPC server acts as a proxy, buffering and forwarding log data to the Rerun Viewer.
You can also connect to the gRPC server from a Rerun Web Viewer.
To host a Rerun Web Viewer, you can use the serve_web_viewer function.
"""Log data to a gRPC server and connect the web viewer to it."""
import time
import rerun as rr
rr.init("rerun_example_serve_web_viewer")
# Start a gRPC server and use it as log sink.
server_uri = rr.serve_grpc()
# Connect the web viewer to the gRPC server and open it in the browser
rr.serve_web_viewer(connect_to=server_uri)
# Log some data to the gRPC server.
rr.log("data", rr.Boxes3D(half_sizes=[2.0, 2.0, 1.0]))
# Keep server running. If we cancel it too early, data may never arrive in
# the browser.
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
print("\nShutting down server…")
RecordingStream::serve_grpc.serve_web_vieweris not available (#4638).
save
Streams all logging data into an .rrd file on disk, which can then be loaded into a stand-alone viewer.
To view the saved file, use rerun path/to/file.rrd.
Standard Input/Output (stdout)
Streams all logging data to standard output, which can then be loaded by the Rerun Viewer by streaming it from standard input.
Use rr.stdout.
Check out our dedicated example.
Check out our dedicated example.
Use RecordingStream::to_stdout.
Check out our dedicated example.
set_sinks
You can use this to log to multiple sinks concurrently, such as saving to disk while streaming to the viewer.
"""Log some data to a file and a Viewer at the same time."""
import numpy as np
import rerun as rr
# Initialize the SDK and give our recording a unique name
rr.init("rerun_example_set_sinks")
rr.set_sinks(
# Connect to an existing local Viewer or gRPC server.
rr.GrpcSink(),
# To host a gRPC server instead, replace the sink above with:
# rr.GrpcServerSink(),
# Write data to a `data.rrd` file in the current directory
rr.FileSink("data.rrd"),
)
# Create some data
SIZE = 10
pos_grid = np.meshgrid(*[np.linspace(-10, 10, SIZE)] * 3)
positions = np.vstack([d.reshape(-1) for d in pos_grid]).T
col_grid = np.meshgrid(*[np.linspace(0, 255, SIZE)] * 3)
colors = np.vstack([c.reshape(-1) for c in col_grid]).astype(np.uint8).T
# Log the data
rr.log(
# name under which this entity is logged (known as "entity path")
"my_points",
# log data as a 3D point cloud archetype
rr.Points3D(positions, colors=colors, radii=0.5),
)
Adding the standard flags to your programs
We provide helpers for both Python & Rust to add and handle all of these flags in your programs.
- For Python, check out
rr.script_add_args,rr.script_setup, andrr.script_teardown. - For Rust, check out our
clapintegration.
Have a look at the official examples to see these helpers in action.
See also
- Recordings: Understand how recordings relate to sinks
- Blueprints: Learn how to configure the viewer's layout
- API References: