From fb712b5b1e6be825ad90129a65ead031f1944c97 Mon Sep 17 00:00:00 2001 From: Florian Engelhardt Date: Thu, 25 Apr 2024 08:53:52 +0200 Subject: [PATCH] add `info.json` with start time (#2610) --- Cargo.lock | 1 + profiling/Cargo.toml | 1 + profiling/src/profiling/mod.rs | 2 ++ profiling/src/profiling/uploader.rs | 15 ++++++++++++++- 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index a1d84d0a16..db270764cd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -745,6 +745,7 @@ dependencies = [ "bumpalo", "cc", "cfg-if", + "chrono", "cpu-time", "criterion", "criterion-perf-events", diff --git a/profiling/Cargo.toml b/profiling/Cargo.toml index 815a4b4917..d2b748bd78 100644 --- a/profiling/Cargo.toml +++ b/profiling/Cargo.toml @@ -19,6 +19,7 @@ anyhow = { version = "1.0" } bumpalo = { version = "3.12", features = ["collections"] } cfg-if = { version = "1.0" } cpu-time = { version = "1.0" } +chrono = { version = "0.4" } crossbeam-channel = { version = "0.5", default-features = false, features = ["std"] } datadog-profiling = { git = "https://github.com/DataDog/libdatadog", tag = "v7.0.0" } ddcommon = { git = "https://github.com/DataDog/libdatadog", tag = "v7.0.0" } diff --git a/profiling/src/profiling/mod.rs b/profiling/src/profiling/mod.rs index 27ae59190e..ac77b52e4d 100644 --- a/profiling/src/profiling/mod.rs +++ b/profiling/src/profiling/mod.rs @@ -17,6 +17,7 @@ use crate::bindings::ddog_php_prof_get_active_fiber_test as ddog_php_prof_get_ac use crate::bindings::{datadog_php_profiling_get_profiling_context, zend_execute_data}; use crate::config::SystemSettings; use crate::{CLOCKS, TAGS}; +use chrono::Utc; use core::{ptr, str}; use crossbeam_channel::{Receiver, Sender, TrySendError}; use datadog_profiling::api::{ @@ -527,6 +528,7 @@ impl Profiler { upload_receiver, system_settings.output_pprof.clone(), system_settings.uri.clone(), + Utc::now(), ); let ddprof_time = "ddprof_time"; diff --git a/profiling/src/profiling/uploader.rs b/profiling/src/profiling/uploader.rs index f9343334af..aac911d21e 100644 --- a/profiling/src/profiling/uploader.rs +++ b/profiling/src/profiling/uploader.rs @@ -3,6 +3,7 @@ use crate::config::AgentEndpoint; use crate::exception::EXCEPTION_PROFILING_EXCEPTION_COUNT; use crate::profiling::{UploadMessage, UploadRequest}; use crate::{PROFILER_NAME_STR, PROFILER_VERSION_STR}; +use chrono::{DateTime, Utc}; use crossbeam_channel::{select, Receiver}; use datadog_profiling::exporter::File; use ddcommon::Endpoint; @@ -19,6 +20,7 @@ pub struct Uploader { receiver: Receiver, output_pprof: Option>, endpoint: AgentEndpoint, + start_time: String, } impl Uploader { @@ -27,12 +29,14 @@ impl Uploader { receiver: Receiver, output_pprof: Option>, endpoint: AgentEndpoint, + start_time: DateTime, ) -> Self { Self { fork_barrier, receiver, output_pprof, endpoint, + start_time: start_time.to_rfc3339_opts(chrono::SecondsFormat::Secs, true), } } @@ -47,6 +51,15 @@ impl Uploader { Some(metadata) } + fn create_profiler_info(&self) -> Option { + let metadata = json!({ + "application": { + "start_time": self.start_time, + } + }); + Some(metadata) + } + fn upload(&self, message: Box) -> anyhow::Result { let index = message.index; let profile = message.profile; @@ -84,7 +97,7 @@ impl Uploader { None, endpoint_counts, Self::create_internal_metadata(), - None, + self.create_profiler_info(), timeout, )?; debug!("Sending profile to: {agent_endpoint}");