Skip to content

Commit 6f118be

Browse files
chore(examples): update exporter.cpp
1 parent e8b26b9 commit 6f118be

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

examples/ffi/exporter.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,18 @@ int main(int argc, char *argv[]) {
135135
auto cancel = ddog_CancellationToken_new();
136136
auto cancel_for_background_thread = ddog_CancellationToken_clone(&cancel);
137137

138+
// Eagerly initialize the tokio runtime. This is optional, but required
139+
// to avoid race conditions if another thread might be using the
140+
// the cancellation token at the same time as the profile is being sent
141+
// (as is the case here).
142+
ddog_VoidResult init_result = ddog_prof_Exporter_init_runtime(exporter);
143+
if (init_result.tag != DDOG_VOID_RESULT_OK) {
144+
print_error("Failed to initialize exporter runtime: ", init_result.err);
145+
ddog_Error_drop(&init_result.err);
146+
ddog_prof_Exporter_drop(exporter);
147+
return 1;
148+
}
149+
138150
// As an example of CancellationToken usage, here we create a background
139151
// thread that sleeps for some time and then cancels a request early (e.g.
140152
// before the timeout in ddog_prof_Exporter_send_blocking is hit).

0 commit comments

Comments
 (0)