@@ -10,7 +10,8 @@ use libdd_common_ffi::{
1010} ;
1111
1212use libdd_data_pipeline:: trace_exporter:: {
13- TelemetryConfig , TraceExporter , TraceExporterInputFormat , TraceExporterOutputFormat ,
13+ TelemetryConfig , TelemetryInstrumentationSessions , TraceExporter , TraceExporterInputFormat ,
14+ TraceExporterOutputFormat ,
1415} ;
1516use std:: { ptr:: NonNull , time:: Duration } ;
1617use tracing:: { debug, error} ;
@@ -43,6 +44,13 @@ pub struct TelemetryClientConfig<'a> {
4344 /// When enabled, sets the DD-Telemetry-Debug-Enabled header to true.
4445 /// Defaults to false.
4546 pub debug_enabled : bool ,
47+
48+ /// HTTP header `dd-session-id` (empty = omitted).
49+ pub session_id : CharSlice < ' a > ,
50+ /// HTTP header `dd-root-session-id` (empty = omitted).
51+ pub root_session_id : CharSlice < ' a > ,
52+ /// HTTP header `dd-parent-session-id` (empty = omitted).
53+ pub parent_session_id : CharSlice < ' a > ,
4654}
4755
4856/// The TraceExporterConfig object will hold the configuration properties for the TraceExporter.
@@ -64,6 +72,7 @@ pub struct TraceExporterConfig {
6472 compute_stats : bool ,
6573 client_computed_stats : bool ,
6674 telemetry_cfg : Option < TelemetryConfig > ,
75+ telemetry_instrumentation_sessions : TelemetryInstrumentationSessions ,
6776 health_metrics_enabled : bool ,
6877 process_tags : Option < String > ,
6978 test_session_token : Option < String > ,
@@ -302,8 +311,23 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_enable_telemetry(
302311 } ,
303312 debug_enabled: telemetry_cfg. debug_enabled,
304313 } ;
305- debug!( telemetry_cfg = ?cfg, "Configuring telemetry" ) ;
314+ let sessions = TelemetryInstrumentationSessions {
315+ session_id: match sanitize_string( telemetry_cfg. session_id) {
316+ Ok ( s) => Some ( s) ,
317+ Err ( e) => return Some ( e) ,
318+ } ,
319+ root_session_id: match sanitize_string( telemetry_cfg. root_session_id) {
320+ Ok ( s) => Some ( s) ,
321+ Err ( e) => return Some ( e) ,
322+ } ,
323+ parent_session_id: match sanitize_string( telemetry_cfg. parent_session_id) {
324+ Ok ( s) => Some ( s) ,
325+ Err ( e) => return Some ( e) ,
326+ } ,
327+ } ;
328+ debug!( telemetry_cfg = ?cfg, telemetry_sessions = ?sessions, "Configuring telemetry" ) ;
306329 config. telemetry_cfg = Some ( cfg) ;
330+ config. telemetry_instrumentation_sessions = sessions;
307331 }
308332 None
309333 } else {
@@ -488,6 +512,9 @@ pub unsafe extern "C" fn ddog_trace_exporter_new(
488512 if let Some ( cfg) = & config. telemetry_cfg {
489513 builder. enable_telemetry( cfg. clone( ) ) ;
490514 }
515+ builder. set_telemetry_instrumentation_sessions(
516+ config. telemetry_instrumentation_sessions. clone( ) ,
517+ ) ;
491518
492519 if let Some ( token) = & config. test_session_token {
493520 builder. set_test_session_token( token) ;
@@ -831,6 +858,9 @@ mod tests {
831858 interval : 1000 ,
832859 runtime_id : CharSlice :: from ( "id" ) ,
833860 debug_enabled : false ,
861+ session_id : CharSlice :: empty ( ) ,
862+ root_session_id : CharSlice :: empty ( ) ,
863+ parent_session_id : CharSlice :: empty ( ) ,
834864 } ) ,
835865 ) ;
836866 assert_eq ! ( error. as_ref( ) . unwrap( ) . code, ErrorCode :: InvalidArgument ) ;
@@ -848,6 +878,9 @@ mod tests {
848878 interval : 1000 ,
849879 runtime_id : CharSlice :: from ( "foo" ) ,
850880 debug_enabled : true ,
881+ session_id : CharSlice :: empty ( ) ,
882+ root_session_id : CharSlice :: empty ( ) ,
883+ parent_session_id : CharSlice :: empty ( ) ,
851884 } ) ,
852885 ) ;
853886 assert ! ( error. is_none( ) ) ;
@@ -863,6 +896,40 @@ mod tests {
863896 "foo"
864897 ) ;
865898 assert ! ( cfg. telemetry_cfg. as_ref( ) . unwrap( ) . debug_enabled) ;
899+ assert_eq ! (
900+ cfg. telemetry_instrumentation_sessions. session_id. as_deref( ) ,
901+ Some ( "" )
902+ ) ;
903+ assert_eq ! (
904+ cfg. telemetry_instrumentation_sessions
905+ . root_session_id
906+ . as_deref( ) ,
907+ Some ( "" )
908+ ) ;
909+ assert_eq ! (
910+ cfg. telemetry_instrumentation_sessions
911+ . parent_session_id
912+ . as_deref( ) ,
913+ Some ( "" )
914+ ) ;
915+
916+ let mut cfg = TraceExporterConfig :: default ( ) ;
917+ let error = ddog_trace_exporter_config_enable_telemetry (
918+ Some ( & mut cfg) ,
919+ Some ( & TelemetryClientConfig {
920+ interval : 500 ,
921+ runtime_id : CharSlice :: from ( "rid" ) ,
922+ debug_enabled : false ,
923+ session_id : CharSlice :: from ( "sess-z" ) ,
924+ root_session_id : CharSlice :: from ( "root-z" ) ,
925+ parent_session_id : CharSlice :: from ( "par-z" ) ,
926+ } ) ,
927+ ) ;
928+ assert ! ( error. is_none( ) ) ;
929+ let s = & cfg. telemetry_instrumentation_sessions ;
930+ assert_eq ! ( s. session_id. as_deref( ) , Some ( "sess-z" ) ) ;
931+ assert_eq ! ( s. root_session_id. as_deref( ) , Some ( "root-z" ) ) ;
932+ assert_eq ! ( s. parent_session_id. as_deref( ) , Some ( "par-z" ) ) ;
866933 }
867934 }
868935
0 commit comments