Skip to content

Commit a6fa778

Browse files
refactor(profiling): use two-time upload api in libdatadog
1 parent 011a989 commit a6fa778

2 files changed

Lines changed: 30 additions & 23 deletions

File tree

ddtrace/internal/datadog/profiling/dd_wrapper/src/uploader.cpp

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
#include "profiler_state.hpp"
66
#include "profiler_stats.hpp"
77

8-
#include <cerrno> // errno
9-
#include <cstring> // strerror
8+
#include <cerrno> // errno
9+
#include <cstring> // strerror
1010
#include <fstream> // ofstream
1111
#include <sstream> // ostringstream
1212
#include <unistd.h> // getpid
@@ -122,7 +122,14 @@ Datadog::Uploader::upload_unlocked()
122122
.len = static_cast<uintptr_t>(to_compress_files.size()),
123123
};
124124

125-
bool ret = true;
125+
// Build and send the request in one call
126+
auto init_runtime_res = ddog_prof_Exporter_init_runtime(&ddog_exporter);
127+
if (init_runtime_res.tag != DDOG_VOID_RESULT_OK) {
128+
std::cerr << "Error initializing runtime: " << err_to_msg(&init_runtime_res.err, "Error initializing runtime")
129+
<< std::endl;
130+
return false;
131+
}
132+
126133
// Before starting a new upload, we need to cancel the current one (if it exists).
127134
// To do that, we exchange the current cancellation token with a new one (which will be used for our own upload)
128135
// If the current cancellation token was not null, then we use it to cancel the ongoing upload, then drop it.
@@ -138,16 +145,16 @@ Datadog::Uploader::upload_unlocked()
138145
ddog_CancellationToken_drop(&current_cancel);
139146
}
140147

141-
// Build and send the request in one call
142-
ddog_prof_Result_HttpStatus res = ddog_prof_Exporter_send_blocking(&ddog_exporter,
143-
&encoded_profile,
144-
files_to_compress,
145-
nullptr, // optional_additional_tags
146-
optional_process_tags_ptr,
147-
&internal_metadata_json_slice,
148-
nullptr, // optional_info_json
149-
&new_cancel_clone_for_request);
148+
auto res = ddog_prof_Exporter_send_blocking(&ddog_exporter,
149+
&encoded_profile,
150+
files_to_compress,
151+
nullptr, // optional_additional_tags
152+
optional_process_tags_ptr,
153+
&internal_metadata_json_slice,
154+
nullptr, // optional_info_json
155+
&new_cancel_clone_for_request);
150156

157+
bool ret = true;
151158
if (res.tag == DDOG_PROF_RESULT_HTTP_STATUS_ERR_HTTP_STATUS) { // NOLINT (cppcoreguidelines-pro-type-union-access)
152159
auto err = res.err; // NOLINT (cppcoreguidelines-pro-type-union-access)
153160
errmsg = err_to_msg(&err, "Error uploading");

src/native/Cargo.toml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,27 @@ anyhow = { version = "1.0", optional = true }
2121
libc = { version = "0.2", optional = true }
2222
rand = "0.9"
2323
serde = "1.0"
24-
datadog-ffe = { git = "https://github.com/DataDog/libdatadog", rev = "v28.0.4", optional = true, version = "1.0.0", features = ["pyo3"] }
24+
datadog-ffe = { git = "https://github.com/DataDog/libdatadog", rev = "1e58e48a2bf22e472669bddb4e578e09d9c6746f", optional = true, version = "1.0.0", features = ["pyo3"] }
2525
serde_json = "1.0"
26-
datadog-remote-config = { git = "https://github.com/DataDog/libdatadog", rev = "v28.0.4" }
27-
datadog-tracer-flare = { git = "https://github.com/DataDog/libdatadog", rev = "v28.0.4" }
28-
libdd-crashtracker = { git = "https://github.com/DataDog/libdatadog", rev = "v28.0.4", optional = true }
29-
libdd-ddsketch = { git = "https://github.com/DataDog/libdatadog", rev = "v28.0.4", optional = true }
30-
libdd-library-config = { git = "https://github.com/DataDog/libdatadog", rev = "v28.0.4" }
26+
datadog-remote-config = { git = "https://github.com/DataDog/libdatadog", rev = "1e58e48a2bf22e472669bddb4e578e09d9c6746f" }
27+
datadog-tracer-flare = { git = "https://github.com/DataDog/libdatadog", rev = "1e58e48a2bf22e472669bddb4e578e09d9c6746f" }
28+
libdd-crashtracker = { git = "https://github.com/DataDog/libdatadog", rev = "1e58e48a2bf22e472669bddb4e578e09d9c6746f", optional = true }
29+
libdd-ddsketch = { git = "https://github.com/DataDog/libdatadog", rev = "1e58e48a2bf22e472669bddb4e578e09d9c6746f", optional = true }
30+
libdd-library-config = { git = "https://github.com/DataDog/libdatadog", rev = "1e58e48a2bf22e472669bddb4e578e09d9c6746f" }
3131
libdd-log = { git = "https://github.com/DataDog/libdatadog", rev = "v27.0.0" }
32-
libdd-data-pipeline = { git = "https://github.com/DataDog/libdatadog", rev = "v28.0.4" }
33-
libdd-profiling-ffi = { git = "https://github.com/DataDog/libdatadog", rev = "v28.0.4", optional = true, features = [
32+
libdd-data-pipeline = { git = "https://github.com/DataDog/libdatadog", rev = "1e58e48a2bf22e472669bddb4e578e09d9c6746f" }
33+
libdd-profiling-ffi = { git = "https://github.com/DataDog/libdatadog", rev = "1e58e48a2bf22e472669bddb4e578e09d9c6746f", optional = true, features = [
3434
"cbindgen",
3535
] }
36-
libdd-common = { git = "https://github.com/DataDog/libdatadog", rev = "v28.0.4", optional = true }
37-
libdd-trace-utils = { git = "https://github.com/DataDog/libdatadog", rev = "v28.0.4" }
36+
libdd-common = { git = "https://github.com/DataDog/libdatadog", rev = "1e58e48a2bf22e472669bddb4e578e09d9c6746f", optional = true }
37+
libdd-trace-utils = { git = "https://github.com/DataDog/libdatadog", rev = "1e58e48a2bf22e472669bddb4e578e09d9c6746f" }
3838
pyo3 = { version = "0.27", features = ["extension-module", "anyhow"] }
3939
tracing = { version = "0.1", default-features = false }
4040
pyo3-ffi = { version = "0.27", optional = true }
4141

4242
[build-dependencies]
4343
pyo3-build-config = "0.27"
44-
build_common = { git = "https://github.com/DataDog/libdatadog", rev = "v28.0.4", features = [
44+
build_common = { git = "https://github.com/DataDog/libdatadog", rev = "1e58e48a2bf22e472669bddb4e578e09d9c6746f", features = [
4545
"cbindgen",
4646
] }
4747

0 commit comments

Comments
 (0)