Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
181 changes: 181 additions & 0 deletions libdd-telemetry-ffi/src/builder/expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,70 @@ mod macros {
};
ffi::MaybeError::None
}
#[no_mangle]
Comment thread
mabdinur marked this conversation as resolved.
pub unsafe extern "C" fn ddog_telemetry_builder_with_str_session_id(
telemetry_builder: &mut TelemetryWorkerBuilder,
param: ffi::CharSlice,
) -> ffi::MaybeError {
telemetry_builder.config.session_id = match (|s: ffi::CharSlice| -> Result<_, String> {
Ok(Some(s.to_utf8_lossy().into_owned()))
})(param)
{
Ok(o) => o,
Err(e) => {
return ffi::MaybeError::Some(libdd_common_ffi::Error::from(
({
let res = std::fmt::format(format_args!("{e:?}"));
res
}),
));
}
};
ffi::MaybeError::None
}
#[no_mangle]
pub unsafe extern "C" fn ddog_telemetry_builder_with_str_root_session_id(
telemetry_builder: &mut TelemetryWorkerBuilder,
param: ffi::CharSlice,
) -> ffi::MaybeError {
telemetry_builder.config.root_session_id = match (|s: ffi::CharSlice| -> Result<_, String> {
Ok(Some(s.to_utf8_lossy().into_owned()))
})(param)
{
Ok(o) => o,
Err(e) => {
return ffi::MaybeError::Some(libdd_common_ffi::Error::from(
({
let res = std::fmt::format(format_args!("{e:?}"));
res
}),
));
}
};
ffi::MaybeError::None
}
#[no_mangle]
pub unsafe extern "C" fn ddog_telemetry_builder_with_str_parent_session_id(
Comment thread
mabdinur marked this conversation as resolved.
telemetry_builder: &mut TelemetryWorkerBuilder,
param: ffi::CharSlice,
) -> ffi::MaybeError {
telemetry_builder.config.parent_session_id =
match (|s: ffi::CharSlice| -> Result<_, String> {
Ok(Some(s.to_utf8_lossy().into_owned()))
})(param)
{
Ok(o) => o,
Err(e) => {
return ffi::MaybeError::Some(libdd_common_ffi::Error::from(
({
let res = std::fmt::format(format_args!("{e:?}"));
res
}),
));
}
};
ffi::MaybeError::None
}
#[repr(C)]
#[allow(dead_code)]
pub enum TelemetryWorkerBuilderStrProperty {
Expand All @@ -259,6 +323,9 @@ mod macros {
HostKernelRelease,
HostKernelVersion,
RuntimeId,
SessionId,
ParentSessionId,
Comment thread
mabdinur marked this conversation as resolved.
RootSessionId,
}
#[no_mangle]
/**
Expand Down Expand Up @@ -288,6 +355,12 @@ mod macros {

* runtime_id

* session_id

* parent_session_id
Comment thread
mabdinur marked this conversation as resolved.
Comment thread
mabdinur marked this conversation as resolved.

* root_session_id

*/
pub unsafe extern "C" fn ddog_telemetry_builder_with_property_str(
telemetry_builder: &mut TelemetryWorkerBuilder,
Expand Down Expand Up @@ -481,6 +554,57 @@ mod macros {
}
};
}
SessionId => {
telemetry_builder.config.session_id =
match (|s: ffi::CharSlice| -> Result<_, String> {
Ok(Some(s.to_utf8_lossy().into_owned()))
})(param)
{
Ok(o) => o,
Err(e) => {
return ffi::MaybeError::Some(libdd_common_ffi::Error::from(
({
let res = std::fmt::format(format_args!("{e:?}"));
res
}),
));
}
};
}
ParentSessionId => {
telemetry_builder.config.parent_session_id =
match (|s: ffi::CharSlice| -> Result<_, String> {
Ok(Some(s.to_utf8_lossy().into_owned()))
})(param)
{
Ok(o) => o,
Err(e) => {
return ffi::MaybeError::Some(libdd_common_ffi::Error::from(
({
let res = std::fmt::format(format_args!("{e:?}"));
res
}),
));
}
};
}
RootSessionId => {
telemetry_builder.config.root_session_id =
match (|s: ffi::CharSlice| -> Result<_, String> {
Ok(Some(s.to_utf8_lossy().into_owned()))
})(param)
{
Ok(o) => o,
Err(e) => {
return ffi::MaybeError::Some(libdd_common_ffi::Error::from(
({
let res = std::fmt::format(format_args!("{e:?}"));
res
}),
));
}
};
}
}
ffi::MaybeError::None
}
Expand Down Expand Up @@ -512,6 +636,12 @@ mod macros {

* runtime_id

* session_id

* parent_session_id

* root_session_id

*/
pub unsafe extern "C" fn ddog_telemetry_builder_with_str_named_property(
telemetry_builder: &mut TelemetryWorkerBuilder,
Expand Down Expand Up @@ -715,6 +845,57 @@ mod macros {
}
};
}
"session_id" => {
telemetry_builder.config.session_id =
match (|s: ffi::CharSlice| -> Result<_, String> {
Ok(Some(s.to_utf8_lossy().into_owned()))
})(param)
{
Ok(o) => o,
Err(e) => {
return ffi::MaybeError::Some(libdd_common_ffi::Error::from(
({
let res = std::fmt::format(format_args!("{e:?}"));
res
}),
));
}
};
}
"parent_session_id" => {
telemetry_builder.config.parent_session_id =
match (|s: ffi::CharSlice| -> Result<_, String> {
Ok(Some(s.to_utf8_lossy().into_owned()))
})(param)
{
Ok(o) => o,
Err(e) => {
return ffi::MaybeError::Some(libdd_common_ffi::Error::from(
({
let res = std::fmt::format(format_args!("{e:?}"));
res
}),
));
}
};
}
"root_session_id" => {
telemetry_builder.config.root_session_id =
match (|s: ffi::CharSlice| -> Result<_, String> {
Ok(Some(s.to_utf8_lossy().into_owned()))
})(param)
{
Ok(o) => o,
Err(e) => {
return ffi::MaybeError::Some(libdd_common_ffi::Error::from(
({
let res = std::fmt::format(format_args!("{e:?}"));
res
}),
));
}
};
}
_ => return ffi::MaybeError::None,
}
ffi::MaybeError::None
Expand Down
5 changes: 4 additions & 1 deletion libdd-telemetry-ffi/src/builder/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ crate::c_setters!(
host.kernel_release,
host.kernel_version,

runtime_id
runtime_id,
session_id,
parent_session_id,
Comment thread
mabdinur marked this conversation as resolved.
root_session_id
}
);

Expand Down
31 changes: 31 additions & 0 deletions libdd-telemetry-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,37 @@ mod tests {
);
assert_eq!(builder.runtime_id.as_deref(), Some("abcd"));

assert_eq!(
ddog_telemetry_builder_with_property_str(
&mut builder,
TelemetryWorkerBuilderStrProperty::SessionId,
ffi::CharSlice::from("sess-1")
),
MaybeError::None,
);
assert_eq!(builder.config.session_id.as_deref(), Some("sess-1"));
assert_eq!(
ddog_telemetry_builder_with_property_str(
&mut builder,
TelemetryWorkerBuilderStrProperty::RootSessionId,
ffi::CharSlice::from("root-9")
),
MaybeError::None,
);
assert_eq!(builder.config.root_session_id.as_deref(), Some("root-9"));
assert_eq!(
ddog_telemetry_builder_with_property_str(
&mut builder,
TelemetryWorkerBuilderStrProperty::ParentSessionId,
ffi::CharSlice::from("parent-2")
),
MaybeError::None,
);
assert_eq!(
builder.config.parent_session_id.as_deref(),
Some("parent-2")
);

assert_eq!(
ddog_telemetry_builder_with_property_str(
&mut builder,
Expand Down
13 changes: 13 additions & 0 deletions libdd-telemetry/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ pub struct Config {
pub restartable: bool,

pub debug_enabled: bool,

#[serde(default)]
pub session_id: Option<String>,
#[serde(default)]
pub parent_session_id: Option<String>,
#[serde(default)]
pub root_session_id: Option<String>,
}

fn endpoint_with_telemetry_path(
Expand Down Expand Up @@ -168,6 +175,9 @@ impl Default for Config {
direct_submission_enabled: false,
restartable: false,
debug_enabled: false,
session_id: None,
parent_session_id: None,
root_session_id: None,
}
}
}
Expand Down Expand Up @@ -252,6 +262,9 @@ impl Config {
direct_submission_enabled: settings.direct_submission_enabled,
restartable: false,
debug_enabled: false,
session_id: None,
parent_session_id: None,
root_session_id: None,
};
if let Ok(url) = parse_uri(&trace_agent_url) {
let _res = this.set_endpoint(Endpoint {
Expand Down
32 changes: 31 additions & 1 deletion libdd-telemetry/src/worker/http_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,38 @@ pub mod header {
pub const LIBRARY_LANGUAGE: HeaderName = HeaderName::from_static("dd-client-library-language");
pub const LIBRARY_VERSION: HeaderName = HeaderName::from_static("dd-client-library-version");

/// Header key for whether to enable debug mode of telemetry.
pub const DEBUG_ENABLED: HeaderName = HeaderName::from_static("dd-telemetry-debug-enabled");

pub const DD_SESSION_ID: HeaderName = HeaderName::from_static("dd-session-id");
pub const DD_ROOT_SESSION_ID: HeaderName = HeaderName::from_static("dd-root-session-id");
pub const DD_PARENT_SESSION_ID: HeaderName = HeaderName::from_static("dd-parent-session-id");
Comment thread
mabdinur marked this conversation as resolved.
}

/// `session_id`, then `parent_session_id`, then `root_session_id` (must match call sites in
/// `build_request`).
pub(crate) fn add_instrumentation_session_headers(
Comment thread
mabdinur marked this conversation as resolved.
mut builder: HttpRequestBuilder,
session_id: Option<&str>,
parent_session_id: Option<&str>,
root_session_id: Option<&str>,
) -> HttpRequestBuilder {
let Some(s) = session_id.filter(|id| !id.is_empty()) else {
return builder;
};
builder = builder.header(header::DD_SESSION_ID, s);
if let Some(r) = root_session_id
.filter(|r| !r.is_empty())
.filter(|r| *r != s)
{
builder = builder.header(header::DD_ROOT_SESSION_ID, r);
}
if let Some(p) = parent_session_id
.filter(|p| !p.is_empty())
.filter(|p| *p != s)
{
builder = builder.header(header::DD_PARENT_SESSION_ID, p);
}
builder
}

pub type ResponseFuture =
Expand Down
Loading
Loading