Skip to content
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pin-project-lite = "0.2"
prost = "0.13"
prost-build = "0.13"
prost-types = "0.13"
rand = { version = "0.8", default-features = false }
rand = { version = "0.9", default-features = false }
reqwest = { version = "0.12", default-features = false }
serde = { version = "1.0", default-features = false }
serde_json = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ futures-channel = "0.3"
futures-executor = { workspace = true }
futures-util = { workspace = true, features = ["std", "sink", "async-await-macro"] }
percent-encoding = { version = "2.0", optional = true }
rand = { workspace = true, features = ["std", "std_rng","small_rng"], optional = true }
rand = { workspace = true, features = ["std", "std_rng", "small_rng", "os_rng", "thread_rng"], optional = true }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see we actually removed thread_rng in other files. Why do we still need this feature?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was just renamed, thread_rng() -> rng()

glob = { version = "0.3.1", optional =true}
serde = { workspace = true, features = ["derive", "rc"], optional = true }
serde_json = { workspace = true, optional = true }
Expand Down
4 changes: 2 additions & 2 deletions opentelemetry-sdk/benches/metric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ fn bench_histogram(bound_count: usize) -> (SharedReader, Histogram<u64>) {

fn histograms(c: &mut Criterion) {
let mut group = c.benchmark_group("Histogram");
let mut rng = rand::thread_rng();
let mut rng = rand::rng();

for bound_size in [10, 49, 50, 1000].iter() {
let (_, hist) = bench_histogram(*bound_size);
Expand All @@ -313,7 +313,7 @@ fn histograms(c: &mut Criterion) {
format!("V,{},{},{}", bound_size, attr_size, i),
))
}
let value: u64 = rng.gen_range(0..MAX_BOUND).try_into().unwrap();
let value: u64 = rng.random_range(0..MAX_BOUND).try_into().unwrap();
group.bench_function(
format!("Record{}Attrs{}bounds", attr_size, bound_size),
|b| b.iter(|| hist.record(value, &attributes)),
Expand Down
44 changes: 22 additions & 22 deletions opentelemetry-sdk/benches/metrics_counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use std::cell::RefCell;

thread_local! {
/// Store random number generator for each thread
static CURRENT_RNG: RefCell<rngs::SmallRng> = RefCell::new(rngs::SmallRng::from_entropy());
static CURRENT_RNG: RefCell<rngs::SmallRng> = RefCell::new(rngs::SmallRng::from_os_rng());
}

static ATTRIBUTE_VALUES: [&str; 10] = [
Expand Down Expand Up @@ -75,10 +75,10 @@ fn counter_add_sorted(c: &mut Criterion) {
CURRENT_RNG.with(|rng| {
let mut rng = rng.borrow_mut();
[
rng.gen_range(0..4),
rng.gen_range(0..4),
rng.gen_range(0..10),
rng.gen_range(0..10),
rng.random_range(0..4),
rng.random_range(0..4),
rng.random_range(0..10),
rng.random_range(0..10),
]
})
},
Expand Down Expand Up @@ -111,10 +111,10 @@ fn counter_add_unsorted(c: &mut Criterion) {
CURRENT_RNG.with(|rng| {
let mut rng = rng.borrow_mut();
[
rng.gen_range(0..4),
rng.gen_range(0..4),
rng.gen_range(0..10),
rng.gen_range(0..10),
rng.random_range(0..4),
rng.random_range(0..4),
rng.random_range(0..10),
rng.random_range(0..10),
]
})
},
Expand Down Expand Up @@ -147,10 +147,10 @@ fn counter_add_sorted_with_non_static_values(c: &mut Criterion, attribute_values
CURRENT_RNG.with(|rng| {
let mut rng = rng.borrow_mut();
[
rng.gen_range(0..4),
rng.gen_range(0..4),
rng.gen_range(0..10),
rng.gen_range(0..10),
rng.random_range(0..4),
rng.random_range(0..4),
rng.random_range(0..10),
rng.random_range(0..10),
]
})
},
Expand Down Expand Up @@ -199,10 +199,10 @@ fn counter_overflow(c: &mut Criterion) {
let rands = CURRENT_RNG.with(|rng| {
let mut rng = rng.borrow_mut();
[
rng.gen_range(0..4),
rng.gen_range(0..4),
rng.gen_range(0..10),
rng.gen_range(0..10),
rng.random_range(0..4),
rng.random_range(0..4),
rng.random_range(0..10),
rng.random_range(0..10),
]
});
let index_first_attribute = rands[0];
Expand All @@ -228,11 +228,11 @@ fn random_generator(c: &mut Criterion) {
let __i1 = CURRENT_RNG.with(|rng| {
let mut rng = rng.borrow_mut();
[
rng.gen_range(0..4),
rng.gen_range(0..4),
rng.gen_range(0..10),
rng.gen_range(0..10),
rng.gen_range(0..10),
rng.random_range(0..4),
rng.random_range(0..4),
rng.random_range(0..10),
rng.random_range(0..10),
rng.random_range(0..10),
]
});
});
Expand Down
10 changes: 5 additions & 5 deletions opentelemetry-sdk/benches/metrics_gauge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use std::cell::RefCell;

thread_local! {
/// Store random number generator for each thread
static CURRENT_RNG: RefCell<rngs::SmallRng> = RefCell::new(rngs::SmallRng::from_entropy());
static CURRENT_RNG: RefCell<rngs::SmallRng> = RefCell::new(rngs::SmallRng::from_os_rng());
}

static ATTRIBUTE_VALUES: [&str; 10] = [
Expand Down Expand Up @@ -55,10 +55,10 @@ fn gauge_record(c: &mut Criterion) {
let rands = CURRENT_RNG.with(|rng| {
let mut rng = rng.borrow_mut();
[
rng.gen_range(0..4),
rng.gen_range(0..4),
rng.gen_range(0..10),
rng.gen_range(0..10),
rng.random_range(0..4),
rng.random_range(0..4),
rng.random_range(0..10),
rng.random_range(0..10),
]
});
let index_first_attribute = rands[0];
Expand Down
18 changes: 9 additions & 9 deletions opentelemetry-sdk/benches/metrics_histogram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use std::cell::RefCell;

thread_local! {
/// Store random number generator for each thread
static CURRENT_RNG: RefCell<rngs::SmallRng> = RefCell::new(rngs::SmallRng::from_entropy());
static CURRENT_RNG: RefCell<rngs::SmallRng> = RefCell::new(rngs::SmallRng::from_os_rng());
}

static ATTRIBUTE_VALUES: [&str; 10] = [
Expand Down Expand Up @@ -68,10 +68,10 @@ fn histogram_record(c: &mut Criterion) {
CURRENT_RNG.with(|rng| {
let mut rng = rng.borrow_mut();
[
rng.gen_range(0..4),
rng.gen_range(0..4),
rng.gen_range(0..10),
rng.gen_range(0..10),
rng.random_range(0..4),
rng.random_range(0..4),
rng.random_range(0..10),
rng.random_range(0..10),
]
})
},
Expand Down Expand Up @@ -104,10 +104,10 @@ fn histogram_record_with_non_static_values(c: &mut Criterion, attribute_values:
CURRENT_RNG.with(|rng| {
let mut rng = rng.borrow_mut();
[
rng.gen_range(0..4),
rng.gen_range(0..4),
rng.gen_range(0..10),
rng.gen_range(0..10),
rng.random_range(0..4),
rng.random_range(0..4),
rng.random_range(0..10),
rng.random_range(0..10),
]
})
},
Expand Down
6 changes: 3 additions & 3 deletions opentelemetry-sdk/src/metrics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1924,16 +1924,16 @@ mod tests {
let histogram = test_context.meter().u64_histogram("my_histogram").build();

// Act
let mut rand = rngs::SmallRng::from_entropy();
let mut rand = rngs::SmallRng::from_os_rng();
let values_kv1 = (0..50)
.map(|_| rand.gen_range(0..100))
.map(|_| rand.random_range(0..100))
.collect::<Vec<u64>>();
for value in values_kv1.iter() {
histogram.record(*value, &[KeyValue::new("key1", "value1")]);
}

let values_kv2 = (0..30)
.map(|_| rand.gen_range(0..100))
.map(|_| rand.random_range(0..100))
.collect::<Vec<u64>>();
for value in values_kv2.iter() {
histogram.record(*value, &[KeyValue::new("key1", "value2")]);
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-sdk/src/trace/id_generator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ impl IdGenerator for RandomIdGenerator {

thread_local! {
/// Store random number generator for each thread
static CURRENT_RNG: RefCell<rngs::SmallRng> = RefCell::new(rngs::SmallRng::from_entropy());
static CURRENT_RNG: RefCell<rngs::SmallRng> = RefCell::new(rngs::SmallRng::from_os_rng());
}
5 changes: 2 additions & 3 deletions opentelemetry-sdk/src/trace/sampler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ mod tests {
use super::*;
use crate::testing::trace::TestSpan;
use opentelemetry::trace::{SpanContext, SpanId, TraceFlags};
use rand::Rng;
use rand::random;

#[rustfmt::skip]
fn sampler_data() -> Vec<(&'static str, Sampler, f64, bool, bool)> {
Expand Down Expand Up @@ -301,7 +301,6 @@ mod tests {
#[test]
fn sampling() {
let total = 10_000;
let mut rng = rand::thread_rng();
for (name, sampler, expectation, parent, sample_parent) in sampler_data() {
let mut sampled = 0;
for _ in 0..total {
Expand All @@ -324,7 +323,7 @@ mod tests {
None
};

let trace_id = TraceId::from(rng.gen::<u128>());
let trace_id = TraceId::from(random::<u128>());
if sampler
.should_sample(
parent_context.as_ref(),
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-zipkin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ opentelemetry_sdk = { version = "0.28", path = "../opentelemetry-sdk", features
opentelemetry-http = { version = "0.28", path = "../opentelemetry-http" }
serde_json = { workspace = true }
serde = { workspace = true, features = ["derive"] }
typed-builder = "0.18"
typed-builder = "0.20"
http = { workspace = true }
reqwest = { workspace = true, optional = true }
thiserror = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ internal-logs = ["tracing"]
[dev-dependencies]
opentelemetry_sdk = { path = "../opentelemetry-sdk", features = ["spec_unstable_logs_enabled"]} # for documentation tests
criterion = { workspace = true }
rand = { workspace = true }
rand = { workspace = true, features = ["os_rng", "thread_rng"] }

[[bench]]
name = "metrics"
Expand Down
10 changes: 3 additions & 7 deletions opentelemetry/src/metrics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ pub trait InstrumentProvider {

#[cfg(test)]
mod tests {
use rand::Rng;
use rand::random;

use crate::KeyValue;
use std::collections::hash_map::DefaultHasher;
Expand Down Expand Up @@ -201,10 +201,8 @@ mod tests {
assert_eq!(kv1, kv2);
}

let mut rng = rand::thread_rng();

for _ in 0..100 {
let random_value = rng.gen::<f64>();
let random_value = random::<f64>();
let kv1 = KeyValue::new("key", random_value);
let kv2 = KeyValue::new("key", random_value);
assert_eq!(kv1, kv2);
Expand All @@ -228,10 +226,8 @@ mod tests {
assert_eq!(hash_helper(&kv1), hash_helper(&kv2));
}

let mut rng = rand::thread_rng();

for _ in 0..100 {
let random_value = rng.gen::<f64>();
let random_value = random::<f64>();
let kv1 = KeyValue::new("key", random_value);
let kv2 = KeyValue::new("key", random_value);
assert_eq!(hash_helper(&kv1), hash_helper(&kv2));
Expand Down
2 changes: 1 addition & 1 deletion stress/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ num_cpus = "1.15.0"
opentelemetry = { path = "../opentelemetry", features = ["metrics", "logs", "trace", "spec_unstable_logs_enabled"] }
opentelemetry_sdk = { path = "../opentelemetry-sdk", features = ["metrics", "logs", "trace", "spec_unstable_logs_enabled"] }
opentelemetry-appender-tracing = { path = "../opentelemetry-appender-tracing"}
rand = { version = "0.8.4", features = ["small_rng"] }
rand = { workspace = true, features = ["small_rng", "os_rng"] }
tracing = { workspace = true, features = ["std"]}
tracing-subscriber = { workspace = true, features = ["registry", "std"] }
num-format = "0.4.4"
Expand Down
8 changes: 4 additions & 4 deletions stress/src/metrics_counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ lazy_static! {

thread_local! {
/// Store random number generator for each thread
static CURRENT_RNG: RefCell<rngs::SmallRng> = RefCell::new(rngs::SmallRng::from_entropy());
static CURRENT_RNG: RefCell<rngs::SmallRng> = RefCell::new(rngs::SmallRng::from_os_rng());
}

fn main() {
Expand All @@ -48,9 +48,9 @@ fn test_counter() {
let rands = CURRENT_RNG.with(|rng| {
let mut rng = rng.borrow_mut();
[
rng.gen_range(0..len),
rng.gen_range(0..len),
rng.gen_range(0..len),
rng.random_range(0..len),
rng.random_range(0..len),
rng.random_range(0..len),
]
});
let index_first_attribute = rands[0];
Expand Down
8 changes: 4 additions & 4 deletions stress/src/metrics_gauge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ lazy_static! {

thread_local! {
/// Store random number generator for each thread
static CURRENT_RNG: RefCell<rngs::SmallRng> = RefCell::new(rngs::SmallRng::from_entropy());
static CURRENT_RNG: RefCell<rngs::SmallRng> = RefCell::new(rngs::SmallRng::from_os_rng());
}

fn main() {
Expand All @@ -45,9 +45,9 @@ fn test_gauge() {
let rands = CURRENT_RNG.with(|rng| {
let mut rng = rng.borrow_mut();
[
rng.gen_range(0..len),
rng.gen_range(0..len),
rng.gen_range(0..len),
rng.random_range(0..len),
rng.random_range(0..len),
rng.random_range(0..len),
]
});
let index_first_attribute = rands[0];
Expand Down
8 changes: 4 additions & 4 deletions stress/src/metrics_histogram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ lazy_static! {

thread_local! {
/// Store random number generator for each thread
static CURRENT_RNG: RefCell<rngs::SmallRng> = RefCell::new(rngs::SmallRng::from_entropy());
static CURRENT_RNG: RefCell<rngs::SmallRng> = RefCell::new(rngs::SmallRng::from_os_rng());

static PROVIDER_PER_THREAD: SdkMeterProvider = SdkMeterProvider::builder()
.with_reader(ManualReader::builder().build())
Expand Down Expand Up @@ -65,9 +65,9 @@ fn test_histogram(histogram: &Histogram<u64>) {
let rands = CURRENT_RNG.with(|rng| {
let mut rng = rng.borrow_mut();
[
rng.gen_range(0..len),
rng.gen_range(0..len),
rng.gen_range(0..len),
rng.random_range(0..len),
rng.random_range(0..len),
rng.random_range(0..len),
]
});
let index_first_attribute = rands[0];
Expand Down
4 changes: 2 additions & 2 deletions stress/src/metrics_overflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ lazy_static! {

thread_local! {
/// Store random number generator for each thread
static CURRENT_RNG: RefCell<rngs::SmallRng> = RefCell::new(rngs::SmallRng::from_entropy());
static CURRENT_RNG: RefCell<rngs::SmallRng> = RefCell::new(rngs::SmallRng::from_os_rng());
}

fn main() {
Expand All @@ -41,6 +41,6 @@ fn test_counter() {
// memory usage indefinitely even when user code misbehaves by producing
// unbounded metric points (unique time series).
// It also checks that SDK's internal logging is also done in a bounded way.
let rand = CURRENT_RNG.with(|rng| rng.borrow_mut().gen_range(0..100000000));
let rand = CURRENT_RNG.with(|rng| rng.borrow_mut().random_range(0..100000000));
COUNTER.add(1, &[KeyValue::new("A", rand)]);
}
Loading