Skip to content

Commit b9b6bf9

Browse files
committed
feat(profiling): Simpler API for profile exporter
1 parent 5027515 commit b9b6bf9

File tree

5 files changed

+103
-525
lines changed

5 files changed

+103
-525
lines changed

examples/ffi/exporter.cpp

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ int main(int argc, char *argv[]) {
123123
auto exporter = &exporter_new_result.ok;
124124

125125
auto files_to_compress_and_export = ddog_prof_Exporter_Slice_File_empty();
126-
auto files_to_export_unmodified = ddog_prof_Exporter_Slice_File_empty();
127126

128127
ddog_CharSlice internal_metadata_example = DDOG_CHARSLICE_C_BARE(
129128
"{\"no_signals_workaround_enabled\": \"true\", \"execution_trace_enabled\": \"false\"}");
@@ -132,32 +131,12 @@ int main(int argc, char *argv[]) {
132131
DDOG_CHARSLICE_C_BARE("{\"application\": {\"start_time\": \"2024-01-24T11:17:22+0000\"}, "
133132
"\"platform\": {\"kernel\": \"Darwin Kernel 22.5.0\"}}");
134133

135-
auto res = ddog_prof_Exporter_set_timeout(exporter, 30000);
136-
if (res.tag == DDOG_VOID_RESULT_ERR) {
137-
print_error("Failed to set the timeout", res.err);
138-
ddog_Error_drop(&res.err);
139-
return 1;
140-
}
141-
142-
auto build_result = ddog_prof_Exporter_Request_build(
143-
exporter, encoded_profile, files_to_compress_and_export, files_to_export_unmodified, nullptr, nullptr,
144-
&internal_metadata_example, &info_example);
145-
ddog_prof_EncodedProfile_drop(encoded_profile);
146-
147-
if (build_result.tag == DDOG_PROF_REQUEST_RESULT_ERR_HANDLE_REQUEST) {
148-
print_error("Failed to build request: ", build_result.err);
149-
ddog_Error_drop(&build_result.err);
150-
return 1;
151-
}
152-
153-
auto request = &build_result.ok;
154-
155134
auto cancel = ddog_CancellationToken_new();
156135
auto cancel_for_background_thread = ddog_CancellationToken_clone(&cancel);
157136

158137
// As an example of CancellationToken usage, here we create a background
159138
// thread that sleeps for some time and then cancels a request early (e.g.
160-
// before the timeout in ddog_ProfileExporter_send is hit).
139+
// before the timeout in ddog_prof_Exporter_send_blocking is hit).
161140
//
162141
// If the request is faster than the sleep time, no cancellation takes place.
163142
std::thread trigger_cancel_if_request_takes_too_long_thread(
@@ -174,7 +153,9 @@ int main(int argc, char *argv[]) {
174153
trigger_cancel_if_request_takes_too_long_thread.detach();
175154

176155
int exit_code = 0;
177-
auto send_result = ddog_prof_Exporter_send(exporter, request, &cancel);
156+
auto send_result = ddog_prof_Exporter_send_blocking(
157+
exporter, encoded_profile, files_to_compress_and_export,
158+
nullptr, nullptr, &internal_metadata_example, &info_example, &cancel);
178159
if (send_result.tag == DDOG_PROF_RESULT_HTTP_STATUS_ERR_HTTP_STATUS) {
179160
print_error("Failed to send profile: ", send_result.err);
180161
exit_code = 1;
@@ -183,7 +164,6 @@ int main(int argc, char *argv[]) {
183164
printf("Response code: %d\n", send_result.ok.code);
184165
}
185166

186-
ddog_prof_Exporter_Request_drop(request);
187167
ddog_prof_Exporter_drop(exporter);
188168
ddog_CancellationToken_drop(&cancel);
189169
return exit_code;

0 commit comments

Comments
 (0)