Skip to content

Commit 11d4111

Browse files
morrisonleviyannhambwoebi
authored
refactor(otel-thread-ctx)!: gate behind feature (#1843)
# What does this PR do? Moves the `otel-thread-ctx` feature behind a Cargo feature. # Motivation This feature broke the dd-trace-php CI because they build with clang 17, and `-mtls-dialect=gnu2` is not recognized there. I expect this would be problematic for some customers as well. So it seems like a good idea for now to feature flag it. # Additional Notes I think the TracerMetadata stuff is okay since it's not `repr(C)` but someone should double-check if this is okay or not, maybe that part needs to always be there and just use empty/default values. # How to test the change? Test as usual, and you can test again when enabling feature `otel-thread-ctx`, for example: ```sh cargo test \ -p libdd-profiling\ -p libdd-library-config \ --features otel-thread-ctx ``` Or: ```sh cargo nextest run \ -p libdd-profiling \ -p libdd-library-config \ --features otel-thread-ctx ``` Co-authored-by: yannham <yann.hamdaoui@datadoghq.com> Co-authored-by: bob.weinand <bob.weinand@datadoghq.com>
1 parent 4360dbb commit 11d4111

5 files changed

Lines changed: 19 additions & 6 deletions

File tree

libdd-library-config/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ license.workspace = true
1414
crate-type = ["lib"]
1515
bench = false
1616

17+
[features]
18+
otel-thread-ctx = []
19+
1720
[dependencies]
1821
serde = { version = "1.0", features = ["derive"] }
1922
serde_yaml = "0.9.34"

libdd-library-config/src/tracer_metadata.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ pub struct TracerMetadata {
4040
/// This field is specific to OTel process context. It is ignored for (de)serialization, and is
4141
/// only used when converting to an OTel process context in
4242
/// [TracerMetadata::to_otel_process_ctx].
43+
#[cfg(feature = "otel-thread-ctx")]
4344
#[serde(skip)]
4445
pub threadlocal_attribute_keys: Vec<String>,
4546
}
@@ -57,6 +58,7 @@ impl Default for TracerMetadata {
5758
service_version: None,
5859
process_tags: None,
5960
container_id: None,
61+
#[cfg(feature = "otel-thread-ctx")]
6062
threadlocal_attribute_keys: vec![],
6163
}
6264
}
@@ -67,8 +69,10 @@ impl TracerMetadata {
6769
const OTEL_SDK_NAME: &str = "libdatadog";
6870

6971
pub fn to_otel_process_ctx(&self) -> otel_proto::common::v1::ProcessContext {
72+
#[cfg(feature = "otel-thread-ctx")]
73+
use otel_proto::common::v1::ArrayValue;
7074
use otel_proto::{
71-
common::v1::{any_value, AnyValue, ArrayValue, KeyValue, ProcessContext},
75+
common::v1::{any_value, AnyValue, KeyValue, ProcessContext},
7276
resource::v1::Resource,
7377
};
7478

@@ -102,9 +106,11 @@ impl TracerMetadata {
102106
service_version,
103107
process_tags,
104108
container_id,
109+
#[cfg(feature = "otel-thread-ctx")]
105110
threadlocal_attribute_keys,
106111
} = self;
107112

113+
#[cfg_attr(not(feature = "otel-thread-ctx"), allow(unused_mut))]
108114
let mut attributes = vec![
109115
key_value_opt("service.name", service_name),
110116
key_value_opt("service.instance.id", runtime_id),
@@ -117,6 +123,7 @@ impl TracerMetadata {
117123
key_value_opt("container.id", container_id),
118124
];
119125

126+
#[cfg(feature = "otel-thread-ctx")]
120127
if !threadlocal_attribute_keys.is_empty() {
121128
attributes.push(key_value(
122129
"threadlocal.schema_version",
@@ -217,9 +224,9 @@ pub use other::*;
217224
#[cfg(test)]
218225
mod tests {
219226
use super::*;
220-
use libdd_trace_protobuf::opentelemetry::proto::common::v1::{
221-
any_value, AnyValue, ProcessContext,
222-
};
227+
#[cfg(feature = "otel-thread-ctx")]
228+
use libdd_trace_protobuf::opentelemetry::proto::common::v1::any_value;
229+
use libdd_trace_protobuf::opentelemetry::proto::common::v1::{AnyValue, ProcessContext};
223230

224231
fn find_attr<'a>(ctx: &'a ProcessContext, key: &str) -> Option<&'a AnyValue> {
225232
ctx.resource
@@ -239,6 +246,7 @@ mod tests {
239246
assert!(find_attr(&ctx, "threadlocal.attribute_key_map").is_none());
240247
}
241248

249+
#[cfg(feature = "otel-thread-ctx")]
242250
#[test]
243251
fn threadlocal_attrs_present_with_correct_values() {
244252
let ctx = TracerMetadata {

libdd-profiling/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ bench = false
1919
[features]
2020
default = []
2121
cxx = ["dep:cxx", "dep:cxx-build"]
22+
otel-thread-ctx = []
2223
test-utils = ["libdd-common/test-utils"]
2324

2425
[[bench]]

libdd-profiling/build.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ fn main() {
1212
println!("cargo:rerun-if-changed=src/cxx.rs");
1313
}
1414

15-
// Only compile the TLS shim on Linux; the thread-level context feature is Linux-only.
16-
#[cfg(target_os = "linux")]
15+
// Only compile the TLS shim on Linux with the otel-thread-ctx feature enabled.
16+
#[cfg(all(target_os = "linux", feature = "otel-thread-ctx"))]
1717
{
1818
let mut build = cc::Build::new();
1919

libdd-profiling/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub mod cxx;
1414
pub mod exporter;
1515
pub mod internal;
1616
pub mod iter;
17+
#[cfg(feature = "otel-thread-ctx")]
1718
pub mod otel_thread_ctx;
1819
pub mod pprof;
1920
pub mod profiles;

0 commit comments

Comments
 (0)