Skip to content

Commit a6f3bd9

Browse files
committed
address semvar issues
1 parent 9ac72b7 commit a6f3bd9

File tree

8 files changed

+131
-127
lines changed

8 files changed

+131
-127
lines changed

libdd-data-pipeline-ffi/src/trace_exporter.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ use libdd_common_ffi::{
1010
};
1111

1212
use libdd_data_pipeline::trace_exporter::{
13-
TelemetryConfig, TraceExporter, TraceExporterInputFormat, TraceExporterOutputFormat,
13+
TelemetryConfig, TelemetryInstrumentationSessions, TraceExporter, TraceExporterInputFormat,
14+
TraceExporterOutputFormat,
1415
};
1516
use std::{ptr::NonNull, time::Duration};
1617
use tracing::{debug, error};
@@ -71,6 +72,7 @@ pub struct TraceExporterConfig {
7172
compute_stats: bool,
7273
client_computed_stats: bool,
7374
telemetry_cfg: Option<TelemetryConfig>,
75+
telemetry_instrumentation_sessions: TelemetryInstrumentationSessions,
7476
health_metrics_enabled: bool,
7577
process_tags: Option<String>,
7678
test_session_token: Option<String>,
@@ -308,6 +310,8 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_enable_telemetry(
308310
Err(e) => return Some(e),
309311
},
310312
debug_enabled: telemetry_cfg.debug_enabled,
313+
};
314+
let sessions = TelemetryInstrumentationSessions {
311315
session_id: match sanitize_string(telemetry_cfg.session_id) {
312316
Ok(s) => Some(s),
313317
Err(e) => return Some(e),
@@ -321,8 +325,9 @@ pub unsafe extern "C" fn ddog_trace_exporter_config_enable_telemetry(
321325
Err(e) => return Some(e),
322326
},
323327
};
324-
debug!(telemetry_cfg = ?cfg, "Configuring telemetry");
328+
debug!(telemetry_cfg = ?cfg, telemetry_sessions = ?sessions, "Configuring telemetry");
325329
config.telemetry_cfg = Some(cfg);
330+
config.telemetry_instrumentation_sessions = sessions;
326331
}
327332
None
328333
} else {
@@ -507,6 +512,9 @@ pub unsafe extern "C" fn ddog_trace_exporter_new(
507512
if let Some(cfg) = &config.telemetry_cfg {
508513
builder.enable_telemetry(cfg.clone());
509514
}
515+
builder.set_telemetry_instrumentation_sessions(
516+
config.telemetry_instrumentation_sessions.clone(),
517+
);
510518

511519
if let Some(token) = &config.test_session_token {
512520
builder.set_test_session_token(token);
@@ -889,21 +897,17 @@ mod tests {
889897
);
890898
assert!(cfg.telemetry_cfg.as_ref().unwrap().debug_enabled);
891899
assert_eq!(
892-
cfg.telemetry_cfg.as_ref().unwrap().session_id.as_deref(),
900+
cfg.telemetry_instrumentation_sessions.session_id.as_deref(),
893901
Some("")
894902
);
895903
assert_eq!(
896-
cfg.telemetry_cfg
897-
.as_ref()
898-
.unwrap()
904+
cfg.telemetry_instrumentation_sessions
899905
.root_session_id
900906
.as_deref(),
901907
Some("")
902908
);
903909
assert_eq!(
904-
cfg.telemetry_cfg
905-
.as_ref()
906-
.unwrap()
910+
cfg.telemetry_instrumentation_sessions
907911
.parent_session_id
908912
.as_deref(),
909913
Some("")
@@ -922,10 +926,10 @@ mod tests {
922926
}),
923927
);
924928
assert!(error.is_none());
925-
let t = cfg.telemetry_cfg.as_ref().unwrap();
926-
assert_eq!(t.session_id.as_deref(), Some("sess-z"));
927-
assert_eq!(t.root_session_id.as_deref(), Some("root-z"));
928-
assert_eq!(t.parent_session_id.as_deref(), Some("par-z"));
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"));
929933
}
930934
}
931935

@@ -1206,9 +1210,6 @@ mod tests {
12061210
heartbeat: 10000,
12071211
runtime_id: Some("foo".to_string()),
12081212
debug_enabled: true,
1209-
session_id: None,
1210-
root_session_id: None,
1211-
parent_session_id: None,
12121213
}),
12131214
..Default::default()
12141215
};

libdd-data-pipeline/src/telemetry/mod.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ pub struct TelemetryClientBuilder {
3232
tracer_version: Option<String>,
3333
config: libdd_telemetry::config::Config,
3434
runtime_id: Option<String>,
35-
session_id: Option<String>,
36-
root_session_id: Option<String>,
37-
parent_session_id: Option<String>,
3835
}
3936

4037
impl TelemetryClientBuilder {
@@ -99,21 +96,21 @@ impl TelemetryClientBuilder {
9996
/// Sets the instrumentation session id sent as the `dd-session-id` header on telemetry
10097
/// requests.
10198
pub fn set_session_id(mut self, id: &str) -> Self {
102-
self.session_id = Some(id.to_string());
99+
self.config.session_id = Some(id.to_string());
103100
self
104101
}
105102

106103
/// Sets the root session id sent as the `dd-root-session-id` header (only with a valid session
107104
/// id).
108105
pub fn set_root_session_id(mut self, id: &str) -> Self {
109-
self.root_session_id = Some(id.to_string());
106+
self.config.root_session_id = Some(id.to_string());
110107
self
111108
}
112109

113110
/// Sets the parent session id sent as the `dd-parent-session-id` header (only with a valid
114111
/// session id).
115112
pub fn set_parent_session_id(mut self, id: &str) -> Self {
116-
self.parent_session_id = Some(id.to_string());
113+
self.config.parent_session_id = Some(id.to_string());
117114
self
118115
}
119116

@@ -141,9 +138,6 @@ impl TelemetryClientBuilder {
141138
if let Some(id) = self.runtime_id {
142139
builder.runtime_id = Some(id);
143140
}
144-
builder.session_id = self.session_id;
145-
builder.root_session_id = self.root_session_id;
146-
builder.parent_session_id = self.parent_session_id;
147141

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

libdd-data-pipeline/src/trace_exporter/builder.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ use crate::telemetry::TelemetryClientBuilder;
99
use crate::trace_exporter::agent_response::AgentResponsePayloadVersion;
1010
use crate::trace_exporter::error::BuilderErrorKind;
1111
use crate::trace_exporter::{
12-
add_path, StatsComputationStatus, TelemetryConfig, TraceExporter, TraceExporterError,
13-
TraceExporterInputFormat, TraceExporterOutputFormat, TraceExporterWorkers, TracerMetadata,
14-
INFO_ENDPOINT,
12+
add_path, StatsComputationStatus, TelemetryConfig, TelemetryInstrumentationSessions,
13+
TraceExporter, TraceExporterError, TraceExporterInputFormat, TraceExporterOutputFormat,
14+
TraceExporterWorkers, TracerMetadata, INFO_ENDPOINT,
1515
};
1616
use arc_swap::ArcSwap;
1717
use libdd_common::http_common::new_default_client;
@@ -49,6 +49,7 @@ pub struct TraceExporterBuilder {
4949
compute_stats_by_span_kind: bool,
5050
peer_tags: Vec<String>,
5151
telemetry: Option<TelemetryConfig>,
52+
telemetry_instrumentation_sessions: TelemetryInstrumentationSessions,
5253
health_metrics_enabled: bool,
5354
test_session_token: Option<String>,
5455
agent_rates_payload_version_enabled: bool,
@@ -209,6 +210,15 @@ impl TraceExporterBuilder {
209210
self
210211
}
211212

213+
/// Sets optional `dd-session-id` / root / parent session headers on telemetry requests.
214+
pub fn set_telemetry_instrumentation_sessions(
215+
&mut self,
216+
sessions: TelemetryInstrumentationSessions,
217+
) -> &mut Self {
218+
self.telemetry_instrumentation_sessions = sessions;
219+
self
220+
}
221+
212222
/// Enables health metrics emission.
213223
pub fn enable_health_metrics(&mut self) -> &mut Self {
214224
self.health_metrics_enabled = true;
@@ -294,6 +304,7 @@ impl TraceExporterBuilder {
294304
stats = StatsComputationStatus::DisabledByAgent { bucket_size };
295305
}
296306

307+
let sessions = self.telemetry_instrumentation_sessions.clone();
297308
let telemetry = self.telemetry.map(|telemetry_config| {
298309
let mut builder = TelemetryClientBuilder::default()
299310
.set_language(&self.language)
@@ -308,13 +319,13 @@ impl TraceExporterBuilder {
308319
if let Some(id) = telemetry_config.runtime_id {
309320
builder = builder.set_runtime_id(&id);
310321
}
311-
if let Some(ref id) = telemetry_config.session_id {
322+
if let Some(ref id) = sessions.session_id {
312323
builder = builder.set_session_id(id);
313324
}
314-
if let Some(ref id) = telemetry_config.root_session_id {
325+
if let Some(ref id) = sessions.root_session_id {
315326
builder = builder.set_root_session_id(id);
316327
}
317-
if let Some(ref id) = telemetry_config.parent_session_id {
328+
if let Some(ref id) = sessions.parent_session_id {
318329
builder = builder.set_parent_session_id(id);
319330
}
320331
builder.build(runtime.handle().clone())
@@ -446,7 +457,6 @@ mod tests {
446457
heartbeat: 1000,
447458
runtime_id: None,
448459
debug_enabled: false,
449-
..Default::default()
450460
});
451461
let exporter = builder.build().unwrap();
452462

libdd-data-pipeline/src/trace_exporter/mod.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ mod trace_serializer;
1010
// Re-export the builder
1111
pub use builder::TraceExporterBuilder;
1212

13+
/// Optional instrumentation session headers for telemetry (`dd-session-id`, etc.).
14+
#[derive(Debug, Default, Clone)]
15+
pub struct TelemetryInstrumentationSessions {
16+
pub session_id: Option<String>,
17+
pub root_session_id: Option<String>,
18+
pub parent_session_id: Option<String>,
19+
}
20+
1321
use self::agent_response::AgentResponse;
1422
use self::metrics::MetricsEmitter;
1523
use self::stats::StatsComputationStatus;
@@ -904,12 +912,6 @@ pub struct TelemetryConfig {
904912
pub heartbeat: u64,
905913
pub runtime_id: Option<String>,
906914
pub debug_enabled: bool,
907-
/// Sent as the `dd-session-id` telemetry header when set.
908-
pub session_id: Option<String>,
909-
/// Sent as `dd-root-session-id` when set (only with a valid session id).
910-
pub root_session_id: Option<String>,
911-
/// Sent as `dd-parent-session-id` when set (only with a valid session id).
912-
pub parent_session_id: Option<String>,
913915
}
914916

915917
#[allow(missing_docs)]

0 commit comments

Comments
 (0)