Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving the readability of the Ruby logs. #498

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
UPCOMING
--------
- Improved the logging format to include more information and increase human readability.

30.0.0
------
- Compatibility with v17.1 of the API: https://developers.google.com/google-ads/api/docs/release-notes
Expand Down
20 changes: 12 additions & 8 deletions lib/google/ads/google_ads/interceptors/logging_interceptor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ def request_response(request:, call:, method:, metadata: {})
response = yield

@logger.info { build_summary_message(request, call, method, false) }
@logger.debug { build_request_message(metadata, request) }
@logger.debug { build_request_message(request, call, method, metadata) }
@logger.debug { build_success_response_message(response) }
if response.respond_to?(:partial_failure_error) && response.partial_failure_error
@logger.debug { build_partial_failure_message(response) }
end
response
rescue Exception
@logger.warn { build_summary_message(request, call, method, true) }
@logger.info { build_request_message(metadata, request) }
@logger.info { build_request_message(request, call, method, metadata) }
@logger.info { build_error_response_message }
raise
end
Expand All @@ -77,7 +77,7 @@ def server_streamer(request:, call:, method:, metadata: {})
responses = yield
Enumerator.new do |y|
responses.each { |response|
@logger.debug { build_request_message(metadata, request) }
@logger.debug { build_request_message(request, call, method, metadata) }
@logger.debug { build_success_response_message(response) }
if response.respond_to?(:partial_failure_error) && response.partial_failure_error
@logger.debug { build_partial_failure_message(response) }
Expand All @@ -103,7 +103,7 @@ def server_streamer(request:, call:, method:, metadata: {})

def handle_error(request, call, method, metadata)
@logger.warn { build_summary_message(request, call, method, true) }
@logger.info { build_request_message(metadata, request) }
@logger.info { build_request_message(request, call, method, metadata) }
@logger.info { build_error_response_message }
raise
end
Expand Down Expand Up @@ -155,10 +155,11 @@ def error_details(exception)
end

def build_success_response_message(response)
"Incoming response: Payload: #{sanitize_message(response).to_json}"
"\nResponse\n--------\n" \
"Response: #{sanitize_message(response).to_json}"
end

def build_request_message(metadata, request)
def build_request_message(request, call, method, metadata)
# calling #to_json on some protos (specifically those with non-UTF8
# encodable byte values) causes a segfault, however #inspect works
# so we check if the proto contains a bytevalue, and if it does
Expand All @@ -168,8 +169,11 @@ def build_request_message(metadata, request)
else
sanitize_message(request).to_json
end
"Outgoing request: Headers: #{sanitize_headers(metadata).to_json} " \
"Payload: #{request_inspect}"
"\nRequest\n-------\n" \
"Method: #{method}\n" \
"Host: #{call.instance_variable_get(:@wrapped).instance_variable_get(:@peer)}\n" \
"Headers: #{sanitize_headers(metadata).to_json}\n" \
"Request: #{request_inspect}"
end

def sanitize_headers(metadata)
Expand Down