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

feat(tracing): using tracing and zenoh-util init_log #308

Merged
merged 5 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
313 changes: 156 additions & 157 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,18 @@ maintenance = { status = "actively-developed" }
async-std = "=1.12.0"
async-trait = "0.1.66"
chrono = "0.4.34"
env_logger = "0.10.0"
futures = "0.3.26"
json5 = "0.4.1"
lazy_static = "1.4.0"
libc = "0.2.139"
log = "0.4.17"
rand = "0.8.5"
spin = "0.9.5"
# shared-memory enabled for zenoh even if zenoh-c "shared-memory" feature is disabled. This is to make "std::mem::transmute" work for `ZSLice`
zenoh = { version = "0.11.0-dev", git = "https://github.com/eclipse-zenoh/zenoh.git", branch = "main", features = ["shared-memory", "unstable"], default-features = false }
zenoh-protocol = { version = "0.11.0-dev", git = "https://github.com/eclipse-zenoh/zenoh.git", branch = "main", features = ["shared-memory"] }
zenoh-util = { version = "0.11.0-dev", git = "https://github.com/eclipse-zenoh/zenoh.git", branch = "main" }
zenoh-ext = { version = "0.11.0-dev", git = "https://github.com/eclipse-zenoh/zenoh.git", branch = "main", features = ["unstable"] }
tracing = "0.1"

[build-dependencies]
cbindgen = "0.24.3"
Expand Down
3 changes: 1 addition & 2 deletions Cargo.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,18 @@ maintenance = { status = "actively-developed" }
async-std = "=1.12.0"
async-trait = "0.1.66"
chrono = "0.4.34"
env_logger = "0.10.0"
futures = "0.3.26"
json5 = "0.4.1"
lazy_static = "1.4.0"
libc = "0.2.139"
log = "0.4.17"
rand = "0.8.5"
spin = "0.9.5"
# shared-memory enabled for zenoh even if zenoh-c "shared-memory" feature is disabled. This is to make "std::mem::transmute" work for `ZSLice`
zenoh = { version = "0.11.0-dev", git = "https://github.com/eclipse-zenoh/zenoh.git", branch = "main", features = ["shared-memory", "unstable"], default-features = false }
zenoh-protocol = { version = "0.11.0-dev", git = "https://github.com/eclipse-zenoh/zenoh.git", branch = "main", features = ["shared-memory"] }
zenoh-util = { version = "0.11.0-dev", git = "https://github.com/eclipse-zenoh/zenoh.git", branch = "main" }
zenoh-ext = { version = "0.11.0-dev", git = "https://github.com/eclipse-zenoh/zenoh.git", branch = "main", features = ["unstable"] }
tracing = "0.1"

[build-dependencies]
cbindgen = "0.24.3"
Expand Down
2 changes: 1 addition & 1 deletion src/attachment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub extern "C" fn z_attachment_iterate(
if let Some(driver) = this.iteration_driver {
return driver(this.data, body, context);
}
log::error!("Invalid iteration_driver");
tracing::error!("Invalid iteration_driver");
i8::MIN
}

Expand Down
2 changes: 1 addition & 1 deletion src/closures/hello_closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub extern "C" fn z_closure_hello_call(
match closure.call {
Some(call) => call(hello, closure.context),
None => {
log::error!("Attempted to call an uninitialized closure!");
tracing::error!("Attempted to call an uninitialized closure!");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/closures/matching_status_closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub extern "C" fn zcu_closure_matching_status_call(
match closure.call {
Some(call) => call(sample, closure.context),
None => {
log::error!("Attempted to call an uninitialized closure!");
tracing::error!("Attempted to call an uninitialized closure!");
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/closures/query_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub extern "C" fn zc_query_fifo_new(bound: usize) -> z_owned_query_channel_t {
From::from(move |query: &mut z_owned_query_t| {
if let Some(query) = query.take() {
if let Err(e) = tx.send(query) {
log::error!("Attempted to push onto a closed query_fifo: {}", e)
tracing::error!("Attempted to push onto a closed query_fifo: {}", e)
}
}
}),
Expand All @@ -69,7 +69,7 @@ pub extern "C" fn zc_query_fifo_new(bound: usize) -> z_owned_query_channel_t {
From::from(move |query: &mut z_owned_query_t| {
if let Some(query) = query.take() {
if let Err(e) = tx.send(query) {
log::error!("Attempted to push onto a closed query_fifo: {}", e)
tracing::error!("Attempted to push onto a closed query_fifo: {}", e)
}
}
}),
Expand Down Expand Up @@ -105,7 +105,7 @@ pub extern "C" fn zc_query_non_blocking_fifo_new(bound: usize) -> z_owned_query_
From::from(move |query: &mut z_owned_query_t| {
if let Some(query) = query.take() {
if let Err(e) = tx.send(query) {
log::error!("Attempted to push onto a closed query_fifo: {}", e)
tracing::error!("Attempted to push onto a closed query_fifo: {}", e)
}
}
}),
Expand All @@ -117,7 +117,7 @@ pub extern "C" fn zc_query_non_blocking_fifo_new(bound: usize) -> z_owned_query_
From::from(move |query: &mut z_owned_query_t| {
if let Some(query) = query.take() {
if let Err(e) = tx.send(query) {
log::error!("Attempted to push onto a closed query_fifo: {}", e)
tracing::error!("Attempted to push onto a closed query_fifo: {}", e)
}
}
}),
Expand Down Expand Up @@ -180,7 +180,7 @@ pub extern "C" fn z_query_channel_closure_call(
match closure.call {
Some(call) => call(sample, closure.context),
None => {
log::error!("Attempted to call an uninitialized closure!");
tracing::error!("Attempted to call an uninitialized closure!");
true
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/closures/query_closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub extern "C" fn z_closure_query_null() -> z_owned_closure_query_t {
pub extern "C" fn z_closure_query_call(closure: &z_owned_closure_query_t, query: &z_query_t) {
match closure.call {
Some(call) => call(query, closure.context),
None => log::error!("Attempted to call an uninitialized closure!"),
None => tracing::error!("Attempted to call an uninitialized closure!"),
}
}
/// Drops the closure. Droping an uninitialized closure is a no-op.
Expand Down Expand Up @@ -126,7 +126,7 @@ pub extern "C" fn z_closure_owned_query_call(
) {
match closure.call {
Some(call) => call(query, closure.context),
None => log::error!("Attempted to call an uninitialized closure!"),
None => tracing::error!("Attempted to call an uninitialized closure!"),
}
}
/// Drops the closure. Droping an uninitialized closure is a no-op.
Expand Down
2 changes: 1 addition & 1 deletion src/closures/reply_closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub extern "C" fn z_closure_reply_call(
match closure.call {
Some(call) => call(sample, closure.context),
None => {
log::error!("Attempted to call an uninitialized closure!");
tracing::error!("Attempted to call an uninitialized closure!");
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/closures/response_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub extern "C" fn zc_reply_fifo_new(bound: usize) -> z_owned_reply_channel_t {
From::from(move |reply: &mut z_owned_reply_t| {
if let Some(reply) = reply.take() {
if let Err(e) = tx.send(reply) {
log::error!("Attempted to push onto a closed reply_fifo: {}", e)
tracing::error!("Attempted to push onto a closed reply_fifo: {}", e)
}
}
}),
Expand All @@ -68,7 +68,7 @@ pub extern "C" fn zc_reply_fifo_new(bound: usize) -> z_owned_reply_channel_t {
From::from(move |reply: &mut z_owned_reply_t| {
if let Some(reply) = reply.take() {
if let Err(e) = tx.send(reply) {
log::error!("Attempted to push onto a closed reply_fifo: {}", e)
tracing::error!("Attempted to push onto a closed reply_fifo: {}", e)
}
}
}),
Expand Down Expand Up @@ -104,7 +104,7 @@ pub extern "C" fn zc_reply_non_blocking_fifo_new(bound: usize) -> z_owned_reply_
From::from(move |reply: &mut z_owned_reply_t| {
if let Some(reply) = reply.take() {
if let Err(e) = tx.send(reply) {
log::error!("Attempted to push onto a closed reply_fifo: {}", e)
tracing::error!("Attempted to push onto a closed reply_fifo: {}", e)
}
}
}),
Expand All @@ -116,7 +116,7 @@ pub extern "C" fn zc_reply_non_blocking_fifo_new(bound: usize) -> z_owned_reply_
From::from(move |reply: &mut z_owned_reply_t| {
if let Some(reply) = reply.take() {
if let Err(e) = tx.send(reply) {
log::error!("Attempted to push onto a closed reply_fifo: {}", e)
tracing::error!("Attempted to push onto a closed reply_fifo: {}", e)
}
}
}),
Expand Down Expand Up @@ -180,7 +180,7 @@ pub extern "C" fn z_reply_channel_closure_call(
match closure.call {
Some(call) => call(sample, closure.context),
None => {
log::error!("Attempted to call an uninitialized closure!");
tracing::error!("Attempted to call an uninitialized closure!");
true
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/closures/sample_closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub extern "C" fn z_closure_sample_null() -> z_owned_closure_sample_t {
pub extern "C" fn z_closure_sample_call(closure: &z_owned_closure_sample_t, sample: &z_sample_t) {
match closure.call {
Some(call) => call(sample, closure.context),
None => log::error!("Attempted to call an uninitialized closure!"),
None => tracing::error!("Attempted to call an uninitialized closure!"),
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/closures/zenohid_closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub extern "C" fn z_closure_zid_call(closure: &z_owned_closure_zid_t, sample: &z
match closure.call {
Some(call) => call(sample, closure.context),
None => {
log::error!("Attempted to call an uninitialized closure!");
tracing::error!("Attempted to call an uninitialized closure!");
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,12 @@ pub unsafe extern "C" fn zc_config_from_file(path: *const c_char) -> z_owned_con
Ok(path) => match zenoh::config::Config::from_file(path) {
Ok(c) => Some(Box::new(c)),
Err(e) => {
log::error!("Couldn't read config from {}: {}", path, e);
tracing::error!("Couldn't read config from {}: {}", path, e);
None
}
},
Err(e) => {
log::error!("Invalid path '{}': {}", path_str.to_string_lossy(), e);
tracing::error!("Invalid path '{}': {}", path_str.to_string_lossy(), e);
None
}
}))
Expand Down Expand Up @@ -262,7 +262,7 @@ pub unsafe extern "C" fn z_config_client(
Vec::<zenoh::prelude::Locator>::new(),
|mut acc, it| match it {
Err(e) => {
log::error!("Error parsing peer address: {}", e);
tracing::error!("Error parsing peer address: {}", e);
Err(())
}
Ok(loc) => {
Expand Down
4 changes: 2 additions & 2 deletions src/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ pub unsafe extern "C" fn z_get(
CStr::from_ptr(parameters).to_str().unwrap()
};
let Some(s) = session.upgrade() else {
log::error!("{LOG_INVALID_SESSION}");
tracing::error!("{LOG_INVALID_SESSION}");
return i8::MIN;
};
let mut q = s.get(KeyExpr::try_from(keyexpr).unwrap().with_parameters(p));
Expand Down Expand Up @@ -244,7 +244,7 @@ pub unsafe extern "C" fn z_get(
{
Ok(()) => 0,
Err(e) => {
log::error!("{}", e);
tracing::error!("{}", e);
e.errno().get()
}
}
Expand Down
38 changes: 19 additions & 19 deletions src/keyexpr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ pub unsafe extern "C" fn z_keyexpr_new(name: *const c_char) -> z_owned_keyexpr_t
Ok(name) => match KeyExpr::try_from(name) {
Ok(v) => v.into_owned().into(),
Err(e) => {
log::error!("Couldn't construct a keyexpr from {:02x?}: {}", name, e);
tracing::error!("Couldn't construct a keyexpr from {:02x?}: {}", name, e);
z_owned_keyexpr_t::null()
}
},
Err(e) => {
log::error!("{}", e);
tracing::error!("{}", e);
z_owned_keyexpr_t::null()
}
}
Expand All @@ -118,13 +118,13 @@ pub unsafe extern "C" fn z_keyexpr_new_autocanonize(name: *const c_char) -> z_ow
match KeyExpr::autocanonize(name_owned) {
Ok(v) => v.into_owned().into(),
Err(e) => {
log::error!("Couldn't construct a keyexpr from {:02x?}: {}", name, e);
tracing::error!("Couldn't construct a keyexpr from {:02x?}: {}", name, e);
z_owned_keyexpr_t::null()
}
}
}
Err(e) => {
log::error!("{}", e);
tracing::error!("{}", e);
z_owned_keyexpr_t::null()
}
}
Expand Down Expand Up @@ -240,12 +240,12 @@ pub unsafe extern "C" fn z_keyexpr_is_canon(start: *const c_char, len: usize) ->
Ok(name) => match keyexpr::new(name) {
Ok(_) => 0,
Err(e) => {
log::error!("Couldn't construct a keyexpr from `{}`: {}", name, e);
tracing::error!("Couldn't construct a keyexpr from `{}`: {}", name, e);
e.errno().get()
}
},
Err(e) => {
log::error!("{:02x?} is not valid UTF8 {}", name, e);
tracing::error!("{:02x?} is not valid UTF8 {}", name, e);
i8::MIN
}
}
Expand Down Expand Up @@ -288,12 +288,12 @@ pub unsafe extern "C" fn z_keyexpr_canonize(start: *mut c_char, len: &mut usize)
0
}
Err(e) => {
log::error!("Canonization error: {e}");
tracing::error!("Canonization error: {e}");
e.errno().get()
}
},
Err(e) => {
log::error!("{:02x?} is not valid UTF8 {}", name, e);
tracing::error!("{:02x?} is not valid UTF8 {}", name, e);
i8::MIN
}
}
Expand All @@ -309,12 +309,12 @@ pub unsafe extern "C" fn zc_keyexpr_from_slice(name: *const c_char, len: usize)
Ok(name) => match KeyExpr::try_from(name) {
Ok(v) => v.into(),
Err(e) => {
log::error!("Couldn't construct a keyexpr from `{}`: {}", name, e);
tracing::error!("Couldn't construct a keyexpr from `{}`: {}", name, e);
z_keyexpr_t::null()
}
},
Err(e) => {
log::error!("{:02x?} is not valid UTF8 {}", name, e);
tracing::error!("{:02x?} is not valid UTF8 {}", name, e);
z_keyexpr_t::null()
}
}
Expand Down Expand Up @@ -455,20 +455,20 @@ pub extern "C" fn z_declare_keyexpr(
let key_expr = match keyexpr.as_ref() {
Some(ke) => ke,
None => {
log::warn!("{}", UninitializedKeyExprError);
tracing::warn!("{}", UninitializedKeyExprError);
return z_owned_keyexpr_t::null();
}
};
match session.upgrade() {
Some(s) => match s.declare_keyexpr(key_expr).res_sync() {
Ok(id) => id.into_owned().into(),
Err(e) => {
log::debug!("{}", e);
tracing::debug!("{}", e);
z_owned_keyexpr_t::null()
}
},
None => {
log::debug!("{}", LOG_INVALID_SESSION);
tracing::debug!("{}", LOG_INVALID_SESSION);
z_owned_keyexpr_t::null()
}
}
Expand All @@ -479,20 +479,20 @@ pub extern "C" fn z_declare_keyexpr(
#[no_mangle]
pub extern "C" fn z_undeclare_keyexpr(session: z_session_t, kexpr: &mut z_owned_keyexpr_t) -> i8 {
let Some(kexpr) = kexpr.deref_mut().take() else {
log::debug!("Attempted to undeclare dropped keyexpr");
tracing::debug!("Attempted to undeclare dropped keyexpr");
return i8::MIN;
};

match session.upgrade() {
Some(s) => match s.undeclare(kexpr).res() {
Ok(()) => 0,
Err(e) => {
log::debug!("{}", e);
tracing::debug!("{}", e);
e.errno().get()
}
},
None => {
log::debug!("{}", LOG_INVALID_SESSION);
tracing::debug!("{}", LOG_INVALID_SESSION);
i8::MIN
}
}
Expand Down Expand Up @@ -570,7 +570,7 @@ pub unsafe extern "C" fn z_keyexpr_concat(
let right = match std::str::from_utf8(right) {
Ok(r) => r,
Err(e) => {
log::error!(
tracing::error!(
"Couldn't concatenate {:02x?} to {} because it is not valid UTF8: {}",
right,
left,
Expand All @@ -582,7 +582,7 @@ pub unsafe extern "C" fn z_keyexpr_concat(
match left.concat(right) {
Ok(result) => result.into(),
Err(e) => {
log::error!("{}", e);
tracing::error!("{}", e);
z_owned_keyexpr_t::null()
}
}
Expand All @@ -604,7 +604,7 @@ pub extern "C" fn z_keyexpr_join(left: z_keyexpr_t, right: z_keyexpr_t) -> z_own
match left.join(right.as_str()) {
Ok(result) => result.into(),
Err(e) => {
log::error!("{}", e);
tracing::error!("{}", e);
z_owned_keyexpr_t::null()
}
}
Expand Down
Loading
Loading