Skip to content

Conversation

@cy-yun cy-yun requested review from a team and yoshi-approver as code owners October 31, 2025 02:10
@cy-yun cy-yun force-pushed the pubsub-logging branch 2 times, most recently from 7c8937c to 2ead334 Compare November 3, 2025 21:01
@hongalex hongalex requested a review from feywind November 3, 2025 21:52
Copy link

@feywind feywind left a comment

Choose a reason for hiding this comment

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

Looks fine from a logging perspective, just wondering about the histogram class comment.

@cy-yun
Copy link
Contributor Author

cy-yun commented Nov 4, 2025

The acceptance tests pass locally. They can be flakey when running on Kokoro. Acceptance test failures are unrelated to my changes.

@cy-yun cy-yun force-pushed the pubsub-logging branch 4 times, most recently from f36a306 to 4ebacf2 Compare November 12, 2025 23:37
@cy-yun cy-yun requested review from aandreassa and feywind November 13, 2025 20:11
@cy-yun cy-yun force-pushed the pubsub-logging branch 3 times, most recently from 039d065 to bdd5d68 Compare November 19, 2025 21:00
Copy link
Contributor

@aandreassa aandreassa left a comment

Choose a reason for hiding this comment

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

I had a change to look into this a bit more. I think the approach we want to take it is along the lines of:

  1. Allow configuration of logger in lib/google/cloud/pubsub.rb. I was thinking something like here, with 3 options.
  2. Once we have it there, we can pass it to Service to use downstream.
  3. Logs should happen via Message from google-logging-utils:
@logger&.info do
    # This block is only executed if INFO level is enabled, making it efficient.
    Google::Logging::Message.new(....)
  end

This logic should be able to handle instances of a default Ruby logger (e.g. stdin/out) or Google::Logging::StructuredFormatter, which you can use for testing.

@cy-yun
Copy link
Contributor Author

cy-yun commented Dec 2, 2025

I had a change to look into this a bit more. I think the approach we want to take it is along the lines of:

  1. Allow configuration of logger in lib/google/cloud/pubsub.rb. I was thinking something like here, with 3 options.
  2. Once we have it there, we can pass it to Service to use downstream.
  3. Logs should happen via Message from google-logging-utils:
@logger&.info do
    # This block is only executed if INFO level is enabled, making it efficient.
    Google::Logging::Message.new(....)
  end

This logic should be able to handle instances of a default Ruby logger (e.g. stdin/out) or Google::Logging::StructuredFormatter, which you can use for testing.

HI @aandreassa . Thanks for your feedback.

  1. The logger is configurable. README instructs how.

You can programmatically configure a custom logger:

require "google/cloud/pubsub"
require "logger"

# Configure a logger for the pubsub library
Google::Cloud.configure.pubsub.logger = Logger.new "my-app.log"

If the custom logger is not configured, it will default to a standard stdout logger.

  1. Could you provide more clarity on what "Downstream" means here? Do you mean the GAPIC layer?

  2. I can investigate the Message class to understand how to make it work.

Talk tomorrow!

@cy-yun cy-yun force-pushed the pubsub-logging branch 2 times, most recently from 73e205a to 1990c5e Compare December 3, 2025 21:39
@cy-yun
Copy link
Contributor Author

cy-yun commented Dec 3, 2025

These two pull requests introduce a standardized and dynamically configurable debug logging framework for Google Cloud Ruby clients and implement it in the Pub/Sub library.

The primary goal was to enable on-demand debug logging that could be controlled by the developer via configuring a custom logger and controlling an environment variable to turn logs on/off. This required passing a logger from the handwritten client (google-cloud-pubsub) down to the underlying GAPIC client (google-cloud-pubsub-v1). I needed to build a wrapper around the logger (creating a logger duck-type) that will evaluate the environment variable before emitting logs.

The Solution:

  • https://github.com/googleapis/ruby-core-libraries/pull/49/files creates the core component, GoogleSdkLoggerDelegator in google-logging-util gem. This class acts as a "duck-type" for a standard Ruby logger. Its key function is to wrap a real logger and check the GOOGLE_SDK_RUBY_LOGGING_GEMS environment variable before passing a log message through. If the variable isn't set for the specific gem, the delegator simply does nothing. This provides a reusable, centralized way to control logging across all Google Cloud Ruby libraries.

  • https://github.com/googleapis/google-cloud-ruby/pull/32136/files implements this framework in the Pub/Sub library. It modifies the handwritten google-cloud-pubsub client to accept a logger, wraps it with the GoogleSdkLoggerDelegator, and emits debug logs requested by the Pub/Sub team. It also includes an .owlbot.rb file which will trigger a post-processing code change in the GAPIC-layer which will allow the GAPIC clients to accept both Logger type and GoogleSdkLoggerDelegator type. The github workflows are failing because I set the version of google-logging-util gem to currently-non-existent, future version, 0.3.0 . The current latest version of google-logging-util gem is 0.2.0 . The version with the release of GoogleSdkLoggerDelegator would be 0.3.0 (correct me if I'm wrong).

Once the first 2 PRs are approved, I will create a new PR that passes the GoogleSdkLoggerDelegator down to the GAPIC layer (google-cloud-pubsub-v1).

@cy-yun cy-yun requested a review from aandreassa December 17, 2025 21:32
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.

5 participants