PCBC-1039: Add LoggingMeter implementation#246
PCBC-1039: Add LoggingMeter implementation#246DemetrisChr wants to merge 1 commit intocouchbase:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a PHP LoggingMeter implementation and wires it to the C++ core meter via new PHP/C++ bindings so the SDK can default to logging-based metrics when no external meter is configured.
Changes:
- Implement
LoggingMeter/LoggingValueRecorderin PHP and default to it when no meter is provided. - Add a new PHP extension binding
coreMeterRecordOperationDurationand plumb it throughconnection_handle. - Update the embedded C++ client submodule to include the underlying meter support.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/wrapper/core_span_resource.cxx | Minor cleanup of span resource implementation/includes. |
| src/wrapper/connection_handle.hxx | Exposes a new method to record operation duration into the core meter. |
| src/wrapper/connection_handle.cxx | Implements PHP-array-to-tag-map conversion and forwards duration to the core meter wrapper. |
| src/php_couchbase.cxx | Adds the new PHP function + arginfo and registers it. |
| src/deps/couchbase-cxx-client | Updates C++ core dependency to a revision that supports meter wrapper usage. |
| Couchbase/LoggingValueRecorder.php | Implements a PHP ValueRecorder that calls into the extension binding. |
| Couchbase/LoggingMeter.php | Implements the PHP Meter that returns either a logging recorder or a noop recorder. |
| Couchbase/ClusterOptions.php | Changes meter retrieval to return nullable to enable defaulting to LoggingMeter. |
| Couchbase/Cluster.php | Defaults to LoggingMeter when user didn’t configure a meter. |
Comments suppressed due to low confidence (3)
src/wrapper/connection_handle.hxx:119
tagsis only read/converted and not mutated; consider takingconst zval* tagshere (and in the.cxx) to better document intent and prevent accidental modification.
COUCHBASE_API
void record_core_meter_operation_duration(std::int64_t duration_us, zval* tags);
Couchbase/LoggingMeter.php:45
- With
strict_types=1, prefer!==for string comparisons to avoid unintended type coercion ($name !== ...). Also, explicitly declare method visibility (public function close(): void) for consistency and clarity.
if ($name != ObservabilityConstants::METER_NAME_OPERATION_DURATION) {
// The logging meter only uses the db.client.operation.duration metric
return new NoopValueRecorder();
}
Couchbase/LoggingMeter.php:51
- With
strict_types=1, prefer!==for string comparisons to avoid unintended type coercion ($name !== ...). Also, explicitly declare method visibility (public function close(): void) for consistency and clarity.
function close(): void
{
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
47b1c9b to
b0de5bd
Compare
Couchbase/ClusterOptions.php
Outdated
| if (is_null($options) || is_null($options->meter)) { | ||
| return null; |
There was a problem hiding this comment.
nitpick, but I think second is_null is not necessary, the caller expects null and the signature is ?Meter.
We should either create new LoggingMeter here or just let it to return null.
| if (is_null($options) || is_null($options->meter)) { | |
| return null; | |
| if (is_null($options)) { | |
| return null; |
There was a problem hiding this comment.
Yes, that is_null is not necessary. I've updated this.
| 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. |
There was a problem hiding this comment.
But maybe it will make sense to emit some warning or stringify them?
I am okay if we will just ignore them, but add API reference note about that to Couchbase/LoggingMeter.php
public function valueRecorder(string $name, array $tags): ValueRecorderThere was a problem hiding this comment.
The LoggingMeter ignores all attributes except db.operation.name and couchbase.service, both of which are strings. So I think in a way this is an implementation detail. I don't think it would be necessary to mention this in the API docs. But I will add a comment in the bindings to point this out.
b0de5bd to
0e3a848
Compare
Motivation
When no external meter is configured, the SDK must default to the LoggingMeter. Now that metrics are created on the PHP-side, we need to implement the LoggingMeter PHP class.
Changes
coreMeterRecordOperationDurationin the C++ bindings.recordValueis called in theLoggingValueRecorderthe metric is recorded to the core's logging meter via the C++ core API.