Skip to content
Open
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
6 changes: 4 additions & 2 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@ rustflags = ["-C", "target-feature=+crt-static"]
[target.aarch64-pc-windows-msvc]
rustflags = ["-C", "target-feature=+crt-static"]

# `-headerpad_max_install_names` on macOS: Flutter's native-assets step rewrites the cdylib's
# install name with install_name_tool, which fails without the padding.
# `-ObjC` must also be passed to rustdoc: doctest binaries are linked by rustdoc
# and do not inherit `rustflags`. Without it the ObjC categories in libwebrtc's
# static lib (e.g. `NSString (StdString)`) are not loaded, and static
# initializers such as RTCH264ProfileLevelId.mm abort at process startup.
[target.x86_64-apple-darwin]
rustflags = ["-C", "link-args=-ObjC"]
rustflags = ["-C", "link-args=-ObjC -Wl,-headerpad_max_install_names"]
rustdocflags = ["-C", "link-args=-ObjC"]

[target.aarch64-apple-darwin]
rustflags = ["-C", "link-args=-ObjC"]
rustflags = ["-C", "link-args=-ObjC -Wl,-headerpad_max_install_names"]
rustdocflags = ["-C", "link-args=-ObjC"]

[target.aarch64-apple-ios]
Expand Down
5 changes: 5 additions & 0 deletions .changeset/telemetry-severity-from-log-level.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
livekit-telemetry: minor
---

Convert a `log::Level` into a telemetry `Severity` with `From`, and remove the process pipeline without draining it with `global::uninstall`.
5 changes: 5 additions & 0 deletions .changeset/uniffi-telemetry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
livekit-ffi: minor
---

Expose the client telemetry core through the `core-modules` UniFFI surface (`telemetry_configure`, `telemetry_configure_pulled`, `telemetry_scope`, spans, stats and `telemetry_disable`); `log_forward_bootstrap` now copies the core's own warnings and errors into telemetry and keeps the Rust log level at `warn` or looser.
12 changes: 12 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ members = [
"examples/rpc",
"examples/save_to_disk",
"examples/screensharing",
"examples/telemetry_ping",
"examples/token_source",
"examples/webhooks",
]
Expand Down
11 changes: 11 additions & 0 deletions examples/telemetry_ping/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "telemetry_ping"
version = "0.1.0"
edition.workspace = true
publish = false

[dependencies]
livekit-telemetry = { workspace = true, features = ["net"] }
livekit-net = { workspace = true, features = ["native", "rustls-tls-native-roots"] }
tokio = { workspace = true, features = ["rt-multi-thread", "macros"] }
env_logger = { workspace = true }
91 changes: 91 additions & 0 deletions examples/telemetry_ping/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// Copyright 2026 LiveKit, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! Records a small session through the telemetry core — an `lk.connect` span with its
//! checkpoints, an `lk.publish`, an `lk.subscribe` ended by first media, and a custom event —
//! and exports it.
//!
//! - A local OpenTelemetry collector: `LK_TELEMETRY_ENDPOINT=http://localhost:4318` (the core's
//! test-only override; any server URL and token are accepted).
//! - A LiveKit Cloud project: `LK_URL=wss://<project>.livekit.cloud` and `LK_TOKEN=<participant
//! token with the observability grant>`.

use std::{env, sync::Arc};

use livekit_telemetry::{
Attribute, NetTransport, RoomIdentity, RtcStatsSample, SpanName, SpanOutcome, SpanStep,
SpanTrack, StreamDirection, Telemetry, TelemetryConfig, TrackKind, TrackSource,
ENDPOINT_OVERRIDE_ENV,
};

#[tokio::main]
async fn main() {
env_logger::init();
let url = env::var("LK_URL").unwrap_or_else(|_| "ws://localhost:7880".to_owned());
let token = env::var("LK_TOKEN").unwrap_or_default();
if env::var(ENDPOINT_OVERRIDE_ENV).is_err() && env::var("LK_URL").is_err() {
eprintln!("set {ENDPOINT_OVERRIDE_ENV}=http://localhost:4318, or LK_URL and LK_TOKEN");
return;
}

let config = TelemetryConfig {
resource: vec![
Attribute::new("service.name", "telemetry_ping"),
Attribute::new("os.name", env::consts::OS),
],
// Optional on-disk cache: run once with the collector down, once with it up.
storage_dir: env::var("LK_TELEMETRY_DIR").ok(),
..Default::default()
};
let transport = NetTransport::from_registry().expect("livekit-net has no HTTP client");
let (telemetry, exporter) = Telemetry::new(config, Arc::new(transport));
tokio::spawn(exporter.run());

let room = telemetry.begin_scope();
room.set_server(&url, &token);
room.set_room(RoomIdentity { name: Some("telemetry-ping".into()), ..Default::default() });

let connect = room.start(SpanName::Connect, None);
for step in [SpanStep::WsOpen, SpanStep::Signal, SpanStep::JoinRecv, SpanStep::PcCreated] {
connect.step(step);
}
connect.end(SpanOutcome::Ok, None);

let microphone = SpanTrack {
sid: Some("TR_ping_mic".into()),
kind: TrackKind::Audio,
source: TrackSource::Microphone,
remote_identity: None,
};
let publish = room.start(SpanName::Publish, None);
publish.set_track(microphone);
publish.end(SpanOutcome::Ok, None);

let remote = SpanTrack {
sid: Some("TR_ping_remote".into()),
kind: TrackKind::Video,
source: TrackSource::Camera,
remote_identity: Some("bob".into()),
};
room.subscribe_started(remote.clone());
room.subscribed(remote);
let mut media =
RtcStatsSample::new("TR_ping_remote", TrackKind::Video, StreamDirection::Inbound);
media.bytes = Some(1_500);
room.record_stats(media); // first media: the lk.subscribe span ends ok

room.emit_custom("ping", vec![Attribute::new("seq", 1i64)]);
telemetry.shutdown().await;
println!("trace {} — {}", room.trace_id(), telemetry.stats());
}
5 changes: 5 additions & 0 deletions livekit-ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ core-modules = [
"dep:livekit-data-stream",
"dep:livekit-datatrack",
"dep:livekit-net",
"dep:livekit-telemetry",
"dep:livekit-token",
"dep:prost",
"dep:async-trait",
Expand All @@ -53,6 +54,8 @@ core-modules = [
"livekit-common/uniffi",
"livekit-datatrack/uniffi",
"livekit-net/uniffi",
"livekit-telemetry/net",
"livekit-telemetry/uniffi",
"uniffi/tokio",
]

Expand Down Expand Up @@ -97,6 +100,7 @@ livekit-common = { workspace = true, optional = true }
livekit-token = { workspace = true, optional = true }
livekit-datatrack = { workspace = true, optional = true }
livekit-net = { workspace = true, optional = true }
livekit-telemetry = { workspace = true, optional = true }
livekit-data-stream = { workspace = true, optional = true }
tokio-util = { version = "0.7.18", optional = true }
once_cell = { version = "1.21.3", optional = true }
Expand Down Expand Up @@ -126,6 +130,7 @@ prost-build = { workspace = true, optional = true }
webrtc-sys-build = { workspace = true, optional = true }

[dev-dependencies]
flate2 = "1"
livekit-token = { workspace = true }
serial_test = "3.0"

Expand Down
Loading
Loading