Skip to content

Commit 7a55094

Browse files
committed
Pass in API key
1 parent 15df816 commit 7a55094

File tree

2 files changed

+41
-10
lines changed

2 files changed

+41
-10
lines changed

datadog-crashtracker/src/crash_info/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,21 @@ impl CrashInfo {
195195
let payload_json = serde_json::to_string(&error_tracking_payload)?;
196196

197197
// Log endpoint and payload for debugging/testing
198+
let debug_msg = format!(
199+
"DEBUG: upload_to_error_tracking called with endpoint: {}, api_key: {}\n",
200+
endpoint.url,
201+
if endpoint.api_key.is_some() {
202+
"present"
203+
} else {
204+
"missing"
205+
}
206+
);
207+
let _ = std::fs::OpenOptions::new()
208+
.create(true)
209+
.append(true)
210+
.open("/tmp/crashtracker_debug.log")
211+
.and_then(|mut f| std::io::Write::write_all(&mut f, debug_msg.as_bytes()));
212+
198213
if let Err(e) = self.log_error_tracking_request(&endpoint.url.to_string(), &payload_json) {
199214
eprintln!("Failed to log error tracking request: {}", e);
200215
}

datadog-crashtracker/src/shared/configuration.rs

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -142,16 +142,10 @@ impl CrashtrackerConfiguration {
142142

143143
// If no secondary endpoint is provided but we have a primary endpoint,
144144
// derive a default secondary endpoint
145-
// let secondary_endpoint = secondary_endpoint.or_else(|| {
146-
// endpoint
147-
// .as_ref()
148-
// .and_then(|primary| derive_default_secondary_endpoint(primary))
149-
// });
150-
151145
let secondary_endpoint = secondary_endpoint.or_else(|| {
152-
let derived = derive_default_secondary_endpoint(endpoint.as_ref().unwrap());
153-
panic!("{}", format!("new_with_secondary: {:?}", derived));
154-
endpoint.as_ref().and_then(|primary| derived)
146+
endpoint
147+
.as_ref()
148+
.and_then(|primary| derive_default_secondary_endpoint(primary))
155149
});
156150

157151
// Note: don't check the receiver socket upfront, since a configuration can be interned
@@ -314,9 +308,31 @@ fn derive_default_secondary_endpoint(primary: &Endpoint) -> Option<Endpoint> {
314308
return None;
315309
};
316310

311+
// For Error Tracking endpoints, we need an API key
312+
let api_key = primary.api_key.clone().or_else(|| {
313+
std::env::var("DD_API_KEY")
314+
.ok()
315+
.map(std::borrow::Cow::Owned)
316+
});
317+
318+
let debug_msg = format!(
319+
"DEBUG: Creating secondary endpoint: {} with api_key: {}\n",
320+
secondary_url,
321+
if api_key.is_some() {
322+
"present"
323+
} else {
324+
"missing"
325+
}
326+
);
327+
let _ = std::fs::OpenOptions::new()
328+
.create(true)
329+
.append(true)
330+
.open("/tmp/crashtracker_debug.log")
331+
.and_then(|mut f| std::io::Write::write_all(&mut f, debug_msg.as_bytes()));
332+
317333
Some(Endpoint {
318334
url: secondary_url.parse().ok()?,
319-
api_key: primary.api_key.clone(),
335+
api_key,
320336
timeout_ms: primary.timeout_ms,
321337
test_token: primary.test_token.clone(),
322338
})

0 commit comments

Comments
 (0)