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
4 changes: 4 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ component_management:
name: libdd-profiling-ffi # this is a display name, and can be changed freely
paths:
- libdd-profiling-ffi
- component_id: sampling # this is an identifier that should not be changed
name: libdd-sampling # this is a display name, and can be changed freely
paths:
- libdd-sampling
- component_id: sidecar # this is an identifier that should not be changed
name: datadog-sidecar # this is a display name, and can be changed freely
paths:
Expand Down
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ libdd-library-config*/ @DataDog/apm-sdk-capabilities-rust
libdd-log*/ @DataDog/apm-common-components-core
libdd-otel-thread-ctx/ @DataDog/apm-common-components-core
libdd-profiling*/ @DataDog/libdatadog-profiling
libdd-sampling/ @DataDog/apm-common-components-core
libdd-shared-runtime*/ @DataDog/apm-common-components-core
libdd-telemetry*/ @DataDog/apm-common-components-core
libdd-tinybytes @DataDog/apm-common-components-core
Expand Down
6 changes: 6 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,9 @@ crashtracker:
'libdd-crashtracker/**/*',
'libdd-crashtracker-ffi/**/*',
]

sampling:
- changed-files:
- any-glob-to-any-file: [
'libdd-sampling/**/*',
]
26 changes: 26 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 @@ -53,6 +53,7 @@ members = [
"libdd-http-client",
"libdd-log",
"libdd-log-ffi",
"libdd-sampling",
]

# https://doc.rust-lang.org/cargo/reference/resolver.html
Expand Down
1 change: 1 addition & 0 deletions LICENSE-3rdparty.csv
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ linux-raw-sys,https://github.com/sunfishcode/linux-raw-sys,Apache-2.0 WITH LLVM-
litemap,https://github.com/unicode-org/icu4x,Unicode-3.0,The ICU4X Project Developers
lock_api,https://github.com/Amanieu/parking_lot,MIT OR Apache-2.0,Amanieu d'Antras <amanieu@gmail.com>
log,https://github.com/rust-lang/log,MIT OR Apache-2.0,The Rust Project Developers
lru,https://github.com/jeromefroe/lru-rs,MIT,Jerome Froelich <jeromefroelic@hotmail.com>
manual_future,https://github.com/dmarcuse/manual_future,MIT,Dominic Marcuse <dominic@marcuse.us>
matchers,https://github.com/hawkw/matchers,MIT,Eliza Weisman <eliza@buoyant.io>
matchit,https://github.com/ibraheemdev/matchit,MIT AND BSD-3-Clause,Ibraheem Ahmed <ibraheem@ibraheem.ca>
Expand Down
2 changes: 1 addition & 1 deletion benchmark/run_benchmarks_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pushd "${PROJECT_DIR}" > /dev/null

# Run benchmarks
message "Running benchmarks"
cargo bench --workspace --features libdd-crashtracker/benchmarking -- --warm-up-time 1 --measurement-time 5 --sample-size=200
cargo bench --workspace --features libdd-crashtracker/benchmarking,libdd-sampling/v04_span -- --warm-up-time 1 --measurement-time 5 --sample-size=200
message "Finished running benchmarks"

# Copy the benchmark results to the output directory
Expand Down
47 changes: 46 additions & 1 deletion libdd-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use anyhow::Context;
use http::uri;
use serde::de::Error;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::sync::{Mutex, MutexGuard};
use std::sync::{Mutex, MutexGuard, RwLock, RwLockReadGuard, RwLockWriteGuard};
use std::{borrow::Cow, ops::Deref, path::PathBuf, str::FromStr};

pub mod azure_app_services;
Expand Down Expand Up @@ -90,6 +90,51 @@ impl<T> MutexExt<T> for Mutex<T> {
}
}

/// Extension trait for `RwLock` to provide methods that acquire read/write locks, panicking if
/// the lock is poisoned.
///
/// Mirrors [`MutexExt`] for `RwLock` so callers avoid `#[allow(clippy::unwrap_used)]` at each
/// lock site.
///
/// # Examples
///
/// ```
/// use libdd_common::RwLockExt;
/// use std::sync::{Arc, RwLock};
///
/// let data = Arc::new(RwLock::new(5));
/// let data_clone = Arc::clone(&data);
///
/// std::thread::spawn(move || {
/// let mut num = data_clone.write_or_panic();
/// *num += 1;
/// })
/// .join()
/// .expect("Thread panicked");
///
/// assert_eq!(*data.read_or_panic(), 6);
/// ```
pub trait RwLockExt<T> {
fn read_or_panic(&self) -> RwLockReadGuard<'_, T>;
fn write_or_panic(&self) -> RwLockWriteGuard<'_, T>;
}

impl<T> RwLockExt<T> for RwLock<T> {
#[inline(always)]
#[track_caller]
fn read_or_panic(&self) -> RwLockReadGuard<'_, T> {
#[allow(clippy::unwrap_used)]
self.read().unwrap()
}

#[inline(always)]
#[track_caller]
fn write_or_panic(&self) -> RwLockWriteGuard<'_, T> {
#[allow(clippy::unwrap_used)]
self.write().unwrap()
}
}

pub mod header {
#![allow(clippy::declare_interior_mutable_const)]
use http::{header::HeaderName, HeaderValue};
Expand Down
37 changes: 37 additions & 0 deletions libdd-sampling/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright 2025-Present Datadog, Inc. https://www.datadoghq.com/
# SPDX-License-Identifier: Apache-2.0

[package]
name = "libdd-sampling"
version = "0.1.0"
edition.workspace = true
rust-version.workspace = true
license.workspace = true
homepage = "https://github.com/DataDog/libdatadog/tree/main/libdd-sampling"
repository = "https://github.com/DataDog/libdatadog/tree/main/libdd-sampling"
description = "Core sampling logic for Datadog tracing"
authors.workspace = true
autobenches = false

[lib]
bench = false

[[bench]]
name = "sampling_bench"
harness = false
path = "benches/sampling_bench.rs"
required-features = ["v04_span"]

[dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
lru = "0.16.3"
libdd-common = { path = "../libdd-common", version = "4.0.0" }
libdd-trace-utils = { path = "../libdd-trace-utils", version = "3.0.1", optional = true }

[features]
v04_span = ["dep:libdd-trace-utils"]

[dev-dependencies]
criterion = "0.5"
libdd-common = { path = "../libdd-common", version = "4.0.0", features = ["bench-utils"] }
Loading
Loading