Skip to content
Draft
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
5 changes: 4 additions & 1 deletion examples/ffi/trace_exporter.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ int main(int argc, char** argv)
ddog_TelemetryClientConfig telemetry_config = {
.interval = 60000,
.runtime_id = DDOG_CHARSLICE_C("12345678-1234-1234-1234-123456789abc"),
.debug_enabled = true
.debug_enabled = true,
.session_id = DDOG_CHARSLICE_C("12345678-1234-1234-1234-123456789abc"),
.root_session_id =DDOG_CHARSLICE_C("87654321-1234-1234-1234-123456789abc"),
.parent_session_id = DDOG_CHARSLICE_C(""),
};

ret = ddog_trace_exporter_config_enable_telemetry(config, &telemetry_config);
Expand Down
66 changes: 66 additions & 0 deletions libdd-data-pipeline-ffi/src/trace_exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ pub struct TelemetryClientConfig<'a> {
/// When enabled, sets the DD-Telemetry-Debug-Enabled header to true.
/// Defaults to false.
pub debug_enabled: bool,

/// Instrumentation session id (`dd-session-id`), same encoding rules as [`Self::runtime_id`].
pub session_id: CharSlice<'a>,
/// Root session id (`dd-root-session-id`).
pub root_session_id: CharSlice<'a>,
/// Parent session id (`dd-parent-session-id`).
pub parent_session_id: CharSlice<'a>,
}

/// The TraceExporterConfig object will hold the configuration properties for the TraceExporter.
Expand Down Expand Up @@ -301,6 +308,18 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_enable_telemetry(
Err(e) => return Some(e),
},
debug_enabled: telemetry_cfg.debug_enabled,
session_id: match sanitize_string(telemetry_cfg.session_id) {
Ok(s) => Some(s),
Err(e) => return Some(e),
},
root_session_id: match sanitize_string(telemetry_cfg.root_session_id) {
Ok(s) => Some(s),
Err(e) => return Some(e),
},
parent_session_id: match sanitize_string(telemetry_cfg.parent_session_id) {
Ok(s) => Some(s),
Err(e) => return Some(e),
},
};
debug!(telemetry_cfg = ?cfg, "Configuring telemetry");
config.telemetry_cfg = Some(cfg);
Expand Down Expand Up @@ -831,6 +850,9 @@ mod tests {
interval: 1000,
runtime_id: CharSlice::from("id"),
debug_enabled: false,
session_id: CharSlice::empty(),
root_session_id: CharSlice::empty(),
parent_session_id: CharSlice::empty(),
}),
);
assert_eq!(error.as_ref().unwrap().code, ErrorCode::InvalidArgument);
Expand All @@ -848,6 +870,9 @@ mod tests {
interval: 1000,
runtime_id: CharSlice::from("foo"),
debug_enabled: true,
session_id: CharSlice::empty(),
root_session_id: CharSlice::empty(),
parent_session_id: CharSlice::empty(),
}),
);
assert!(error.is_none());
Expand All @@ -863,6 +888,44 @@ mod tests {
"foo"
);
assert!(cfg.telemetry_cfg.as_ref().unwrap().debug_enabled);
assert_eq!(
cfg.telemetry_cfg.as_ref().unwrap().session_id.as_deref(),
Some("")
);
assert_eq!(
cfg.telemetry_cfg
.as_ref()
.unwrap()
.root_session_id
.as_deref(),
Some("")
);
assert_eq!(
cfg.telemetry_cfg
.as_ref()
.unwrap()
.parent_session_id
.as_deref(),
Some("")
);

let mut cfg = TraceExporterConfig::default();
let error = ddog_trace_exporter_config_enable_telemetry(
Some(&mut cfg),
Some(&TelemetryClientConfig {
interval: 500,
runtime_id: CharSlice::from("rid"),
debug_enabled: false,
session_id: CharSlice::from("sess-z"),
root_session_id: CharSlice::from("root-z"),
parent_session_id: CharSlice::from("par-z"),
}),
);
assert!(error.is_none());
let t = cfg.telemetry_cfg.as_ref().unwrap();
assert_eq!(t.session_id.as_deref(), Some("sess-z"));
assert_eq!(t.root_session_id.as_deref(), Some("root-z"));
assert_eq!(t.parent_session_id.as_deref(), Some("par-z"));
}
}

Expand Down Expand Up @@ -1143,6 +1206,9 @@ mod tests {
heartbeat: 10000,
runtime_id: Some("foo".to_string()),
debug_enabled: true,
session_id: None,
root_session_id: None,
parent_session_id: None,
}),
..Default::default()
};
Expand Down
35 changes: 34 additions & 1 deletion libdd-data-pipeline/src/telemetry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ pub struct TelemetryClientBuilder {
tracer_version: Option<String>,
config: libdd_telemetry::config::Config,
runtime_id: Option<String>,
session_id: Option<String>,
root_session_id: Option<String>,
parent_session_id: Option<String>,
}

impl TelemetryClientBuilder {
Expand Down Expand Up @@ -93,6 +96,27 @@ impl TelemetryClientBuilder {
self
}

/// Sets the instrumentation session id sent as the `dd-session-id` header on telemetry
/// requests.
pub fn set_session_id(mut self, id: &str) -> Self {
self.session_id = Some(id.to_string());
self
}

/// Sets the root session id sent as the `dd-root-session-id` header (only with a valid session
/// id).
pub fn set_root_session_id(mut self, id: &str) -> Self {
self.root_session_id = Some(id.to_string());
self
}

/// Sets the parent session id sent as the `dd-parent-session-id` header (only with a valid
/// session id).
pub fn set_parent_session_id(mut self, id: &str) -> Self {
self.parent_session_id = Some(id.to_string());
self
}

/// Sets the debug enabled flag for the telemetry client.
pub fn set_debug_enabled(mut self, debug: bool) -> Self {
self.config.debug_enabled = debug;
Expand All @@ -117,6 +141,9 @@ impl TelemetryClientBuilder {
if let Some(id) = self.runtime_id {
builder.runtime_id = Some(id);
}
builder.session_id = self.session_id;
builder.root_session_id = self.root_session_id;
builder.parent_session_id = self.parent_session_id;

let (worker_handle, worker) = builder.build_worker(runtime);

Expand Down Expand Up @@ -854,7 +881,10 @@ mod tests {
let telemetry_srv = server
.mock_async(|when, then| {
when.method(POST)
.body_includes(r#""application":{"service_name":"test_service","service_version":"test_version","env":"test_env","language_name":"test_language","language_version":"test_language_version","tracer_version":"test_tracer_version"}"#);
.body_includes(r#""application":{"service_name":"test_service","service_version":"test_version","env":"test_env","language_name":"test_language","language_version":"test_language_version","tracer_version":"test_tracer_version"}"#)
.header("dd-session-id", "sess-e2e")
.header("dd-root-session-id", "root-e2e")
.header("dd-parent-session-id", "parent-e2e");
then.status(200).body("");
})
.await;
Expand All @@ -869,6 +899,9 @@ mod tests {
.set_url(&server.url("/"))
.set_heartbeat(100)
.set_runtime_id("foo")
.set_session_id("sess-e2e")
.set_root_session_id("root-e2e")
.set_parent_session_id("parent-e2e")
.build(Handle::current());
tokio::spawn(async move { worker.run().await });

Expand Down
10 changes: 10 additions & 0 deletions libdd-data-pipeline/src/trace_exporter/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,15 @@ impl TraceExporterBuilder {
if let Some(id) = telemetry_config.runtime_id {
builder = builder.set_runtime_id(&id);
}
if let Some(ref id) = telemetry_config.session_id {
builder = builder.set_session_id(id);
}
if let Some(ref id) = telemetry_config.root_session_id {
builder = builder.set_root_session_id(id);
}
if let Some(ref id) = telemetry_config.parent_session_id {
builder = builder.set_parent_session_id(id);
}
builder.build(runtime.handle().clone())
});

Expand Down Expand Up @@ -437,6 +446,7 @@ mod tests {
heartbeat: 1000,
runtime_id: None,
debug_enabled: false,
..Default::default()
});
let exporter = builder.build().unwrap();

Expand Down
6 changes: 6 additions & 0 deletions libdd-data-pipeline/src/trace_exporter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,12 @@ pub struct TelemetryConfig {
pub heartbeat: u64,
pub runtime_id: Option<String>,
pub debug_enabled: bool,
/// Sent as the `dd-session-id` telemetry header when set.
pub session_id: Option<String>,
/// Sent as `dd-root-session-id` when set (only with a valid session id).
pub root_session_id: Option<String>,
/// Sent as `dd-parent-session-id` when set (only with a valid session id).
pub parent_session_id: Option<String>,
}

#[allow(missing_docs)]
Expand Down
Loading
Loading