Skip to content

Commit 139d731

Browse files
committed
RCBC-527: Include child spans created by the C++ core
1 parent 0f464c7 commit 139d731

29 files changed

Lines changed: 1572 additions & 504 deletions

ext/couchbase

ext/rcb_analytics.cxx

Lines changed: 157 additions & 47 deletions
Large diffs are not rendered by default.

ext/rcb_buckets.cxx

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <ruby.h>
3333

3434
#include "rcb_backend.hxx"
35+
#include "rcb_observability.hxx"
3536
#include "rcb_utils.hxx"
3637

3738
namespace couchbase::ruby
@@ -273,7 +274,10 @@ cb_generate_bucket_settings(VALUE bucket,
273274
}
274275

275276
VALUE
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

311318
VALUE
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

345358
VALUE
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

377393
VALUE
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

564583
VALUE
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

603624
VALUE
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)
640663
void
641664
init_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

ext/rcb_collections.cxx

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,15 @@
3131
#include <ruby.h>
3232

3333
#include "rcb_backend.hxx"
34+
#include "rcb_observability.hxx"
3435
#include "rcb_utils.hxx"
3536

3637
namespace couchbase::ruby
3738
{
3839
namespace
3940
{
4041
VALUE
41-
cb_Backend_scope_get_all(VALUE self, VALUE bucket_name, VALUE options)
42+
cb_Backend_scope_get_all(VALUE self, VALUE bucket_name, VALUE options, VALUE observability_handler)
4243
{
4344
auto cluster = cb_backend_to_core_api_cluster(self);
4445

@@ -50,12 +51,14 @@ cb_Backend_scope_get_all(VALUE self, VALUE bucket_name, VALUE options)
5051
try {
5152
core::operations::management::scope_get_all_request req{ cb_string_new(bucket_name) };
5253
cb_extract_timeout(req, options);
54+
auto parent_span = cb_create_parent_span(req, self);
5355
std::promise<core::operations::management::scope_get_all_response> promise;
5456
auto f = promise.get_future();
5557
cluster.execute(req, [promise = std::move(promise)](auto&& resp) mutable {
5658
promise.set_value(std::forward<decltype(resp)>(resp));
5759
});
5860
auto resp = cb_wait_for_future(f);
61+
cb_add_core_spans(observability_handler, std::move(parent_span), resp.ctx.retry_attempts);
5962
if (resp.ctx.ec) {
6063
cb_throw_error(
6164
resp.ctx,
@@ -97,7 +100,11 @@ cb_Backend_scope_get_all(VALUE self, VALUE bucket_name, VALUE options)
97100
}
98101

99102
VALUE
100-
cb_Backend_scope_create(VALUE self, VALUE bucket_name, VALUE scope_name, VALUE options)
103+
cb_Backend_scope_create(VALUE self,
104+
VALUE bucket_name,
105+
VALUE scope_name,
106+
VALUE options,
107+
VALUE observability_handler)
101108
{
102109
auto cluster = cb_backend_to_core_api_cluster(self);
103110

@@ -111,12 +118,14 @@ cb_Backend_scope_create(VALUE self, VALUE bucket_name, VALUE scope_name, VALUE o
111118
core::operations::management::scope_create_request req{ cb_string_new(bucket_name),
112119
cb_string_new(scope_name) };
113120
cb_extract_timeout(req, options);
121+
auto parent_span = cb_create_parent_span(req, self);
114122
std::promise<core::operations::management::scope_create_response> promise;
115123
auto f = promise.get_future();
116124
cluster.execute(req, [promise = std::move(promise)](auto&& resp) mutable {
117125
promise.set_value(std::forward<decltype(resp)>(resp));
118126
});
119127
auto resp = cb_wait_for_future(f);
128+
cb_add_core_spans(observability_handler, std::move(parent_span), resp.ctx.retry_attempts);
120129

121130
if (resp.ctx.ec) {
122131
cb_throw_error(resp.ctx,
@@ -135,7 +144,11 @@ cb_Backend_scope_create(VALUE self, VALUE bucket_name, VALUE scope_name, VALUE o
135144
}
136145

137146
VALUE
138-
cb_Backend_scope_drop(VALUE self, VALUE bucket_name, VALUE scope_name, VALUE options)
147+
cb_Backend_scope_drop(VALUE self,
148+
VALUE bucket_name,
149+
VALUE scope_name,
150+
VALUE options,
151+
VALUE observability_handler)
139152
{
140153
auto cluster = cb_backend_to_core_api_cluster(self);
141154

@@ -149,12 +162,14 @@ cb_Backend_scope_drop(VALUE self, VALUE bucket_name, VALUE scope_name, VALUE opt
149162
core::operations::management::scope_drop_request req{ cb_string_new(bucket_name),
150163
cb_string_new(scope_name) };
151164
cb_extract_timeout(req, options);
165+
auto parent_span = cb_create_parent_span(req, self);
152166
std::promise<core::operations::management::scope_drop_response> promise;
153167
auto f = promise.get_future();
154168
cluster.execute(req, [promise = std::move(promise)](auto&& resp) mutable {
155169
promise.set_value(std::forward<decltype(resp)>(resp));
156170
});
157171
auto resp = cb_wait_for_future(f);
172+
cb_add_core_spans(observability_handler, std::move(parent_span), resp.ctx.retry_attempts);
158173
if (resp.ctx.ec) {
159174
cb_throw_error(resp.ctx,
160175
fmt::format(R"(unable to drop the scope "{}" on the bucket "{}")",
@@ -177,7 +192,8 @@ cb_Backend_collection_create(VALUE self,
177192
VALUE scope_name,
178193
VALUE collection_name,
179194
VALUE settings,
180-
VALUE options)
195+
VALUE options,
196+
VALUE observability_handler)
181197
{
182198
auto cluster = cb_backend_to_core_api_cluster(self);
183199

@@ -220,13 +236,15 @@ cb_Backend_collection_create(VALUE self,
220236
req.history = RTEST(history);
221237
}
222238
}
239+
auto parent_span = cb_create_parent_span(req, self);
223240

224241
std::promise<core::operations::management::collection_create_response> promise;
225242
auto f = promise.get_future();
226243
cluster.execute(req, [promise = std::move(promise)](auto&& resp) mutable {
227244
promise.set_value(std::forward<decltype(resp)>(resp));
228245
});
229246
auto resp = cb_wait_for_future(f);
247+
cb_add_core_spans(observability_handler, std::move(parent_span), resp.ctx.retry_attempts);
230248
if (resp.ctx.ec) {
231249
cb_throw_error(resp.ctx,
232250
fmt::format(R"(unable create the collection "{}.{}" on the bucket "{}")",
@@ -250,7 +268,8 @@ cb_Backend_collection_update(VALUE self,
250268
VALUE scope_name,
251269
VALUE collection_name,
252270
VALUE settings,
253-
VALUE options)
271+
VALUE options,
272+
VALUE observability_handler)
254273
{
255274
auto cluster = cb_backend_to_core_api_cluster(self);
256275

@@ -293,13 +312,15 @@ cb_Backend_collection_update(VALUE self,
293312
req.history = RTEST(history);
294313
}
295314
}
315+
auto parent_span = cb_create_parent_span(req, self);
296316

297317
std::promise<core::operations::management::collection_update_response> promise;
298318
auto f = promise.get_future();
299319
cluster.execute(req, [promise = std::move(promise)](auto&& resp) mutable {
300320
promise.set_value(std::forward<decltype(resp)>(resp));
301321
});
302322
auto resp = cb_wait_for_future(f);
323+
cb_add_core_spans(observability_handler, std::move(parent_span), resp.ctx.retry_attempts);
303324
if (resp.ctx.ec) {
304325
cb_throw_error(resp.ctx,
305326
fmt::format(R"(unable update the collection "{}.{}" on the bucket "{}")",
@@ -322,7 +343,8 @@ cb_Backend_collection_drop(VALUE self,
322343
VALUE bucket_name,
323344
VALUE scope_name,
324345
VALUE collection_name,
325-
VALUE options)
346+
VALUE options,
347+
VALUE observability_handler)
326348
{
327349
auto cluster = cb_backend_to_core_api_cluster(self);
328350

@@ -338,13 +360,15 @@ cb_Backend_collection_drop(VALUE self,
338360
cb_string_new(scope_name),
339361
cb_string_new(collection_name) };
340362
cb_extract_timeout(req, options);
363+
auto parent_span = cb_create_parent_span(req, self);
341364

342365
std::promise<core::operations::management::collection_drop_response> promise;
343366
auto f = promise.get_future();
344367
cluster.execute(req, [promise = std::move(promise)](auto&& resp) mutable {
345368
promise.set_value(std::forward<decltype(resp)>(resp));
346369
});
347370
auto resp = cb_wait_for_future(f);
371+
cb_add_core_spans(observability_handler, std::move(parent_span), resp.ctx.retry_attempts);
348372
if (resp.ctx.ec) {
349373
cb_throw_error(resp.ctx,
350374
fmt::format(R"(unable to drop the collection "{}.{}" on the bucket "{}")",
@@ -367,11 +391,11 @@ cb_Backend_collection_drop(VALUE self,
367391
void
368392
init_collections(VALUE cBackend)
369393
{
370-
rb_define_method(cBackend, "scope_get_all", cb_Backend_scope_get_all, 2);
371-
rb_define_method(cBackend, "scope_create", cb_Backend_scope_create, 3);
372-
rb_define_method(cBackend, "scope_drop", cb_Backend_scope_drop, 3);
373-
rb_define_method(cBackend, "collection_create", cb_Backend_collection_create, 5);
374-
rb_define_method(cBackend, "collection_update", cb_Backend_collection_update, 5);
375-
rb_define_method(cBackend, "collection_drop", cb_Backend_collection_drop, 4);
394+
rb_define_method(cBackend, "scope_get_all", cb_Backend_scope_get_all, 3);
395+
rb_define_method(cBackend, "scope_create", cb_Backend_scope_create, 4);
396+
rb_define_method(cBackend, "scope_drop", cb_Backend_scope_drop, 4);
397+
rb_define_method(cBackend, "collection_create", cb_Backend_collection_create, 6);
398+
rb_define_method(cBackend, "collection_update", cb_Backend_collection_update, 6);
399+
rb_define_method(cBackend, "collection_drop", cb_Backend_collection_drop, 5);
376400
}
377401
} // namespace couchbase::ruby

0 commit comments

Comments
 (0)