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
1 change: 1 addition & 0 deletions datadog-remote-config/examples/remote_config_fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ async fn main() {
env: ENV.to_string(),
app_version: VERSION.to_string(),
tags: vec![Tag::new("test", "value").unwrap()],
process_tags: vec![],
},
RUNTIME_ID.to_string(),
ConfigOptions {
Expand Down
62 changes: 62 additions & 0 deletions datadog-remote-config/src/fetch/fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ impl<S: FileStorage> ConfigFetcher<S> {
env,
app_version,
tags,
process_tags,
} = (*target).clone();

let mut cached_target_files = vec![];
Expand Down Expand Up @@ -325,6 +326,8 @@ impl<S: FileStorage> ConfigFetcher<S> {
env,
app_version,
tags: tags.iter().map(|t| t.to_string()).collect(),
process_tags: process_tags.iter().map(|t| t.to_string()).collect(),
container_tags: vec![],
}),
is_agent: false,
client_agent: None,
Expand Down Expand Up @@ -601,6 +604,19 @@ pub mod tests {
env: "env".to_string(),
app_version: "1.3.5".to_string(),
tags: vec![],
process_tags: vec![],
})
});
pub(crate) static DUMMY_TARGET_WITH_PROCESS_TAGS: LazyLock<Arc<Target>> = LazyLock::new(|| {
Comment thread
danielsn marked this conversation as resolved.
Arc::new(Target {
service: "service".to_string(),
env: "env".to_string(),
app_version: "1.3.5".to_string(),
tags: vec![],
process_tags: vec![
libdd_common::tag!("entrypoint.workdir", "datadog-remote-config"),
libdd_common::tag!("entrypoint.type", "script"),
],
})
});

Expand Down Expand Up @@ -898,6 +914,52 @@ pub mod tests {
}
}

#[tokio::test]
#[cfg_attr(miri, ignore)]
async fn test_process_tags_forwarded_in_client_tracer() {
let server: Arc<RemoteConfigServer> = RemoteConfigServer::spawn();
server.files.lock().unwrap().insert(
PATH_FIRST.clone(),
(
vec![DUMMY_TARGET_WITH_PROCESS_TAGS.clone()],
1,
"v1".to_string(),
),
);

let storage = Arc::new(Storage::default());
let mut fetcher = ConfigFetcher::new(
storage,
Arc::new(ConfigFetcherState::new(server.dummy_options().invariants)),
);
let mut opaque_state = ConfigClientState::default();

let fetched = fetcher
.fetch_once(
DUMMY_RUNTIME_ID,
DUMMY_TARGET_WITH_PROCESS_TAGS.clone(),
&server.dummy_product_capabilities(),
"foo",
&mut opaque_state,
)
.await
.unwrap()
.unwrap();

assert_eq!(fetched.len(), 1);

let req = server.last_request.lock().unwrap();
let req = req.as_ref().unwrap();
let tracer = req.client.as_ref().unwrap().client_tracer.as_ref().unwrap();
assert_eq!(
tracer.process_tags,
&[
"entrypoint.workdir:datadog-remote-config",
"entrypoint.type:script"
]
);
}

#[test]
#[cfg_attr(miri, ignore)]
fn test_capability_encoding() {
Expand Down
1 change: 1 addition & 0 deletions datadog-remote-config/src/fetch/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ pub mod tests {
env: "env".to_string(),
app_version: "7.8.9".to_string(),
tags: vec![],
process_tags: vec![],
})
});

Expand Down
1 change: 1 addition & 0 deletions datadog-remote-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub struct Target {
pub env: String,
pub app_version: String,
pub tags: Vec<Tag>,
pub process_tags: Vec<Tag>,
Comment thread
dubloom marked this conversation as resolved.
}

#[repr(C)]
Expand Down
9 changes: 5 additions & 4 deletions datadog-sidecar-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ pub unsafe extern "C" fn ddog_remote_config_reader_for_endpoint<'a>(
env: env_name.to_utf8_lossy().into(),
app_version: app_version.to_utf8_lossy().into(),
tags: tags.as_slice().to_vec(),
process_tags: vec![],
}),
))
}
Expand Down Expand Up @@ -588,7 +589,7 @@ pub unsafe extern "C" fn ddog_sidecar_session_set_config(
remote_config_capabilities_count: usize,
remote_config_enabled: bool,
is_fork: bool,
process_tags: ffi::CharSlice,
process_tags: &libdd_common_ffi::Vec<Tag>,
) -> MaybeError {
#[cfg(unix)]
let remote_config_notify_target = libc::getpid();
Expand Down Expand Up @@ -632,7 +633,7 @@ pub unsafe extern "C" fn ddog_sidecar_session_set_config(
.as_slice()
.to_vec(),
remote_config_enabled,
process_tags: process_tags.to_utf8_lossy().into(),
process_tags: process_tags.to_vec(),
},
is_fork
));
Expand All @@ -646,12 +647,12 @@ pub unsafe extern "C" fn ddog_sidecar_session_set_config(
pub unsafe extern "C" fn ddog_sidecar_session_set_process_tags(
transport: &mut Box<SidecarTransport>,
session_id: ffi::CharSlice,
process_tags: ffi::CharSlice,
process_tags: &libdd_common_ffi::Vec<Tag>,
) -> MaybeError {
try_c!(blocking::set_session_process_tags(
transport,
session_id.to_utf8_lossy().into(),
process_tags.to_utf8_lossy().into(),
process_tags.to_vec(),
));

MaybeError::None
Expand Down
5 changes: 3 additions & 2 deletions datadog-sidecar-ffi/tests/sidecar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ fn test_ddog_sidecar_register_app() {
.unwrap();

unsafe {
let process_tags = libdd_common_ffi::Vec::default();
ddog_sidecar_session_set_config(
&mut transport,
"session_id".into(),
Expand All @@ -112,7 +113,7 @@ fn test_ddog_sidecar_register_app() {
0,
false,
false,
"".into(),
&process_tags,
)
.unwrap_none();

Expand Down Expand Up @@ -163,7 +164,7 @@ fn test_ddog_sidecar_register_app() {
0,
false,
false,
"".into(),
&process_tags,
)
.unwrap_none();

Expand Down
4 changes: 2 additions & 2 deletions datadog-sidecar/src/service/blocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,15 +249,15 @@ pub fn set_session_config(
///
/// * `transport` - The transport used for communication.
/// * `session_id` - The ID of the session.
/// * `process_tags` - The process tags string to set.
/// * `process_tags` - The process tags to set.
///
/// # Returns
///
/// An `io::Result<()>` indicating the result of the operation.
pub fn set_session_process_tags(
transport: &mut SidecarTransport,
session_id: String,
process_tags: String,
process_tags: Vec<Tag>,
) -> io::Result<()> {
transport.send(SidecarInterfaceRequest::SetSessionProcessTags {
session_id,
Expand Down
2 changes: 1 addition & 1 deletion datadog-sidecar/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub struct SessionConfig {
pub remote_config_products: Vec<RemoteConfigProduct>,
pub remote_config_capabilities: Vec<RemoteConfigCapabilities>,
pub remote_config_enabled: bool,
pub process_tags: String,
pub process_tags: Vec<Tag>,
}

#[derive(Debug, Deserialize, Serialize)]
Expand Down
2 changes: 2 additions & 0 deletions datadog-sidecar/src/service/remote_configs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ impl RemoteConfigs {
app_version: String,
tags: Vec<Tag>,
dynamic_instrumentation_state: DynamicInstrumentationConfigState,
process_tags: Vec<Tag>,
) -> RemoteConfigsGuard {
match self.0.lock_or_panic().entry(options.invariants) {
Entry::Occupied(e) => e.into_mut(),
Expand Down Expand Up @@ -148,6 +149,7 @@ impl RemoteConfigs {
capabilities: options.capabilities,
},
dynamic_instrumentation_state,
process_tags,
)
}

Expand Down
4 changes: 4 additions & 0 deletions datadog-sidecar/src/service/runtime_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ impl ActiveApplication {
.as_ref()
.expect("Expecting remote config invariants to be set early")
.clone();

let process_tags = session.process_tags.lock_or_panic().clone();

if *session.remote_config_enabled.lock_or_panic() {
self.remote_config_guard = Some(
remote_configs.add_runtime(
Expand All @@ -158,6 +161,7 @@ impl ActiveApplication {
.expect("set_metadata was called before"),
self.global_tags.clone(),
dynamic_instrumentation_state,
process_tags,
),
);
}
Expand Down
4 changes: 2 additions & 2 deletions datadog-sidecar/src/service/session_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::log::{MultiEnvFilterGuard, MultiWriterGuard};
use crate::{spawn_map_err, tracer};
use datadog_live_debugger::sender::{DebuggerType, PayloadSender};
use datadog_remote_config::fetch::ConfigOptions;
use libdd_common::MutexExt;
use libdd_common::{tag::Tag, MutexExt};
use tracing::log::warn;
use tracing::{debug, error, info, trace};

Expand Down Expand Up @@ -43,7 +43,7 @@ pub(crate) struct SessionInfo {
pub(crate) session_id: String,
pub(crate) pid: Arc<AtomicI32>,
pub(crate) remote_config_enabled: Arc<Mutex<bool>>,
pub(crate) process_tags: Arc<Mutex<Option<String>>>,
pub(crate) process_tags: Arc<Mutex<Vec<Tag>>>,
}

impl Clone for SessionInfo {
Expand Down
4 changes: 2 additions & 2 deletions datadog-sidecar/src/service/sidecar_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ pub trait SidecarInterface {
/// # Arguments
///
/// * `session_id` - The ID of the session.
/// * `process_tags` - The process tags string.
/// * `process_tags` - The process tags.
#[force_backpressure]
async fn set_session_process_tags(session_id: String, process_tags: String);
async fn set_session_process_tags(session_id: String, process_tags: Vec<Tag>);

/// Shuts down a runtime.
///
Expand Down
7 changes: 3 additions & 4 deletions datadog-sidecar/src/service/sidecar_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,8 +567,7 @@ impl SidecarInterface for SidecarServer {
*session.remote_config_notify_function.lock().unwrap() = remote_config_notify_function;
}
*session.remote_config_enabled.lock_or_panic() = config.remote_config_enabled;
*session.process_tags.lock_or_panic() =
(!config.process_tags.is_empty()).then_some(config.process_tags.clone());
*session.process_tags.lock_or_panic() = config.process_tags.clone();
session.modify_telemetry_config(|cfg| {
cfg.telemetry_heartbeat_interval = config.telemetry_heartbeat_interval;
let endpoint = get_product_endpoint(
Expand Down Expand Up @@ -664,10 +663,10 @@ impl SidecarInterface for SidecarServer {
self,
_: Context,
session_id: String,
process_tags: String,
process_tags: Vec<Tag>,
) -> Self::SetSessionProcessTagsFut {
let session = self.get_session(&session_id);
*session.process_tags.lock_or_panic() = (!process_tags.is_empty()).then_some(process_tags);
*session.process_tags.lock_or_panic() = process_tags;
no_response()
}

Expand Down
12 changes: 9 additions & 3 deletions datadog-sidecar/src/service/telemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl TelemetryCachedClient {
instance_id: &InstanceId,
runtime_meta: &RuntimeMetadata,
get_config: impl FnOnce() -> libdd_telemetry::config::Config,
process_tags: Option<String>,
process_tags: Vec<Tag>,
) -> Self {
let mut builder = TelemetryWorkerBuilder::new_fetch_host(
service.to_string(),
Expand All @@ -88,7 +88,13 @@ impl TelemetryCachedClient {

builder.runtime_id = Some(instance_id.runtime_id.clone());
builder.application.env = Some(env.to_string());
builder.application.process_tags = process_tags;
builder.application.process_tags = (!process_tags.is_empty()).then(|| {
process_tags
.iter()
.map(|tag| tag.to_string())
.collect::<Vec<_>>()
.join(",")
});
let config = get_config();
builder.config = config.clone();

Expand Down Expand Up @@ -300,7 +306,7 @@ impl TelemetryCachedClientSet {
instance_id: &InstanceId,
runtime_meta: &RuntimeMetadata,
get_config: F,
process_tags: Option<String>,
process_tags: Vec<Tag>,
) -> Arc<Mutex<TelemetryCachedClient>>
where
F: FnOnce() -> libdd_telemetry::config::Config,
Expand Down
4 changes: 4 additions & 0 deletions datadog-sidecar/src/shm_remote_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,12 +461,14 @@ impl<N: NotifyTarget + 'static> ShmRemoteConfigs<N> {
tags: Vec<Tag>,
product_capabilities: ProductCapabilities,
dynamic_instrumentation_state: DynamicInstrumentationConfigState,
process_tags: Vec<Tag>,
) -> ShmRemoteConfigsGuard<N> {
let target = Arc::new(Target {
service,
env,
app_version,
tags,
process_tags,
});
self.0.add_runtime(
runtime_id.clone(),
Expand Down Expand Up @@ -776,6 +778,7 @@ mod tests {
env: "env".to_string(),
app_version: "1.3.5".to_string(),
tags: vec![],
process_tags: vec![],
})
});

Expand Down Expand Up @@ -852,6 +855,7 @@ mod tests {
capabilities: server.dummy_options().capabilities,
},
DynamicInstrumentationConfigState::Disabled,
DUMMY_TARGET.process_tags.clone(),
);

receiver.recv().await;
Expand Down
1 change: 1 addition & 0 deletions datadog-tracer-flare/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ impl TracerFlareManager {
env,
app_version,
tags: vec![],
process_tags: vec![],
},
runtime_id,
config_to_fetch,
Expand Down
2 changes: 2 additions & 0 deletions libdd-trace-protobuf/src/pb/remoteconfig.proto
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ message ClientTracer {
string env = 5;
string app_version = 6;
repeated string tags = 7;
repeated string process_tags = 9;
Comment thread
danielsn marked this conversation as resolved.
repeated string container_tags = 10;
}

message ClientAgent {
Expand Down
4 changes: 4 additions & 0 deletions libdd-trace-protobuf/src/remoteconfig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ pub struct ClientTracer {
pub app_version: ::prost::alloc::string::String,
#[prost(string, repeated, tag = "7")]
pub tags: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
#[prost(string, repeated, tag = "9")]
Comment thread
dubloom marked this conversation as resolved.
pub process_tags: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
#[prost(string, repeated, tag = "10")]
pub container_tags: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
}
#[derive(Deserialize, Serialize)]
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
Expand Down
Loading