Skip to content

PCBC-1039: Add LoggingMeter implementation#246

Merged
DemetrisChr merged 1 commit intocouchbase:mainfrom
DemetrisChr:PCBC-1039-logging-meter
Mar 11, 2026
Merged

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

Conversation

@DemetrisChr
Copy link
Copy Markdown
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
Copy Markdown

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.

Comment thread src/wrapper/connection_handle.cxx
Comment thread src/php_couchbase.cxx
Comment thread src/php_couchbase.cxx Outdated
@DemetrisChr DemetrisChr force-pushed the PCBC-1039-logging-meter branch from 47b1c9b to b0de5bd Compare March 3, 2026 17:59
Comment thread Couchbase/ClusterOptions.php Outdated
Comment thread src/wrapper/connection_handle.cxx
avsej
avsej previously approved these changes Mar 3, 2026
@DemetrisChr DemetrisChr force-pushed the PCBC-1039-logging-meter branch from 0e3a848 to 71a3e58 Compare March 11, 2026 12:00
@DemetrisChr DemetrisChr merged commit 77e0d81 into couchbase:main Mar 11, 2026
272 of 273 checks passed
@DemetrisChr DemetrisChr deleted the PCBC-1039-logging-meter branch March 11, 2026 15:31
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.

4 participants