Skip to content

Commit ae9464f

Browse files
committed
feat(rc): add process_tags to remote config Target
1 parent 04394ec commit ae9464f

11 files changed

Lines changed: 80 additions & 0 deletions

File tree

datadog-remote-config/examples/remote_config_fetch.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ async fn main() {
3333
env: ENV.to_string(),
3434
app_version: VERSION.to_string(),
3535
tags: vec![Tag::new("test", "value").unwrap()],
36+
process_tags: vec![],
3637
},
3738
RUNTIME_ID.to_string(),
3839
ConfigOptions {

datadog-remote-config/src/fetch/fetcher.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ impl<S: FileStorage> ConfigFetcher<S> {
277277
env,
278278
app_version,
279279
tags,
280+
process_tags,
280281
} = (*target).clone();
281282

282283
let mut cached_target_files = vec![];
@@ -325,6 +326,7 @@ impl<S: FileStorage> ConfigFetcher<S> {
325326
env,
326327
app_version,
327328
tags: tags.iter().map(|t| t.to_string()).collect(),
329+
process_tags: process_tags.iter().map(|t| t.to_string()).collect(),
328330
}),
329331
is_agent: false,
330332
client_agent: None,
@@ -601,6 +603,19 @@ pub mod tests {
601603
env: "env".to_string(),
602604
app_version: "1.3.5".to_string(),
603605
tags: vec![],
606+
process_tags: vec![],
607+
})
608+
});
609+
pub(crate) static DUMMY_TARGET_WITH_PROCESS_TAGS: LazyLock<Arc<Target>> = LazyLock::new(|| {
610+
Arc::new(Target {
611+
service: "service".to_string(),
612+
env: "env".to_string(),
613+
app_version: "1.3.5".to_string(),
614+
tags: vec![],
615+
process_tags: vec![
616+
libdd_common::tag::Tag::new("entrypoint.workdir", "datadog-remote-config").unwrap(),
617+
libdd_common::tag::Tag::new("entrypoint.type", "script").unwrap(),
618+
],
604619
})
605620
});
606621

@@ -898,6 +913,42 @@ pub mod tests {
898913
}
899914
}
900915

916+
#[tokio::test]
917+
#[cfg_attr(miri, ignore)]
918+
async fn test_process_tags_forwarded_in_client_tracer() {
919+
let server: Arc<RemoteConfigServer> = RemoteConfigServer::spawn();
920+
server.files.lock().unwrap().insert(
921+
PATH_FIRST.clone(),
922+
(vec![DUMMY_TARGET_WITH_PROCESS_TAGS.clone()], 1, "v1".to_string()),
923+
);
924+
925+
let storage = Arc::new(Storage::default());
926+
let mut fetcher = ConfigFetcher::new(
927+
storage,
928+
Arc::new(ConfigFetcherState::new(server.dummy_options().invariants)),
929+
);
930+
let mut opaque_state = ConfigClientState::default();
931+
932+
let fetched = fetcher
933+
.fetch_once(
934+
DUMMY_RUNTIME_ID,
935+
DUMMY_TARGET_WITH_PROCESS_TAGS.clone(),
936+
&server.dummy_product_capabilities(),
937+
"foo",
938+
&mut opaque_state,
939+
)
940+
.await
941+
.unwrap()
942+
.unwrap();
943+
944+
assert_eq!(fetched.len(), 1);
945+
946+
let req = server.last_request.lock().unwrap();
947+
let req = req.as_ref().unwrap();
948+
let tracer = req.client.as_ref().unwrap().client_tracer.as_ref().unwrap();
949+
assert_eq!(tracer.process_tags, &["entrypoint.workdir:datadog-remote-config", "entrypoint.type:script"]);
950+
}
951+
901952
#[test]
902953
#[cfg_attr(miri, ignore)]
903954
fn test_capability_encoding() {

datadog-remote-config/src/fetch/shared.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ pub mod tests {
385385
env: "env".to_string(),
386386
app_version: "7.8.9".to_string(),
387387
tags: vec![],
388+
process_tags: vec![],
388389
})
389390
});
390391

datadog-remote-config/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub struct Target {
3232
pub env: String,
3333
pub app_version: String,
3434
pub tags: Vec<Tag>,
35+
pub process_tags: Vec<Tag>,
3536
}
3637

3738
#[repr(C)]

datadog-sidecar-ffi/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ pub unsafe extern "C" fn ddog_remote_config_reader_for_endpoint<'a>(
255255
env: env_name.to_utf8_lossy().into(),
256256
app_version: app_version.to_utf8_lossy().into(),
257257
tags: tags.as_slice().to_vec(),
258+
process_tags: vec![],
258259
}),
259260
))
260261
}

datadog-sidecar/src/service/remote_configs.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ impl RemoteConfigs {
110110
app_version: String,
111111
tags: Vec<Tag>,
112112
dynamic_instrumentation_state: DynamicInstrumentationConfigState,
113+
process_tags: Vec<Tag>,
113114
) -> RemoteConfigsGuard {
114115
match self.0.lock_or_panic().entry(options.invariants) {
115116
Entry::Occupied(e) => e.into_mut(),
@@ -148,6 +149,7 @@ impl RemoteConfigs {
148149
capabilities: options.capabilities,
149150
},
150151
dynamic_instrumentation_state,
152+
process_tags,
151153
)
152154
}
153155

datadog-sidecar/src/service/runtime_info.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,13 @@ impl ActiveApplication {
142142
.as_ref()
143143
.expect("Expecting remote config invariants to be set early")
144144
.clone();
145+
146+
let process_tags = session
147+
.process_tags
148+
.lock_or_panic()
149+
.clone()
150+
.unwrap_or_default();
151+
145152
if *session.remote_config_enabled.lock_or_panic() {
146153
self.remote_config_guard = Some(
147154
remote_configs.add_runtime(
@@ -158,6 +165,14 @@ impl ActiveApplication {
158165
.expect("set_metadata was called before"),
159166
self.global_tags.clone(),
160167
dynamic_instrumentation_state,
168+
process_tags
169+
.split(',')
170+
.filter_map(|s| {
171+
s.split_once(':').and_then(|(key, value)| {
172+
libdd_common::tag::Tag::new(key, value).ok()
173+
})
174+
})
175+
.collect(),
161176
),
162177
);
163178
}

datadog-sidecar/src/shm_remote_config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,12 +461,14 @@ impl<N: NotifyTarget + 'static> ShmRemoteConfigs<N> {
461461
tags: Vec<Tag>,
462462
product_capabilities: ProductCapabilities,
463463
dynamic_instrumentation_state: DynamicInstrumentationConfigState,
464+
process_tags: Vec<Tag>,
464465
) -> ShmRemoteConfigsGuard<N> {
465466
let target = Arc::new(Target {
466467
service,
467468
env,
468469
app_version,
469470
tags,
471+
process_tags,
470472
});
471473
self.0.add_runtime(
472474
runtime_id.clone(),
@@ -776,6 +778,7 @@ mod tests {
776778
env: "env".to_string(),
777779
app_version: "1.3.5".to_string(),
778780
tags: vec![],
781+
process_tags: vec![],
779782
})
780783
});
781784

@@ -852,6 +855,7 @@ mod tests {
852855
capabilities: server.dummy_options().capabilities,
853856
},
854857
DynamicInstrumentationConfigState::Disabled,
858+
DUMMY_TARGET.process_tags.clone(),
855859
);
856860

857861
receiver.recv().await;

datadog-tracer-flare/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ impl TracerFlareManager {
192192
env,
193193
app_version,
194194
tags: vec![],
195+
process_tags: vec![],
195196
},
196197
runtime_id,
197198
config_to_fetch,

libdd-trace-protobuf/src/pb/remoteconfig.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ message ClientTracer {
3535
string env = 5;
3636
string app_version = 6;
3737
repeated string tags = 7;
38+
repeated string process_tags = 9;
3839
}
3940

4041
message ClientAgent {

0 commit comments

Comments
 (0)