Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/deps/couchbase-cxx-client
49 changes: 37 additions & 12 deletions src/wrapper/connection_handle.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include <core/operations/management/search.hxx>
#include <core/operations/management/user.hxx>
#include <core/operations/management/view.hxx>
#include <core/tracing/constants.hxx>
#include <core/tracing/wrapper_sdk_tracer.hxx>
#include <core/utils/connection_string.hxx>
#include <core/utils/json.hxx>
Expand Down Expand Up @@ -918,36 +919,60 @@ connection_handle::cluster_labels(zval* return_value)
namespace
{
auto
zval_to_value_recorder_tags(const zval* tags) -> std::map<std::string, std::string>
zval_to_metric_attributes(const zval* tags) -> core::metrics::metric_attributes
{
std::map<std::string, std::string> result{};
namespace attributes = core::tracing::attributes;

core::metrics::metric_attributes attrs{};
if (tags == nullptr || Z_TYPE_P(tags) != IS_ARRAY) {
return result;
return attrs;
}
const zend_string* key = nullptr;
const zval* value = nullptr;

ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(tags), key, value)
{
if (Z_TYPE_P(value) == IS_STRING) {
result[cb_string_new(key)] = cb_string_new(Z_STR_P(value));
}
// We ignore other types. We can't forward them to the C++ SDK's meter.
// This is not an issue at present, as this is only used for the LoggingMeter, which only needs
// the service and operation name tags, which are both strings.
if (key == nullptr || Z_TYPE_P(value) != IS_STRING) {
// We ignore other types. We can't forward them to the C++ SDK's meter.
// This is not an issue at present, as this is only used for the LoggingMeter, which only needs
// the service and operation name tags, which are both strings.
continue;
}
auto name = cb_string_new(key);
auto text = cb_string_new(Z_STR_P(value));
if (name == attributes::op::service) {
attrs.service = std::move(text);
} else if (name == attributes::op::operation_name) {
attrs.operation = std::move(text);
} else if (name == attributes::op::bucket_name) {
attrs.bucket_name = std::move(text);
} else if (name == attributes::op::scope_name) {
attrs.scope_name = std::move(text);
} else if (name == attributes::op::collection_name) {
attrs.collection_name = std::move(text);
} else if (name == attributes::op::error_type) {
attrs.error_type = std::move(text);
} else if (name == attributes::common::cluster_name) {
attrs.internal.cluster_name = std::move(text);
} else if (name == attributes::common::cluster_uuid) {
attrs.internal.cluster_uuid = std::move(text);
}
// Other tags (e.g. the reserved unit and system name) are fixed by
// metric_attributes::encode() and don't need to be forwarded.
}
ZEND_HASH_FOREACH_END();

return result;
return attrs;
}
} // namespace

COUCHBASE_API
void
connection_handle::record_core_meter_operation_duration(std::int64_t duration_us, zval* tags)
{
auto tag_map = zval_to_value_recorder_tags(tags);
impl_->core_api().meter()->record_value(tag_map, std::chrono::microseconds(duration_us));
auto attrs = zval_to_metric_attributes(tags);
impl_->core_api().meter()->record_value(
std::move(attrs), std::chrono::steady_clock::now() - std::chrono::microseconds(duration_us));
}

COUCHBASE_API
Expand Down
Loading