Skip to content

Commit dda08cd

Browse files
committed
Implement bridge wrapper for tracer
1 parent a713385 commit dda08cd

File tree

11 files changed

+457
-14
lines changed

11 files changed

+457
-14
lines changed

CMakeLists.txt

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,20 @@ set(couchbase_cxx_client_FILES
7575
core/agent_group.cxx
7676
core/agent_group_config.cxx
7777
core/analytics_query_options.cxx
78+
core/app_telemetry_address.cxx
79+
core/app_telemetry_meter.cxx
80+
core/app_telemetry_reporter.cxx
7881
core/bucket.cxx
82+
core/chrono_utils.cxx
7983
core/cluster.cxx
8084
core/cluster_agent.cxx
8185
core/cluster_agent_config.cxx
86+
core/cluster_credentials.cxx
8287
core/cluster_options.cxx
8388
core/collections_component.cxx
89+
core/columnar/backoff_calculator.cxx
8490
core/columnar/columnar_agent.cxx
8591
core/columnar/columnar_agent_config.cxx
86-
core/columnar/backoff_calculator.cxx
8792
core/columnar/columnar_error.cxx
8893
core/columnar/error_codes.cxx
8994
core/columnar/management_component.cxx
@@ -105,14 +110,13 @@ set(couchbase_cxx_client_FILES
105110
core/impl/binary_collection.cxx
106111
core/impl/boolean_field_query.cxx
107112
core/impl/boolean_query.cxx
108-
core/impl/public_bucket.cxx
109113
core/impl/bucket_manager.cxx
110-
core/impl/public_cluster.cxx
111114
core/impl/collection.cxx
112115
core/impl/collection_manager.cxx
113116
core/impl/common_error_category.cxx
114117
core/impl/configuration_profiles_registry.cxx
115118
core/impl/conjunction_query.cxx
119+
core/impl/crypto.cxx
116120
core/impl/date_range.cxx
117121
core/impl/date_range_facet.cxx
118122
core/impl/date_range_facet_result.cxx
@@ -141,7 +145,6 @@ set(couchbase_cxx_client_FILES
141145
core/impl/internal_term_facet_result.cxx
142146
core/impl/key_value_error_category.cxx
143147
core/impl/key_value_error_context.cxx
144-
core/impl/public_logger.cxx
145148
core/impl/lookup_in_replica.cxx
146149
core/impl/management_error_category.cxx
147150
core/impl/match_all_query.cxx
@@ -157,6 +160,11 @@ set(couchbase_cxx_client_FILES
157160
core/impl/observe_seqno.cxx
158161
core/impl/phrase_query.cxx
159162
core/impl/prefix_query.cxx
163+
core/impl/public_bucket.cxx
164+
core/impl/public_cluster.cxx
165+
core/impl/public_logger.cxx
166+
core/impl/public_scan_result.cxx
167+
core/impl/public_transaction_get_result.cxx
160168
core/impl/query.cxx
161169
core/impl/query_error_category.cxx
162170
core/impl/query_error_context.cxx
@@ -166,7 +174,6 @@ set(couchbase_cxx_client_FILES
166174
core/impl/replica_utils.cxx
167175
core/impl/retry_action.cxx
168176
core/impl/retry_reason.cxx
169-
core/impl/public_scan_result.cxx
170177
core/impl/scope.cxx
171178
core/impl/search.cxx
172179
core/impl/search_error_category.cxx
@@ -206,13 +213,11 @@ set(couchbase_cxx_client_FILES
206213
core/impl/transaction_error_category.cxx
207214
core/impl/transaction_get_multi_replicas_from_preferred_server_group_spec.cxx
208215
core/impl/transaction_get_multi_spec.cxx
209-
core/impl/public_transaction_get_result.cxx
210216
core/impl/transaction_op_error_category.cxx
211217
core/impl/vector_query.cxx
212218
core/impl/vector_search.cxx
213219
core/impl/view_error_category.cxx
214220
core/impl/wildcard_query.cxx
215-
core/impl/crypto.cxx
216221
core/io/config_tracker.cxx
217222
core/io/dns_client.cxx
218223
core/io/dns_config.cxx
@@ -225,6 +230,7 @@ set(couchbase_cxx_client_FILES
225230
core/io/mcbp_session.cxx
226231
core/io/streams.cxx
227232
core/key_value_config.cxx
233+
core/log_entry.cxx
228234
core/logger/custom_rotating_file_sink.cxx
229235
core/logger/logger.cxx
230236
core/management/analytics_link_azure_blob_external.cxx
@@ -241,6 +247,7 @@ set(couchbase_cxx_client_FILES
241247
core/mcbp/queue_request.cxx
242248
core/mcbp/server_duration.cxx
243249
core/meta/version.cxx
250+
core/metric_measurement.cxx
244251
core/metrics/logging_meter.cxx
245252
core/metrics/meter_wrapper.cxx
246253
core/n1ql_query_options.cxx
@@ -339,6 +346,7 @@ set(couchbase_cxx_client_FILES
339346
core/operations/management/view_index_get_all.cxx
340347
core/operations/management/view_index_upsert.cxx
341348
core/origin.cxx
349+
core/orphan_reporter.cxx
342350
core/platform/base64.cc
343351
core/platform/dirutils.cc
344352
core/platform/random.cc
@@ -395,10 +403,10 @@ set(couchbase_cxx_client_FILES
395403
core/seed_config.cxx
396404
core/signal_bridge.cxx
397405
core/signal_data.cxx
398-
core/metric_measurement.cxx
399-
core/chrono_utils.cxx
400406
core/topology/capabilities.cxx
401407
core/topology/configuration.cxx
408+
core/trace_span.cxx
409+
core/tracing/file_tracer.cxx
402410
core/tracing/threshold_logging_tracer.cxx
403411
core/tracing/tracer_wrapper.cxx
404412
core/transactions/active_transaction_record.cxx
@@ -436,11 +444,6 @@ set(couchbase_cxx_client_FILES
436444
core/utils/url_codec.cxx
437445
core/view_query_options.cxx
438446
core/websocket_codec.cxx
439-
core/app_telemetry_address.cxx
440-
core/app_telemetry_meter.cxx
441-
core/app_telemetry_reporter.cxx
442-
core/cluster_credentials.cxx
443-
core/orphan_reporter.cxx
444447
)
445448

446449
set(couchbase_cxx_client_LIBRARIES)

core/log_entry.cxx

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2+
/*
3+
* Copyright 2025-Current Couchbase, Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include "log_entry.hxx"
19+
20+
#include <tao/json.hpp>
21+
#include <tao/json/contrib/traits.hpp>
22+
23+
namespace tao::json
24+
{
25+
template<>
26+
struct traits<couchbase::core::signal_attribute> {
27+
template<template<typename...> class Traits>
28+
static void assign(basic_value<Traits>& v, const couchbase::core::signal_attribute& attr)
29+
{
30+
v = {
31+
{ "name", attr.name },
32+
{ "value", attr.value },
33+
};
34+
}
35+
};
36+
37+
template<>
38+
struct traits<couchbase::core::log_entry> {
39+
template<template<typename...> class Traits>
40+
static void assign(basic_value<Traits>& v, const couchbase::core::log_entry& entry)
41+
{
42+
v = {
43+
{ "timestamp", entry.timestamp },
44+
{ "severity", entry.severity },
45+
{ "message", entry.message },
46+
{
47+
"context",
48+
{
49+
{ "trace_id", entry.context.trace_id },
50+
{ "span_id", entry.context.span_id },
51+
},
52+
},
53+
{ "attributes", entry.attributes },
54+
};
55+
}
56+
};
57+
} // namespace tao::json
58+
59+
namespace couchbase::core
60+
{
61+
62+
auto
63+
to_string(const log_entry& data) -> std::string
64+
{
65+
tao::json::value json = data;
66+
return tao::json::to_string(json);
67+
}
68+
} // namespace couchbase::core

core/log_entry.hxx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ struct log_entry {
3737
std::vector<signal_attribute> attributes{};
3838
};
3939

40+
auto
41+
to_string(const log_entry& data) -> std::string;
42+
4043
inline auto
4144
operator==(const log_entry& lhs, const log_entry& rhs) -> bool
4245
{

core/metric_measurement.cxx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,34 @@
1717

1818
#include "metric_measurement.hxx"
1919

20+
#include <tao/json.hpp>
21+
22+
namespace tao::json
23+
{
24+
template<>
25+
struct traits<couchbase::core::metric_measurement> {
26+
template<template<typename...> class Traits>
27+
static void assign(basic_value<Traits>& v, const couchbase::core::metric_measurement& measurement)
28+
{
29+
v = basic_value<Traits>::object({});
30+
v["name"] = measurement.name();
31+
32+
if (measurement.is_int64()) {
33+
v["value"] = measurement.as_int64();
34+
} else if (measurement.is_double()) {
35+
v["value"] = measurement.as_double();
36+
}
37+
}
38+
};
39+
} // namespace tao::json
40+
2041
namespace couchbase::core
2142
{
43+
[[nodiscard]] auto
44+
metric_measurement::name() const noexcept -> const std::string&
45+
{
46+
return name_;
47+
}
2248

2349
[[nodiscard]] auto
2450
metric_measurement::is_double() const noexcept -> bool
@@ -62,4 +88,10 @@ metric_measurement::try_as_int64() && -> std::optional<std::int64_t>
6288
return std::nullopt;
6389
}
6490

91+
auto
92+
to_string(const metric_measurement& data) -> std::string
93+
{
94+
tao::json::value json = data;
95+
return tao::json::to_string(json);
96+
}
6597
} // namespace couchbase::core

core/metric_measurement.hxx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ public:
5252
auto operator=(const metric_measurement&) -> metric_measurement& = default;
5353
auto operator=(metric_measurement&&) -> metric_measurement& = default;
5454

55+
[[nodiscard]] auto name() const noexcept -> const std::string&;
56+
5557
[[nodiscard]] auto is_double() const noexcept -> bool;
5658
[[nodiscard]] auto as_double() const -> double;
5759
[[nodiscard]] auto try_as_double() && -> std::optional<double>;
@@ -75,6 +77,9 @@ private:
7577
std::variant<double, std::int64_t> value_;
7678
};
7779

80+
auto
81+
to_string(const metric_measurement& data) -> std::string;
82+
7883
inline auto
7984
operator==(const metric_measurement& lhs, const metric_measurement& rhs) -> bool
8085
{

core/signal_data.cxx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,4 +154,18 @@ signal_data::try_as_log_entry() && -> std::optional<log_entry>
154154
}
155155
return std::nullopt;
156156
}
157+
158+
auto
159+
to_string(const signal_data& data) -> std::string
160+
{
161+
return std::visit(
162+
[](const auto& value) -> std::string {
163+
if constexpr (std::is_same_v<std::decay_t<decltype(value)>, std::monostate>) {
164+
return "{}";
165+
} else {
166+
return to_string(value);
167+
}
168+
},
169+
data.record_);
170+
};
157171
} // namespace couchbase::core

core/signal_data.hxx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,15 @@ public:
8888
}
8989

9090
friend auto operator==(const signal_data& lhs, const signal_data& rhs) -> bool;
91+
friend auto to_string(const signal_data& data) -> std::string;
9192

9293
private:
9394
std::variant<std::monostate, trace_span, metric_measurement, log_entry> record_{};
9495
};
9596

97+
auto
98+
to_string(const signal_data& data) -> std::string;
99+
96100
inline auto
97101
operator==(const signal_data& lhs, const signal_data& rhs) -> bool
98102
{

core/trace_span.cxx

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2+
/*
3+
* Copyright 2025-Current Couchbase, Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include "trace_span.hxx"
19+
20+
#include <tao/json.hpp>
21+
#include <tao/json/contrib/traits.hpp>
22+
23+
namespace tao::json
24+
{
25+
template<>
26+
struct traits<couchbase::core::signal_attribute> {
27+
template<template<typename...> class Traits>
28+
static void assign(basic_value<Traits>& v, const couchbase::core::signal_attribute& attr)
29+
{
30+
v = {
31+
{ "name", attr.name },
32+
{ "value", attr.value },
33+
};
34+
}
35+
};
36+
37+
template<>
38+
struct traits<couchbase::core::trace_event> {
39+
template<template<typename...> class Traits>
40+
static void assign(basic_value<Traits>& v, const couchbase::core::trace_event& event)
41+
{
42+
v = {
43+
{ "name", event.name },
44+
{ "timestamp", event.timestamp },
45+
{ "attributes", event.attributes },
46+
};
47+
}
48+
};
49+
50+
template<>
51+
struct traits<couchbase::core::trace_span> {
52+
template<template<typename...> class Traits>
53+
static void assign(basic_value<Traits>& v, const couchbase::core::trace_span& span)
54+
{
55+
v = {
56+
{ "name", span.name },
57+
{
58+
"context",
59+
{
60+
{ "trace_id", span.context.trace_id },
61+
{ "span_id", span.context.span_id },
62+
},
63+
},
64+
{ "parent_id", span.parent_id },
65+
{ "start_time", span.start_time },
66+
{ "end_time", span.end_time },
67+
{ "attributes", span.attributes },
68+
{ "events", span.events },
69+
};
70+
}
71+
};
72+
} // namespace tao::json
73+
74+
namespace couchbase::core
75+
{
76+
77+
auto
78+
to_string(const trace_span& data) -> std::string
79+
{
80+
tao::json::value json = data;
81+
return tao::json::to_string(json);
82+
}
83+
} // namespace couchbase::core

0 commit comments

Comments
 (0)