Skip to content

Commit 5ad1ea1

Browse files
[mq] working branch - merge f99d4da on top of main at 3f279eb
{"baseBranch":"main","baseCommit":"3f279ebe385d9608a960d01d17102875f63c9cf0","createdAt":"2026-02-10T13:36:52.662491Z","headSha":"f99d4dad1e1dafad5b4b8e912c2cd9a8a7292942","id":"0841d0df-64df-4e41-a29a-a16865f7c695","nextMergeabilityCheckAt":"2026-02-10T14:13:04.504128Z","priority":"200","pullRequestNumber":"1547","queuedAt":"2026-02-10T14:12:37.450346Z","status":"STATUS_QUEUED"}
2 parents ad63597 + f99d4da commit 5ad1ea1

File tree

1 file changed

+69
-0
lines changed
  • datadog-tracer-flare/src

1 file changed

+69
-0
lines changed

datadog-tracer-flare/src/zip.rs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,75 @@ impl TracerFlareManager {
290290
self.send(zip, agent_task).await
291291
}
292292

293+
/// Creates a zip archive containing the specified files and directories, ~~obfuscates sensitive
294+
/// data~~, and sends the flare to the agent. This is a synchronous version of the
295+
/// `zip_and_send` function that can be called from synchronous code.
296+
///
297+
/// # Arguments
298+
///
299+
/// * `files` - A vector of strings representing the paths of files and directories to include
300+
/// in the zip archive.
301+
/// * `send_action` - FlareAction to perform by the tracer flare. Must be a Send action or the
302+
/// function will return an Error.
303+
///
304+
/// # Returns
305+
///
306+
/// * `Ok(())` - If the zip archive was created, ~~obfuscated~~, and sent successfully.
307+
/// * `Err(FlareError)` - An error if any step of the process fails.
308+
///
309+
/// # Errors
310+
///
311+
/// This function will return an error if:
312+
/// - Any problem happened while zipping the file.
313+
/// - The obfuscation process fails.
314+
/// - The zip file cannot be sent to the agent.
315+
/// - No agent task was received by the tracer_flare.
316+
///
317+
/// # Examples
318+
///
319+
/// ```rust no_run
320+
/// use datadog_tracer_flare::{TracerFlareManager, FlareAction};
321+
/// use datadog_remote_config::config::agent_task::{AgentTaskFile, AgentTask};
322+
///
323+
/// let tracer_flare = TracerFlareManager::default();
324+
///
325+
/// // ... listen to remote config and receive an agent task ...
326+
///
327+
/// // Simulate receiving a Send action from remote config
328+
/// let task = AgentTaskFile {
329+
/// args: AgentTask {
330+
/// case_id: "123".to_string(),
331+
/// hostname: "test-host".to_string(),
332+
/// user_handle: "[email protected]".to_string(),
333+
/// },
334+
/// task_type: "tracer_flare".to_string(),
335+
/// uuid: "test-uuid".to_string(),
336+
/// };
337+
/// let send_action = FlareAction::Send(task);
338+
///
339+
/// let files = vec![
340+
/// "/path/to/logs".to_string(),
341+
/// "/path/to/config.txt".to_string(),
342+
/// ];
343+
///
344+
/// match tracer_flare.zip_and_send_sync(files, send_action) {
345+
/// Ok(_) => println!("Flare sent successfully"),
346+
/// Err(e) => eprintln!("Failed to send flare: {}", e),
347+
/// }
348+
/// ```
349+
pub fn zip_and_send_sync(
350+
&self,
351+
files: Vec<String>,
352+
send_action: FlareAction,
353+
) -> Result<(), FlareError> {
354+
let runtime = tokio::runtime::Builder::new_current_thread()
355+
.enable_all()
356+
.build()
357+
.map_err(|e| FlareError::SendError(format!("Failed to create runtime: {e}")))?;
358+
359+
runtime.block_on(self.zip_and_send(files, send_action))
360+
}
361+
293362
/// Sends a zip file to the agent via a POST request.
294363
///
295364
/// This function reads the entire zip file into memory, constructs an HTTP request

0 commit comments

Comments
 (0)