Skip to content

Rust first variant: for review only#2

Open
scottgerring wants to merge 12 commits into
masterfrom
sgg/rust-first
Open

Rust first variant: for review only#2
scottgerring wants to merge 12 commits into
masterfrom
sgg/rust-first

Conversation

@scottgerring

@scottgerring scottgerring commented Apr 8, 2026

Copy link
Copy Markdown
Owner

Update polarsignals custom-labels repo to the new TLS format.

Decisions of relevance:

  • Let's just use prost for protobuf because that is how regular consumers will use it (and we can lift it straight from libdd)
  • Both context mechanisms provide an API generic of platform, but no-op for non-Linux-64; this involved rejigging libdd code a little
  • Let's focus on reducing diff to libdd rather than custom-labels, which means we drop the complete C bindings (it becomes just an impl detail to provide C-style TLS)

Open Qs:

  • What do we do with the license headers?
  • Do we need to do anything special to donate from libdatadog to OTel?

To see the diff against the libdd code, try this link

@scottgerring scottgerring force-pushed the sgg/rust-first branch 3 times, most recently from 688ced9 to 41ca8d2 Compare April 8, 2026 15:19
Comment thread proto/opentelemetry/proto/common/v1/process_context.proto Outdated

@ivoanjo ivoanjo left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is looking good! I think the main question to me is supporting the old api as well/keeping spin.rs as-it-was.

I kinda like the idea of showing off how the old api can be layered on the new format + providing a nice migration path for users of custom-labels (we can even ask claude to give it a stab) but let me know if you're not convinced, as I'm happy to approve as-is.

What do we do with the license headers?
Do we need to do anything special to donate from libdatadog to OTel?

custom-labels, libdatadog AND opentelemetry all use Apache v2 so they're license-compatible.

My read on 1 and 2 is that it's fine to keep the current copyrights (Datadog for files that came from libdatadog, and implicitly Polar Signals for the other files) and once this moves out of WIP we can check with all parties if we should just assign the copyright to OTel directly.

Comment thread proto/opentelemetry/proto/common/v1/process_context.proto Outdated
Comment thread src/otel_process_ctx.rs Outdated
Comment thread src/lib.rs

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This part I think it would be very nice to keep if possible -- e.g. retrofit the existing custom-labels code to use the new APIs, rather than forcing a full API rewrite.

This would provide a really nice way of testing against existing users of custom-labels -- just switch the dep and recompile; vs requiring a full API change; spin.rs would remain exactly the same, which would be a nice demo for how the new format is able to provide the same feature-set (or very close).

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

ACK ! addressed in subsequent commits as discussed offline

Comment thread build.rs
Comment on lines +10 to +13
// On x86-64, force TLSDESC dialect as required by the OTel spec.
// On aarch64, TLSDESC is already the default.
#[cfg(target_arch = "x86_64")]
build.flag("-mtls-dialect=gnu2");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Minor: Could we use mtls-dialect=gnu2 everywhere? E.g. does arm mind if we ask for the default? I think that would simplify a bit (and is one less sharp edge if someone tries to e.g. compile this on another arch)

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

nah, it fails on arm:

unrecognized argument in option '-mtls-dialect=gnu2',
  valid values are desc and trad. 

we can do the opposite ("add this if you're not arm") but i'm not confident that it's going to work on other arches either. Seeing as we only promise to support arm64 / amd64 this is probably fine?

@ivoanjo ivoanjo Apr 9, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

unrecognized argument in option '-mtls-dialect=gnu2',
  valid values are desc and trad. 

Grumble grumble why are compiler people so bad at good/sane behaviors grumble grumble.

I guess let's keep it as-is, we can figure out later what to do with other architectures...

Comment thread Cargo.toml Outdated
@scottgerring scottgerring force-pushed the sgg/rust-first branch 2 times, most recently from 46a66f8 to 148c923 Compare April 9, 2026 11:54
String::from_utf8(
rand::thread_rng()
.sample_iter(&Alphanumeric)
rand::rng()

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

because of dep update and rust's passion for prerelease crate versions

loop {
custom_labels::with_label("l1", rand_str(), || {
custom_labels::with_label("l2", rand_str(), || loop {
otel_thread_ctx::custom_labels_adapter::with_label("l1", rand_str(), || {

@scottgerring scottgerring Apr 9, 2026

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

can't do much about the namespace change; intentionally leaving the adapter "off to the side" as discussed rather than presenting a weird API

Comment thread src/otel_thread_ctx.rs
/// Mutate the currently attached record in-place with proper synchronization.
/// Sets `valid = 0` before calling `f`, and `valid = 1` after, with compiler
/// fences to prevent reordering. Returns `false` if no record is attached.
fn mutate_in_place(f: impl FnOnce(&mut ThreadContextRecord)) -> bool {

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

factored this out from update so we have the guards in one place and can use it for pop attr too

Comment thread src/otel_thread_ctx.rs

pub fn update(_trace_id: [u8; 16], _span_id: [u8; 8], _attrs: &[(u8, &str)]) {}

pub fn pop_last_attr() {}

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

no-op for non-linux

resource: Some(Resource::default()),
extra_attributes: vec![
KeyValue {
key: "threadlocal.schema_version".into(),

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

add the core attributes.
fwiw i've also tested both variants are readable with our test reader for procCtx and TLS !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants