Skip to content

Commit

Permalink
Fix examples, no longer export TimelineId.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmunns committed Aug 22, 2022
1 parent a90357b commit e93727f
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 38 deletions.
33 changes: 18 additions & 15 deletions tracing-modality/examples/monitored_pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::sync::{
use std::time::{Duration, Instant};
use std::{fmt, thread};
use tracing_core::Dispatch;
use tracing_modality::blocking::{timeline_id, ModalityLayer, TimelineId};
use tracing_modality::{blocking::ModalityLayer, timeline_id};
use tracing_subscriber::{fmt::Layer, layer::SubscriberExt, Registry};

fn main() {
Expand Down Expand Up @@ -134,7 +134,7 @@ pub struct MessageMetadata {
/// When was this message from?
timestamp: NanosecondsSinceUnixEpoch,
/// Which tracing timeline was this from?
timeline_id: TimelineId,
timeline_id: u64,
/// A correlation nonce for precisely matching
/// the source event related to this message.
nonce: Option<i64>,
Expand Down Expand Up @@ -231,7 +231,7 @@ mod producer {
fn send_measurement(
sample: i8,
consumer_tx: &SyncSender<MeasurementMessage>,
timeline_id: TimelineId,
timeline_id: u64,
nonce: i64,
) {
// The measurement sample value must be in the range [-50, 50]
Expand Down Expand Up @@ -307,17 +307,19 @@ mod consumer {
Ok(msg) => {
if let Some(nonce) = msg.meta.nonce {
tracing::info!(
sample = msg.sample,
interaction.remote_timeline_id = %msg.meta.timeline_id.get_raw(),
interaction.remote_timestamp = msg.meta.timestamp.0,
interaction.remote_nonce=nonce,
"Received measurement message");
sample = msg.sample,
interaction.remote_timeline_id = msg.meta.timeline_id,
interaction.remote_timestamp = msg.meta.timestamp.0,
interaction.remote_nonce = nonce,
"Received measurement message"
);
} else {
tracing::info!(
sample = msg.sample,
interaction.remote_timeline_id = %msg.meta.timeline_id.get_raw(),
interaction.remote_timestamp = msg.meta.timestamp.0,
"Received measurement message");
sample = msg.sample,
interaction.remote_timeline_id = msg.meta.timeline_id,
interaction.remote_timestamp = msg.meta.timestamp.0,
"Received measurement message"
);
}

expensive_task(msg.sample, &is_shutdown_requested);
Expand Down Expand Up @@ -380,9 +382,10 @@ mod monitor {
Ok(msg) => {
tracing::info!(
source = msg.source.name(),
interaction.remote_timeline_id = %msg.meta.timeline_id.get_raw(),
interaction.remote_timeline_id = msg.meta.timeline_id,
interaction.remote_timestamp = msg.meta.timestamp.0,
"Received heartbeat message");
"Received heartbeat message"
);
let prev = component_to_last_rx.insert(msg.source, Instant::now());
if prev.is_none() {
tracing::info!(
Expand Down Expand Up @@ -421,7 +424,7 @@ fn send_heartbeat(
source: Component,
// What is the timeline id of the component sending the heartbeat?
// Instead of passing this around, for a small cost, one could use the timeline_id() fn
timeline_id: TimelineId,
timeline_id: u64,
) {
let timestamp = match NanosecondsSinceUnixEpoch::now() {
Ok(timestamp) => timestamp,
Expand Down
20 changes: 9 additions & 11 deletions tracing-modality/examples/simple_multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use rand::{thread_rng, Rng};
use std::sync::mpsc::{channel, Receiver, Sender};
use std::thread::{Builder, JoinHandle};
use tracing::{info, info_span};
use tracing_modality::blocking::{timeline_id, TimelineId, TracingModality};
use tracing_modality::{blocking::TracingModality, timeline_id};

const THREADS: usize = 2;

Expand All @@ -13,7 +13,7 @@ enum Message {
struct Job {
nonce: u32,
num: u32,
timeline_id: TimelineId,
timeline_id: u64,
}

fn main() {
Expand Down Expand Up @@ -41,8 +41,8 @@ fn main() {
match msg {
Message::Data(job) => {
info!(
interaction.remote_nonce=job.nonce,
interaction.remote_timeline_id=?job.timeline_id.get_raw(),
interaction.remote_nonce = job.nonce,
interaction.remote_timeline_id = job.timeline_id,
job.num,
"received",
);
Expand All @@ -53,12 +53,10 @@ fn main() {
foo = "bar"
);

let result = comp_span.in_scope(|| {
job.num * 2
});
let result = comp_span.in_scope(|| job.num * 2);
//let nonce = job.nonce + THREADS as u32;
let nonce = job.nonce;
info!(nonce = nonce, source = ?timeline_id.get_raw(), result, "sending");
info!(nonce = nonce, source = timeline_id, result, "sending");
term_tx
.send(Message::Data(Job {
nonce,
Expand All @@ -85,7 +83,7 @@ fn main() {
nonce = i,
worker = target,
input = start,
source = ?timeline_id.get_raw(),
source = timeline_id,
"sending",
);
tx_chans[target]
Expand All @@ -102,8 +100,8 @@ fn main() {
match result {
Message::Data(job) => {
info!(
interaction.remote_nonce=job.nonce,
interaction.remote_timeline_id=?job.timeline_id.get_raw(),
interaction.remote_nonce = job.nonce,
interaction.remote_timeline_id = job.timeline_id,
job.num,
"result",
);
Expand Down
2 changes: 1 addition & 1 deletion tracing-modality/src/async/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod layer;
use crate::common::ingest;
pub use crate::options::Options;
use crate::InitError;
pub use ingest::{ModalityIngestTaskHandle, TimelineId};
pub use ingest::ModalityIngestTaskHandle;
pub use layer::ModalityLayer;

use anyhow::Context as _;
Expand Down
2 changes: 1 addition & 1 deletion tracing-modality/src/blocking/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod layer;

pub use crate::ingest::ModalityIngestThreadHandle;
pub use crate::{InitError, Options, TimelineId};
pub use crate::{InitError, Options};
pub use layer::ModalityLayer;

use anyhow::Context as _;
Expand Down
18 changes: 8 additions & 10 deletions tracing-modality/src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,12 @@ pub enum InitError {
UnexpectedFailure(#[from] anyhow::Error),
}

// TODO(AJM): I don't think this function should exist anymore.
//
// /// Retrieve the current local timeline ID. Useful for for sending alongside data and a custom nonce
// /// for recording timeline interactions on remote timelines.
// pub fn timeline_id() -> TimelineId {
// let f = TIMELINE_IDENTIFIER
// .get()
// .expect("Modality should be initialized before getting current timeline id");
/// Retrieve the current user timeline ID. Useful for for sending alongside data and a custom nonce
/// for recording timeline interactions on remote timelines.
pub fn timeline_id() -> u64 {
let f = TIMELINE_IDENTIFIER
.get()
.expect("Modality should be initialized before getting current timeline id");

// *(*f)().id()
// }
(*f)().user_id
}

0 comments on commit e93727f

Please sign in to comment.