Skip to content

Commit bacfe33

Browse files
committed
debug
1 parent 5d505d2 commit bacfe33

File tree

3 files changed

+82
-10
lines changed

3 files changed

+82
-10
lines changed

datadog-crashtracker/src/crash_info/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,6 @@ impl CrashInfo {
151151
.host()
152152
.map_or(false, |host| host.contains("event-platform-intake"))
153153
{
154-
panic!("Secondary endpoint is not an Error Tracking intake endpoint");
155-
156154
self.upload_to_error_tracking(&Some(secondary.clone()))
157155
.await
158156
} else {

datadog-crashtracker/src/receiver/entry_points.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
use super::receive_report::receive_report_from_stream;
55
use crate::{crash_info::CrashInfo, CrashtrackerConfiguration, StacktraceCollection};
66
use anyhow::Context;
7-
use ddcommon::Endpoint;
87
use std::time::Duration;
98
use tokio::{
109
io::{AsyncBufReadExt, BufReader},
@@ -113,12 +112,7 @@ pub(crate) async fn receiver_entry_point(
113112
}
114113
}
115114
crash_info
116-
.async_upload_to_endpoints(
117-
config.endpoint(),
118-
&Some(Endpoint::from_slice(
119-
"https://event-platform-intake.datad0g.com/api/v2/errorsintake",
120-
)),
121-
)
115+
.async_upload_to_endpoints(config.endpoint(), config.secondary_endpoint())
122116
.await?;
123117
}
124118
Ok(())

datadog-crashtracker/src/shared/configuration.rs

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub enum StacktraceCollection {
2424
EnabledWithSymbolsInReceiver,
2525
}
2626

27-
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
27+
#[derive(Debug, Clone, PartialEq, Serialize)]
2828
pub struct CrashtrackerConfiguration {
2929
// Paths to any additional files to track, if any
3030
additional_files: Vec<String>,
@@ -223,6 +223,50 @@ impl CrashtrackerConfiguration {
223223
}
224224
}
225225

226+
impl<'de> serde::Deserialize<'de> for CrashtrackerConfiguration {
227+
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
228+
where
229+
D: serde::Deserializer<'de>,
230+
{
231+
#[derive(Deserialize)]
232+
struct CrashtrackerConfigurationHelper {
233+
additional_files: Vec<String>,
234+
create_alt_stack: bool,
235+
demangle_names: bool,
236+
endpoint: Option<Endpoint>,
237+
resolve_frames: StacktraceCollection,
238+
secondary_endpoint: Option<Endpoint>,
239+
signals: Vec<i32>,
240+
timeout: Duration,
241+
unix_socket_path: Option<String>,
242+
use_alt_stack: bool,
243+
}
244+
245+
let helper = CrashtrackerConfigurationHelper::deserialize(deserializer)?;
246+
247+
// Apply secondary endpoint derivation logic during deserialization
248+
let secondary_endpoint = helper.secondary_endpoint.or_else(|| {
249+
helper
250+
.endpoint
251+
.as_ref()
252+
.and_then(derive_default_secondary_endpoint)
253+
});
254+
255+
Ok(CrashtrackerConfiguration {
256+
additional_files: helper.additional_files,
257+
create_alt_stack: helper.create_alt_stack,
258+
demangle_names: helper.demangle_names,
259+
endpoint: helper.endpoint,
260+
resolve_frames: helper.resolve_frames,
261+
secondary_endpoint,
262+
signals: helper.signals,
263+
timeout: helper.timeout,
264+
unix_socket_path: helper.unix_socket_path,
265+
use_alt_stack: helper.use_alt_stack,
266+
})
267+
}
268+
}
269+
226270
/// Derives a default secondary endpoint based on the primary endpoint.
227271
/// This mirrors the primary endpoint logic but uses Error Tracking endpoints.
228272
fn derive_default_secondary_endpoint(primary: &Endpoint) -> Option<Endpoint> {
@@ -511,4 +555,40 @@ mod tests {
511555

512556
Ok(())
513557
}
558+
559+
#[test]
560+
fn test_deserialize_with_secondary_endpoint_derivation() -> anyhow::Result<()> {
561+
use ddcommon::Endpoint;
562+
use std::time::Duration;
563+
564+
// Create a config with primary endpoint, serialize it without secondary
565+
let mut original_config = super::CrashtrackerConfiguration::new(
566+
vec![],
567+
false,
568+
false,
569+
Some(Endpoint::from_slice("https://intake.profile.datadoghq.com")),
570+
super::StacktraceCollection::Disabled,
571+
vec![],
572+
Some(Duration::from_secs(1)),
573+
None,
574+
false,
575+
)?;
576+
577+
// Clear the secondary endpoint to simulate receiving from collector
578+
original_config.secondary_endpoint = None;
579+
580+
// Serialize and then deserialize
581+
let serialized = serde_json::to_string(&original_config)?;
582+
let deserialized: super::CrashtrackerConfiguration = serde_json::from_str(&serialized)?;
583+
584+
// Verify that deserialization applied secondary endpoint derivation
585+
assert!(deserialized.secondary_endpoint().is_some());
586+
let secondary = deserialized.secondary_endpoint().as_ref().unwrap();
587+
assert_eq!(
588+
secondary.url.to_string(),
589+
"https://event-platform-intake.datad0g.com/api/v2/errorsintake"
590+
);
591+
592+
Ok(())
593+
}
514594
}

0 commit comments

Comments
 (0)