Skip to content

Commit 53d414f

Browse files
committed
apply opentelemetry logger to the library
1 parent 30e9c6b commit 53d414f

24 files changed

+1281
-835
lines changed

CMakeLists.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,6 @@ set(couchbase_cxx_client_FILES
406406
core/search_query_options.cxx
407407
core/seed_config.cxx
408408
core/topology/configuration.cxx
409-
core/tracing/otel_tracer.cxx
410409
core/tracing/threshold_logging_tracer.cxx
411410
core/tracing/tracer_wrapper.cxx
412411
core/transactions/active_transaction_record.cxx
@@ -494,6 +493,8 @@ if(WIN32 OR NOT COUCHBASE_CXX_CLIENT_BUILD_SHARED)
494493
set(COUCHBASE_CXX_CLIENT_VARIANT couchbase_cxx_client_static)
495494
endif()
496495

496+
add_subdirectory(observability)
497+
497498
foreach(TARGET ${couchbase_cxx_client_LIBRARIES})
498499
include(cmake/DetectStandardFilesystem.cmake)
499500
couchbase_cxx_check_filesystem(
@@ -535,9 +536,12 @@ foreach(TARGET ${couchbase_cxx_client_LIBRARIES})
535536
snappy
536537
jsonsl
537538
couchbase_backtrace
538-
opentelemetry_api
539539
hdr_histogram_static)
540540

541+
target_link_libraries(
542+
${TARGET}
543+
PUBLIC couchbase_observability)
544+
541545
if(WIN32)
542546
target_link_libraries(${TARGET} PRIVATE iphlpapi)
543547
endif()
@@ -588,7 +592,6 @@ endif()
588592

589593
option(COUCHBASE_CXX_CLIENT_BUILD_TOOLS "Build tools" ${COUCHBASE_CXX_CLIENT_MASTER_PROJECT})
590594
if(COUCHBASE_CXX_CLIENT_BUILD_TOOLS)
591-
add_subdirectory(observability)
592595
add_subdirectory(tools)
593596
endif()
594597

cmake/ThirdPartyDependencies.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ if(NOT TARGET opentelemetry_api)
5252
EXCLUDE_FROM_ALL ON
5353
OPTIONS
5454
"OPENTELEMETRY_INSTALL OFF"
55+
"WITH_ABI_VERSION_1 OFF"
56+
"WITH_ABI_VERSION_2 ON"
5557
"WITH_STL ON"
5658
"WITH_ABSEIL OFF"
5759
"WITH_OTLP_HTTP ON"

core/bucket.cxx

Lines changed: 154 additions & 99 deletions
Large diffs are not rendered by default.

core/io/mcbp_command.hxx

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,13 @@ struct mcbp_command : public std::enable_shared_from_this<mcbp_command<Manager,
8585
if (request.durability_level != durability_level::none &&
8686
timeout_ < durability_timeout_floor) {
8787
CB_LOG_DEBUG(
88-
R"(Timeout is too low for operation with durability, increasing to sensible value. timeout={}ms, floor={}ms, id="{}")",
89-
request.id,
90-
timeout_.count(),
91-
durability_timeout_floor.count(),
92-
id_);
88+
"timeout is too low for operation with durability, increasing to sensible value",
89+
opentelemetry::common::MakeAttributes({
90+
{ "document_id", fmt::format("{}", request.id) },
91+
{ "operation_id", id_ },
92+
{ "timeout", fmt::format("{}", timeout_) },
93+
{ "floor", fmt::format("{}", durability_timeout_floor) },
94+
}));
9395
timeout_ = durability_timeout_floor;
9496
}
9597
}
@@ -154,13 +156,14 @@ struct mcbp_command : public std::enable_shared_from_this<mcbp_command<Manager,
154156
if (ec == errc::common::unambiguous_timeout || ec == errc::common::ambiguous_timeout) {
155157
telemetry_recorder->update_counter(app_telemetry_counter::kv_r_timedout);
156158
auto time_left = deadline.expiry() - std::chrono::steady_clock::now();
157-
CB_LOG_TRACE(R"([{}] timeout operation id="{}", {}, key="{}", partition={}, time_left={})",
158-
session_ ? session_->log_prefix() : manager_->log_prefix(),
159-
id_,
160-
encoded_request_type::body_type::opcode,
161-
request.id,
162-
request.partition,
163-
time_left);
159+
CB_LOG_TRACE("timeout operation",
160+
opentelemetry::common::MakeAttributes({
161+
{ "log_prefix", session_ ? session_->log_prefix() : manager_->log_prefix() },
162+
{ "operation_id", id_ },
163+
{ "opcode", fmt::format("{}", encoded_request_type::body_type::opcode) },
164+
{ "partition", request.partition },
165+
{ "time_left", fmt::format("{}", time_left) },
166+
}));
164167
} else if (ec == errc::common::request_canceled) {
165168
telemetry_recorder->update_counter(app_telemetry_counter::kv_r_canceled);
166169
}
@@ -208,11 +211,13 @@ struct mcbp_command : public std::enable_shared_from_this<mcbp_command<Manager,
208211
{
209212
auto backoff = std::chrono::milliseconds(500);
210213
auto time_left = deadline.expiry() - std::chrono::steady_clock::now();
211-
CB_LOG_DEBUG(R"({} unknown collection response for "{}", time_left={}ms, id="{}")",
212-
session_->log_prefix(),
213-
request.id,
214-
std::chrono::duration_cast<std::chrono::milliseconds>(time_left).count(),
215-
id_);
214+
CB_LOG_DEBUG("unknown collection response",
215+
opentelemetry::common::MakeAttributes({
216+
{ "log_prefix", session_->log_prefix() },
217+
{ "document_id", fmt::format("{}", request.id) },
218+
{ "time_left", fmt::format("{}", time_left) },
219+
{ "operation_id", id_ },
220+
}));
216221
request.retries.add_reason(retry_reason::key_value_collection_outdated);
217222
if (time_left < backoff) {
218223
return invoke_handler(make_error_code(request.retries.idempotent()
@@ -241,12 +246,13 @@ struct mcbp_command : public std::enable_shared_from_this<mcbp_command<Manager,
241246
if (collection_id) {
242247
request.id.collection_uid(collection_id.value());
243248
} else {
244-
CB_LOG_DEBUG(
245-
R"({} no cache entry for collection, resolve collection id for "{}", timeout={}ms, id="{}")",
246-
session_->log_prefix(),
247-
request.id,
248-
timeout_.count(),
249-
id_);
249+
CB_LOG_DEBUG("no cache entry for collection, resolve collection id",
250+
opentelemetry::common::MakeAttributes({
251+
{ "log_prefix", session_->log_prefix() },
252+
{ "document_id", fmt::format("{}", request.id) },
253+
{ "timeout", fmt::format("{}", timeout_) },
254+
{ "operation_id", id_ },
255+
}));
250256
return request_collection_id();
251257
}
252258
} else {
@@ -347,13 +353,13 @@ struct mcbp_command : public std::enable_shared_from_this<mcbp_command<Manager,
347353
return self->handle_unknown_collection();
348354
}
349355
if (status == key_value_status_code::config_only) {
350-
CB_LOG_DEBUG("{} server returned status 0x{:02x} ({}) meaning that the node does not "
351-
"serve data operations, "
352-
"requesting new "
353-
"configuration and retrying",
354-
self->session_->log_prefix(),
355-
msg.header.status(),
356-
status);
356+
CB_LOG_DEBUG("server returned status {status} meaning that the node does not serve data "
357+
"operations, requesting new configuration and retrying",
358+
opentelemetry::common::MakeAttributes({
359+
{ "log_prefix", self->session_->log_prefix() },
360+
{ "status", fmt::format("0x{:02x}", msg.header.status()) },
361+
{ "status_text", fmt::format("{}", status) },
362+
}));
357363
self->manager_->fetch_config();
358364
return io::retry_orchestrator::maybe_retry(
359365
self->manager_, self, retry_reason::service_response_code_indicated, ec);

0 commit comments

Comments
 (0)