Skip to content

Commit e44af12

Browse files
authored
feat(rc)!: add process_tags to remote config Target (#1586)
# What does this PR do? This PR allows to send process_tags through Remote Configuration payload. This PR comes with DataDog/dd-trace-php#3658 testing the feature in PHP Tracer. # Motivation Process tags must be sent by dd-trace-php for every product including RC. PHP tracer is using libdatadog for sending RC payload. # How to test the change? The changes is mainly validated in dd-trace-php. I also added a test here and modified the one impacted by the add of process_tags in the `.proto`. Co-authored-by: louis.tricot <louis.tricot@datadoghq.com>
1 parent bb2b2bb commit e44af12

18 files changed

Lines changed: 109 additions & 20 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: 62 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,8 @@ 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(),
330+
container_tags: vec![],
328331
}),
329332
is_agent: false,
330333
client_agent: None,
@@ -601,6 +604,19 @@ pub mod tests {
601604
env: "env".to_string(),
602605
app_version: "1.3.5".to_string(),
603606
tags: vec![],
607+
process_tags: vec![],
608+
})
609+
});
610+
pub(crate) static DUMMY_TARGET_WITH_PROCESS_TAGS: LazyLock<Arc<Target>> = LazyLock::new(|| {
611+
Arc::new(Target {
612+
service: "service".to_string(),
613+
env: "env".to_string(),
614+
app_version: "1.3.5".to_string(),
615+
tags: vec![],
616+
process_tags: vec![
617+
libdd_common::tag!("entrypoint.workdir", "datadog-remote-config"),
618+
libdd_common::tag!("entrypoint.type", "script"),
619+
],
604620
})
605621
});
606622

@@ -898,6 +914,52 @@ pub mod tests {
898914
}
899915
}
900916

917+
#[tokio::test]
918+
#[cfg_attr(miri, ignore)]
919+
async fn test_process_tags_forwarded_in_client_tracer() {
920+
let server: Arc<RemoteConfigServer> = RemoteConfigServer::spawn();
921+
server.files.lock().unwrap().insert(
922+
PATH_FIRST.clone(),
923+
(
924+
vec![DUMMY_TARGET_WITH_PROCESS_TAGS.clone()],
925+
1,
926+
"v1".to_string(),
927+
),
928+
);
929+
930+
let storage = Arc::new(Storage::default());
931+
let mut fetcher = ConfigFetcher::new(
932+
storage,
933+
Arc::new(ConfigFetcherState::new(server.dummy_options().invariants)),
934+
);
935+
let mut opaque_state = ConfigClientState::default();
936+
937+
let fetched = fetcher
938+
.fetch_once(
939+
DUMMY_RUNTIME_ID,
940+
DUMMY_TARGET_WITH_PROCESS_TAGS.clone(),
941+
&server.dummy_product_capabilities(),
942+
"foo",
943+
&mut opaque_state,
944+
)
945+
.await
946+
.unwrap()
947+
.unwrap();
948+
949+
assert_eq!(fetched.len(), 1);
950+
951+
let req = server.last_request.lock().unwrap();
952+
let req = req.as_ref().unwrap();
953+
let tracer = req.client.as_ref().unwrap().client_tracer.as_ref().unwrap();
954+
assert_eq!(
955+
tracer.process_tags,
956+
&[
957+
"entrypoint.workdir:datadog-remote-config",
958+
"entrypoint.type:script"
959+
]
960+
);
961+
}
962+
901963
#[test]
902964
#[cfg_attr(miri, ignore)]
903965
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: 5 additions & 4 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
}
@@ -588,7 +589,7 @@ pub unsafe extern "C" fn ddog_sidecar_session_set_config(
588589
remote_config_capabilities_count: usize,
589590
remote_config_enabled: bool,
590591
is_fork: bool,
591-
process_tags: ffi::CharSlice,
592+
process_tags: &libdd_common_ffi::Vec<Tag>,
592593
) -> MaybeError {
593594
#[cfg(unix)]
594595
let remote_config_notify_target = libc::getpid();
@@ -632,7 +633,7 @@ pub unsafe extern "C" fn ddog_sidecar_session_set_config(
632633
.as_slice()
633634
.to_vec(),
634635
remote_config_enabled,
635-
process_tags: process_tags.to_utf8_lossy().into(),
636+
process_tags: process_tags.to_vec(),
636637
},
637638
is_fork
638639
));
@@ -646,12 +647,12 @@ pub unsafe extern "C" fn ddog_sidecar_session_set_config(
646647
pub unsafe extern "C" fn ddog_sidecar_session_set_process_tags(
647648
transport: &mut Box<SidecarTransport>,
648649
session_id: ffi::CharSlice,
649-
process_tags: ffi::CharSlice,
650+
process_tags: &libdd_common_ffi::Vec<Tag>,
650651
) -> MaybeError {
651652
try_c!(blocking::set_session_process_tags(
652653
transport,
653654
session_id.to_utf8_lossy().into(),
654-
process_tags.to_utf8_lossy().into(),
655+
process_tags.to_vec(),
655656
));
656657

657658
MaybeError::None

datadog-sidecar-ffi/tests/sidecar.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ fn test_ddog_sidecar_register_app() {
8787
.unwrap();
8888

8989
unsafe {
90+
let process_tags = libdd_common_ffi::Vec::default();
9091
ddog_sidecar_session_set_config(
9192
&mut transport,
9293
"session_id".into(),
@@ -112,7 +113,7 @@ fn test_ddog_sidecar_register_app() {
112113
0,
113114
false,
114115
false,
115-
"".into(),
116+
&process_tags,
116117
)
117118
.unwrap_none();
118119

@@ -163,7 +164,7 @@ fn test_ddog_sidecar_register_app() {
163164
0,
164165
false,
165166
false,
166-
"".into(),
167+
&process_tags,
167168
)
168169
.unwrap_none();
169170

datadog-sidecar/src/service/blocking.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,15 +249,15 @@ pub fn set_session_config(
249249
///
250250
/// * `transport` - The transport used for communication.
251251
/// * `session_id` - The ID of the session.
252-
/// * `process_tags` - The process tags string to set.
252+
/// * `process_tags` - The process tags to set.
253253
///
254254
/// # Returns
255255
///
256256
/// An `io::Result<()>` indicating the result of the operation.
257257
pub fn set_session_process_tags(
258258
transport: &mut SidecarTransport,
259259
session_id: String,
260-
process_tags: String,
260+
process_tags: Vec<Tag>,
261261
) -> io::Result<()> {
262262
transport.send(SidecarInterfaceRequest::SetSessionProcessTags {
263263
session_id,

datadog-sidecar/src/service/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub struct SessionConfig {
6464
pub remote_config_products: Vec<RemoteConfigProduct>,
6565
pub remote_config_capabilities: Vec<RemoteConfigCapabilities>,
6666
pub remote_config_enabled: bool,
67-
pub process_tags: String,
67+
pub process_tags: Vec<Tag>,
6868
}
6969

7070
#[derive(Debug, Deserialize, Serialize)]

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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ impl ActiveApplication {
142142
.as_ref()
143143
.expect("Expecting remote config invariants to be set early")
144144
.clone();
145+
146+
let process_tags = session.process_tags.lock_or_panic().clone();
147+
145148
if *session.remote_config_enabled.lock_or_panic() {
146149
self.remote_config_guard = Some(
147150
remote_configs.add_runtime(
@@ -158,6 +161,7 @@ impl ActiveApplication {
158161
.expect("set_metadata was called before"),
159162
self.global_tags.clone(),
160163
dynamic_instrumentation_state,
164+
process_tags,
161165
),
162166
);
163167
}

0 commit comments

Comments
 (0)