@@ -38,8 +38,7 @@ int main(int argc, char *argv[]) {
38
38
39
39
const ddog_prof_Slice_ValueType sample_types = {&wall_time, 1 };
40
40
const ddog_prof_Period period = {wall_time, 60 };
41
- ddog_prof_Profile_NewResult profile_new_result =
42
- ddog_prof_Profile_new (sample_types, &period, nullptr );
41
+ ddog_prof_Profile_NewResult profile_new_result = ddog_prof_Profile_new (sample_types, &period);
43
42
if (profile_new_result.tag != DDOG_PROF_PROFILE_NEW_RESULT_OK) {
44
43
print_error (" Failed to make new profile: " , profile_new_result.err );
45
44
ddog_Error_drop (&profile_new_result.err );
@@ -96,9 +95,9 @@ int main(int argc, char *argv[]) {
96
95
return 1 ;
97
96
}
98
97
99
- ddog_prof_EncodedProfile *encoded_profile = &serialize_result.ok ;
98
+ auto *encoded_profile = &serialize_result.ok ;
100
99
101
- ddog_prof_Endpoint endpoint =
100
+ auto endpoint =
102
101
ddog_prof_Endpoint_agentless (DDOG_CHARSLICE_C_BARE (" datad0g.com" ), to_slice_c_char (api_key));
103
102
104
103
ddog_Vec_Tag tags = ddog_Vec_Tag_new ();
@@ -110,90 +109,82 @@ int main(int argc, char *argv[]) {
110
109
return 1 ;
111
110
}
112
111
113
- ddog_prof_Exporter_NewResult exporter_new_result =
114
- ddog_prof_Exporter_new ( DDOG_CHARSLICE_C_BARE (" exporter-example" ), DDOG_CHARSLICE_C_BARE (" 1.2.3" ),
115
- DDOG_CHARSLICE_C_BARE (" native" ), &tags, endpoint);
112
+ auto exporter_new_result = ddog_prof_Exporter_new (
113
+ DDOG_CHARSLICE_C_BARE (" exporter-example" ), DDOG_CHARSLICE_C_BARE (" 1.2.3" ),
114
+ DDOG_CHARSLICE_C_BARE (" native" ), &tags, endpoint);
116
115
ddog_Vec_Tag_drop (tags);
117
116
118
- if (exporter_new_result.tag == DDOG_PROF_EXPORTER_NEW_RESULT_ERR ) {
117
+ if (exporter_new_result.tag == DDOG_PROF_PROFILE_EXPORTER_RESULT_ERR_HANDLE_PROFILE_EXPORTER ) {
119
118
print_error (" Failed to create exporter: " , exporter_new_result.err );
120
119
ddog_Error_drop (&exporter_new_result.err );
121
120
return 1 ;
122
121
}
123
122
124
- auto exporter = exporter_new_result.ok ;
123
+ auto exporter = & exporter_new_result.ok ;
125
124
126
- ddog_prof_Exporter_File files_to_compress_and_export_[] = {{
127
- .name = DDOG_CHARSLICE_C_BARE (" auto.pprof" ),
128
- .file = ddog_Vec_U8_as_slice (&encoded_profile->buffer ),
129
- }};
130
- ddog_prof_Exporter_Slice_File files_to_compress_and_export = {
131
- .ptr = files_to_compress_and_export_,
132
- .len = sizeof files_to_compress_and_export_ / sizeof *files_to_compress_and_export_,
133
- };
134
-
135
- ddog_prof_Exporter_Slice_File files_to_export_unmodified = ddog_prof_Exporter_Slice_File_empty ();
125
+ auto files_to_compress_and_export = ddog_prof_Exporter_Slice_File_empty ();
126
+ auto files_to_export_unmodified = ddog_prof_Exporter_Slice_File_empty ();
136
127
137
128
ddog_CharSlice internal_metadata_example = DDOG_CHARSLICE_C_BARE (
138
129
" {\" no_signals_workaround_enabled\" : \" true\" , \" execution_trace_enabled\" : \" false\" }" );
139
130
140
- ddog_CharSlice info_example = DDOG_CHARSLICE_C_BARE (
141
- " {\" application\" : {\" start_time\" : \" 2024-01-24T11:17:22+0000\" }, \" platform\" : {\" kernel\" : \" Darwin Kernel 22.5.0\" }}" );
131
+ ddog_CharSlice info_example =
132
+ DDOG_CHARSLICE_C_BARE (" {\" application\" : {\" start_time\" : \" 2024-01-24T11:17:22+0000\" }, "
133
+ " \" platform\" : {\" kernel\" : \" Darwin Kernel 22.5.0\" }}" );
142
134
143
135
auto res = ddog_prof_Exporter_set_timeout (exporter, 30000 );
144
- if (res.tag == DDOG_PROF_OPTION_ERROR_SOME_ERROR ) {
145
- print_error (" Failed to set the timeout" , res.some );
146
- ddog_Error_drop (&res.some );
147
- return 1 ;
136
+ if (res.tag == DDOG_PROF_VOID_RESULT_ERR ) {
137
+ print_error (" Failed to set the timeout" , res.err );
138
+ ddog_Error_drop (&res.err );
139
+ return 1 ;
148
140
}
149
141
150
- ddog_prof_Exporter_Request_BuildResult build_result = ddog_prof_Exporter_Request_build (
151
- exporter, encoded_profile-> start , encoded_profile-> end , files_to_compress_and_export ,
152
- files_to_export_unmodified, nullptr , nullptr , &internal_metadata_example, &info_example);
142
+ auto build_result = ddog_prof_Exporter_Request_build (
143
+ exporter, encoded_profile, files_to_compress_and_export, files_to_export_unmodified, nullptr ,
144
+ &internal_metadata_example, &info_example);
153
145
ddog_prof_EncodedProfile_drop (encoded_profile);
154
146
155
- if (build_result.tag == DDOG_PROF_EXPORTER_REQUEST_BUILD_RESULT_ERR ) {
147
+ if (build_result.tag == DDOG_PROF_REQUEST_RESULT_ERR_HANDLE_REQUEST ) {
156
148
print_error (" Failed to build request: " , build_result.err );
157
149
ddog_Error_drop (&build_result.err );
158
150
return 1 ;
159
151
}
160
152
161
- auto & request = build_result.ok ;
153
+ auto request = & build_result.ok ;
162
154
163
- ddog_CancellationToken * cancel = ddog_CancellationToken_new ();
164
- ddog_CancellationToken * cancel_for_background_thread = ddog_CancellationToken_clone (cancel);
155
+ auto cancel = ddog_CancellationToken_new ();
156
+ auto cancel_for_background_thread = ddog_CancellationToken_clone (& cancel);
165
157
166
158
// As an example of CancellationToken usage, here we create a background
167
159
// thread that sleeps for some time and then cancels a request early (e.g.
168
160
// before the timeout in ddog_ProfileExporter_send is hit).
169
161
//
170
162
// If the request is faster than the sleep time, no cancellation takes place.
171
163
std::thread trigger_cancel_if_request_takes_too_long_thread (
172
- [](ddog_CancellationToken * cancel_for_background_thread) {
164
+ [](ddog_prof_CancellationToken cancel_for_background_thread) {
173
165
int timeout_ms = 5000 ;
174
166
std::this_thread::sleep_for (std::chrono::milliseconds (timeout_ms));
175
167
printf (" Request took longer than %d ms, triggering asynchronous "
176
168
" cancellation\n " ,
177
169
timeout_ms);
178
- ddog_CancellationToken_cancel (cancel_for_background_thread);
179
- ddog_CancellationToken_drop (cancel_for_background_thread);
170
+ ddog_CancellationToken_cancel (& cancel_for_background_thread);
171
+ ddog_CancellationToken_drop (& cancel_for_background_thread);
180
172
},
181
173
cancel_for_background_thread);
182
174
trigger_cancel_if_request_takes_too_long_thread.detach ();
183
175
184
176
int exit_code = 0 ;
185
- ddog_prof_Exporter_SendResult send_result = ddog_prof_Exporter_send (exporter, & request, cancel);
186
- if (send_result.tag == DDOG_PROF_EXPORTER_SEND_RESULT_ERR ) {
177
+ auto send_result = ddog_prof_Exporter_send (exporter, request, & cancel);
178
+ if (send_result.tag == DDOG_PROF_RESULT_HTTP_STATUS_ERR_HTTP_STATUS ) {
187
179
print_error (" Failed to send profile: " , send_result.err );
188
180
exit_code = 1 ;
189
181
ddog_Error_drop (&send_result.err );
190
182
} else {
191
- printf (" Response code: %d\n " , send_result.http_response .code );
183
+ printf (" Response code: %d\n " , send_result.ok .code );
192
184
}
193
185
194
- ddog_prof_Exporter_Request_drop (&request);
195
-
186
+ ddog_prof_Exporter_Request_drop (request);
196
187
ddog_prof_Exporter_drop (exporter);
197
- ddog_CancellationToken_drop (cancel);
188
+ ddog_CancellationToken_drop (& cancel);
198
189
return exit_code;
199
190
}
0 commit comments