Skip to content

PCBC-1039: Add LoggingMeter implementation#246

Open
DemetrisChr wants to merge 1 commit intocouchbase:mainfrom
DemetrisChr:PCBC-1039-logging-meter
Open

PCBC-1039: Add LoggingMeter implementation#246
DemetrisChr wants to merge 1 commit intocouchbase:mainfrom
DemetrisChr:PCBC-1039-logging-meter

Conversation

@DemetrisChr
Copy link
Contributor

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

  • Implement the LoggingMeter. It acts as a wrapper over the C++ core's meter.
  • Add coreMeterRecordOperationDuration in the C++ bindings.
  • When recordValue is called in the LoggingValueRecorder the metric is recorded to the core's logging meter via the C++ core API.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 / LoggingValueRecorder in PHP and default to it when no meter is provided.
  • Add a new PHP extension binding coreMeterRecordOperationDuration and plumb it through connection_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

  • tags is only read/converted and not mutated; consider taking const zval* tags here (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.

@DemetrisChr DemetrisChr force-pushed the PCBC-1039-logging-meter branch from 47b1c9b to b0de5bd Compare March 3, 2026 17:59
Comment on lines +707 to +708
if (is_null($options) || is_null($options->meter)) {
return null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
if (is_null($options) || is_null($options->meter)) {
return null;
if (is_null($options)) {
return null;

Copy link
Contributor Author

@DemetrisChr DemetrisChr Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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): ValueRecorder

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

avsej
avsej previously approved these changes Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants