3232#include < ruby.h>
3333
3434#include " rcb_backend.hxx"
35+ #include " rcb_observability.hxx"
3536#include " rcb_utils.hxx"
3637
3738namespace couchbase ::ruby
@@ -273,7 +274,10 @@ cb_generate_bucket_settings(VALUE bucket,
273274}
274275
275276VALUE
276- cb_Backend_bucket_create (VALUE self, VALUE bucket_settings, VALUE options)
277+ cb_Backend_bucket_create (VALUE self,
278+ VALUE bucket_settings,
279+ VALUE options,
280+ VALUE observability_handler)
277281{
278282 auto cluster = cb_backend_to_core_api_cluster (self);
279283
@@ -286,12 +290,15 @@ cb_Backend_bucket_create(VALUE self, VALUE bucket_settings, VALUE options)
286290 core::operations::management::bucket_create_request req{};
287291 cb_extract_timeout (req, options);
288292 cb_generate_bucket_settings (bucket_settings, req.bucket , true );
293+ auto parent_span = cb_create_parent_span (req, self);
289294 std::promise<core::operations::management::bucket_create_response> promise;
290295 auto f = promise.get_future ();
291296 cluster.execute (req, [promise = std::move (promise)](auto && resp) mutable {
292297 promise.set_value (std::forward<decltype (resp)>(resp));
293298 });
294- if (auto resp = cb_wait_for_future (f); resp.ctx .ec ) {
299+ auto resp = cb_wait_for_future (f);
300+ cb_add_core_spans (observability_handler, std::move (parent_span), resp.ctx .retry_attempts );
301+ if (resp.ctx .ec ) {
295302 cb_throw_error (resp.ctx ,
296303 fmt::format (" unable to create bucket \" {}\" on the cluster ({})" ,
297304 req.bucket .name ,
@@ -309,7 +316,10 @@ cb_Backend_bucket_create(VALUE self, VALUE bucket_settings, VALUE options)
309316}
310317
311318VALUE
312- cb_Backend_bucket_update (VALUE self, VALUE bucket_settings, VALUE options)
319+ cb_Backend_bucket_update (VALUE self,
320+ VALUE bucket_settings,
321+ VALUE options,
322+ VALUE observability_handler)
313323{
314324 auto cluster = cb_backend_to_core_api_cluster (self);
315325
@@ -321,12 +331,15 @@ cb_Backend_bucket_update(VALUE self, VALUE bucket_settings, VALUE options)
321331 core::operations::management::bucket_update_request req{};
322332 cb_extract_timeout (req, options);
323333 cb_generate_bucket_settings (bucket_settings, req.bucket , false );
334+ auto parent_span = cb_create_parent_span (req, self);
324335 std::promise<core::operations::management::bucket_update_response> promise;
325336 auto f = promise.get_future ();
326337 cluster.execute (req, [promise = std::move (promise)](auto && resp) mutable {
327338 promise.set_value (std::forward<decltype (resp)>(resp));
328339 });
329- if (auto resp = cb_wait_for_future (f); resp.ctx .ec ) {
340+ auto resp = cb_wait_for_future (f);
341+ cb_add_core_spans (observability_handler, std::move (parent_span), resp.ctx .retry_attempts );
342+ if (resp.ctx .ec ) {
330343 cb_throw_error (resp.ctx ,
331344 fmt::format (" unable to update bucket \" {}\" on the cluster ({})" ,
332345 req.bucket .name ,
@@ -343,7 +356,7 @@ cb_Backend_bucket_update(VALUE self, VALUE bucket_settings, VALUE options)
343356}
344357
345358VALUE
346- cb_Backend_bucket_drop (VALUE self, VALUE bucket_name, VALUE options)
359+ cb_Backend_bucket_drop (VALUE self, VALUE bucket_name, VALUE options, VALUE observability_handler )
347360{
348361 auto cluster = cb_backend_to_core_api_cluster (self);
349362
@@ -355,12 +368,15 @@ cb_Backend_bucket_drop(VALUE self, VALUE bucket_name, VALUE options)
355368 try {
356369 core::operations::management::bucket_drop_request req{ cb_string_new (bucket_name) };
357370 cb_extract_timeout (req, options);
371+ auto parent_span = cb_create_parent_span (req, self);
358372 std::promise<core::operations::management::bucket_drop_response> promise;
359373 auto f = promise.get_future ();
360374 cluster.execute (req, [promise = std::move (promise)](auto && resp) mutable {
361375 promise.set_value (std::forward<decltype (resp)>(resp));
362376 });
363- if (auto resp = cb_wait_for_future (f); resp.ctx .ec ) {
377+ auto resp = cb_wait_for_future (f);
378+ cb_add_core_spans (observability_handler, std::move (parent_span), resp.ctx .retry_attempts );
379+ if (resp.ctx .ec ) {
364380 cb_throw_error (resp.ctx ,
365381 fmt::format (" unable to remove bucket \" {}\" on the cluster" , req.name ));
366382 }
@@ -375,7 +391,7 @@ cb_Backend_bucket_drop(VALUE self, VALUE bucket_name, VALUE options)
375391}
376392
377393VALUE
378- cb_Backend_bucket_flush (VALUE self, VALUE bucket_name, VALUE options)
394+ cb_Backend_bucket_flush (VALUE self, VALUE bucket_name, VALUE options, VALUE observability_handler )
379395{
380396 auto cluster = cb_backend_to_core_api_cluster (self);
381397
@@ -387,12 +403,15 @@ cb_Backend_bucket_flush(VALUE self, VALUE bucket_name, VALUE options)
387403 try {
388404 core::operations::management::bucket_flush_request req{ cb_string_new (bucket_name) };
389405 cb_extract_timeout (req, options);
406+ auto parent_span = cb_create_parent_span (req, self);
390407 std::promise<core::operations::management::bucket_flush_response> promise;
391408 auto f = promise.get_future ();
392409 cluster.execute (req, [promise = std::move (promise)](auto && resp) mutable {
393410 promise.set_value (std::forward<decltype (resp)>(resp));
394411 });
395- if (auto resp = cb_wait_for_future (f); resp.ctx .ec ) {
412+ auto resp = cb_wait_for_future (f);
413+ cb_add_core_spans (observability_handler, std::move (parent_span), resp.ctx .retry_attempts );
414+ if (resp.ctx .ec ) {
396415 cb_throw_error (resp.ctx ,
397416 fmt::format (" unable to flush bucket \" {}\" on the cluster" , req.name ));
398417 }
@@ -562,7 +581,7 @@ cb_extract_bucket_settings(const core::management::cluster::bucket_settings& ent
562581}
563582
564583VALUE
565- cb_Backend_bucket_get_all (VALUE self, VALUE options)
584+ cb_Backend_bucket_get_all (VALUE self, VALUE options, VALUE observability_handler )
566585{
567586 auto cluster = cb_backend_to_core_api_cluster (self);
568587
@@ -573,12 +592,14 @@ cb_Backend_bucket_get_all(VALUE self, VALUE options)
573592 try {
574593 core::operations::management::bucket_get_all_request req{};
575594 cb_extract_timeout (req, options);
595+ auto parent_span = cb_create_parent_span (req, self);
576596 std::promise<core::operations::management::bucket_get_all_response> promise;
577597 auto f = promise.get_future ();
578598 cluster.execute (req, [promise = std::move (promise)](auto && resp) mutable {
579599 promise.set_value (std::forward<decltype (resp)>(resp));
580600 });
581601 auto resp = cb_wait_for_future (f);
602+ cb_add_core_spans (observability_handler, std::move (parent_span), resp.ctx .retry_attempts );
582603 if (resp.ctx .ec ) {
583604 cb_throw_error (resp.ctx , " unable to get list of the buckets of the cluster" );
584605 }
@@ -601,7 +622,7 @@ cb_Backend_bucket_get_all(VALUE self, VALUE options)
601622}
602623
603624VALUE
604- cb_Backend_bucket_get (VALUE self, VALUE bucket_name, VALUE options)
625+ cb_Backend_bucket_get (VALUE self, VALUE bucket_name, VALUE options, VALUE observability_handler )
605626{
606627 auto cluster = cb_backend_to_core_api_cluster (self);
607628
@@ -613,12 +634,14 @@ cb_Backend_bucket_get(VALUE self, VALUE bucket_name, VALUE options)
613634 try {
614635 core::operations::management::bucket_get_request req{ cb_string_new (bucket_name) };
615636 cb_extract_timeout (req, options);
637+ auto parent_span = cb_create_parent_span (req, self);
616638 std::promise<core::operations::management::bucket_get_response> promise;
617639 auto f = promise.get_future ();
618640 cluster.execute (req, [promise = std::move (promise)](auto && resp) mutable {
619641 promise.set_value (std::forward<decltype (resp)>(resp));
620642 });
621643 auto resp = cb_wait_for_future (f);
644+ cb_add_core_spans (observability_handler, std::move (parent_span), resp.ctx .retry_attempts );
622645 if (resp.ctx .ec ) {
623646 cb_throw_error (resp.ctx ,
624647 fmt::format (" unable to locate bucket \" {}\" on the cluster" , req.name ));
@@ -640,11 +663,11 @@ cb_Backend_bucket_get(VALUE self, VALUE bucket_name, VALUE options)
640663void
641664init_buckets (VALUE cBackend)
642665{
643- rb_define_method (cBackend, " bucket_create" , cb_Backend_bucket_create, 2 );
644- rb_define_method (cBackend, " bucket_update" , cb_Backend_bucket_update, 2 );
645- rb_define_method (cBackend, " bucket_drop" , cb_Backend_bucket_drop, 2 );
646- rb_define_method (cBackend, " bucket_flush" , cb_Backend_bucket_flush, 2 );
647- rb_define_method (cBackend, " bucket_get_all" , cb_Backend_bucket_get_all, 1 );
648- rb_define_method (cBackend, " bucket_get" , cb_Backend_bucket_get, 2 );
666+ rb_define_method (cBackend, " bucket_create" , cb_Backend_bucket_create, 3 );
667+ rb_define_method (cBackend, " bucket_update" , cb_Backend_bucket_update, 3 );
668+ rb_define_method (cBackend, " bucket_drop" , cb_Backend_bucket_drop, 3 );
669+ rb_define_method (cBackend, " bucket_flush" , cb_Backend_bucket_flush, 3 );
670+ rb_define_method (cBackend, " bucket_get_all" , cb_Backend_bucket_get_all, 2 );
671+ rb_define_method (cBackend, " bucket_get" , cb_Backend_bucket_get, 3 );
649672}
650673} // namespace couchbase::ruby
0 commit comments