Skip to content

Commit 1e58e48

Browse files
chore(examples): update exporter.cpp
1 parent 0ba86f7 commit 1e58e48

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
@@ -146,6 +146,18 @@ int main(int argc, char *argv[]) {
146146
auto cancel = ddog_CancellationToken_new();
147147
auto cancel_for_background_thread = ddog_CancellationToken_clone(&cancel);
148148

149+
// Eagerly initialize the tokio runtime. This is optional, but required
150+
// to avoid race conditions if another thread might be using the
151+
// the cancellation token at the same time as the profile is being sent
152+
// (as is the case here).
153+
ddog_VoidResult init_result = ddog_prof_Exporter_init_runtime(exporter);
154+
if (init_result.tag != DDOG_VOID_RESULT_OK) {
155+
print_error("Failed to initialize exporter runtime: ", init_result.err);
156+
ddog_Error_drop(&init_result.err);
157+
ddog_prof_Exporter_drop(exporter);
158+
return 1;
159+
}
160+
149161
// As an example of CancellationToken usage, here we create a background
150162
// thread that sleeps for some time and then cancels a request early (e.g.
151163
// before the timeout in ddog_prof_Exporter_send_blocking is hit).

0 commit comments

Comments
 (0)