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

Adding Debug Logs #1545

Merged
merged 1 commit into from
Nov 15, 2022
Merged

Adding Debug Logs #1545

merged 1 commit into from
Nov 15, 2022

Conversation

klenotiw
Copy link
Contributor

@klenotiw klenotiw commented Oct 21, 2022

What this PR does

This is intended to add logs to critical areas of the code to ease the pain of debugging.

closes https://github.com/Shopify/first-party-library-planning/issues/482

Reviewer's guide to testing

Read through all of the logs. If you are really cool you can test some logs out by using a testing app.

Things to focus on

  1. Does this PR follow our logging approach?
  2. Read logging messages to makes sure they sound clear and make sense.
  3. Should we add logs anywhere else?
  4. Do the logs fall in the correct level?

Checklist

Before submitting the PR, please consider if any of the following are needed:

  • Update CHANGELOG.md if the changes would impact users
  • Update README.md, if appropriate.
  • Update any relevant pages in /docs, if necessary
  • For security fixes, the Disclosure Policy must be followed.

@klenotiw

This comment was marked as resolved.

@klenotiw klenotiw marked this pull request as ready for review October 24, 2022 13:21
Copy link
Contributor

@nelsonwittwer nelsonwittwer left a comment

Choose a reason for hiding this comment

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

Looking good so far! Do you think you could include docs for configuring logging for our users who aren't familiar with how rails logging config works.

lib/shopify_app/controller_concerns/login_protection.rb Outdated Show resolved Hide resolved
lib/shopify_app/controller_concerns/login_protection.rb Outdated Show resolved Hide resolved
lib/shopify_app/managers/webhooks_manager.rb Outdated Show resolved Hide resolved
@klenotiw

This comment was marked as resolved.

@klenotiw

This comment was marked as resolved.

README.md Outdated Show resolved Hide resolved
docs/shopify_app/logging.md Outdated Show resolved Hide resolved
lib/shopify_app/utils.rb Outdated Show resolved Hide resolved
docs/shopify_app/logging.md Outdated Show resolved Hide resolved
lib/shopify_app/utils.rb Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
if embedded_param?
ShopifyApp::Utils::Logger.debug("Embedded param")
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we can give more context on this. What is an embedded param and how was it determined?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I think this is telling the session_controller if the app is embedded or not? At one point we wanted to log all of the conditionals in the authenticate method. Do you think we should just remove these logs?

redirect_for_embedded
else
start_oauth
end
elsif top_level?
ShopifyApp::Utils::Logger.debug("Top level redirect")
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not familiar with what a top level redirect is. If we are logging it, I'd love to give a clue as to why this is important.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this was suppose to help debug the redirect loops. I think the top level is the last redirect but I could be wrong. But we are already logging inside redirect_auth_to_top_level so I think we can just remove this? (and it looks like its in the wrong place)

docs/shopify_app/logging.md Outdated Show resolved Hide resolved
lib/shopify_app/controller_concerns/ensure_billing.rb Outdated Show resolved Hide resolved
lib/shopify_app/controller_concerns/login_protection.rb Outdated Show resolved Hide resolved
lib/shopify_app/session/session_repository.rb Outdated Show resolved Hide resolved
@andyw8
Copy link
Contributor

andyw8 commented Nov 8, 2022

@nelsonwittwer These are lots of good suggestions about what to log, but I wonder if we should try get a first iteration out and then refine it?

@andyw8
Copy link
Contributor

andyw8 commented Nov 8, 2022

Also, I wonder if we should make a 'quiet' release first, and enable it on some internal apps, before we publicize this in the README?

@@ -47,6 +47,7 @@ def before_setup
ShopifyApp::InMemorySessionStore.clear
ShopifyAppConfigurer.call
Rails.application.reload_routes!
ShopifyApp.configuration.log_level = :warn
Copy link
Contributor Author

@klenotiw klenotiw Nov 9, 2022

Choose a reason for hiding this comment

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

I had to set a log_level for our tests. I decided on warn instead of off because some tests are expecting to see some logs come through. All of those tests are rescued errors so I figured warn was the best level. LMK what you think

lib/shopify_app/logger.rb Outdated Show resolved Hide resolved
lib/shopify_app/logger.rb Outdated Show resolved Hide resolved
lib/shopify_app/logger.rb Outdated Show resolved Hide resolved
@andyw8
Copy link
Contributor

andyw8 commented Nov 9, 2022

We also need a CHANGELOG entry.


## Upgrading

Make sure to add the `config.log_level` setting to your configuration file so you can start changing the log level to your preference. If `log_level` isn't found if your configuration settings then it will default to the `:info` level.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also added this upgrading section. (wasn't sure if this is the best place)

Copy link
Collaborator

@teddyhwang teddyhwang left a comment

Choose a reason for hiding this comment

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

I'm not sure if it's necessary but it would be nice to have the same log language as we do across the libraries so that we can have the same tone and content

@@ -55,6 +56,7 @@ def has_active_payment?(session)
end

def has_subscription?(session)
ShopifyApp::Logger.debug("Checking if has subscription")
Copy link
Collaborator

Choose a reason for hiding this comment

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

checking if what has subscription?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe "Checking if session has subscription" would have better? Nelson wanted to have these logs here because has_active_payment? had a lot of conditionals.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think that's what is happening. Seeing the two lines below, I think we're making a API call using the session to check if the shop has a subscription (please validate though I'm only guessing)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah as far as I can tell thats whats happening, "Checking if shop has subscription" would probably be more clear.

lib/shopify_app/controller_concerns/login_protection.rb Outdated Show resolved Hide resolved
@@ -32,6 +35,7 @@ def activate_shopify_session
ShopifyAPI::Context.activate_session(current_shopify_session)
yield
ensure
ShopifyApp::Logger.debug("Deactivating Session")
Copy link
Collaborator

Choose a reason for hiding this comment

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

How come for some logs we capitalize each word like it's a title? Is this a format that we're doing in the node library as well /cc @paulomarg

Copy link
Contributor

Choose a reason for hiding this comment

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

No, we've used sentence case pretty much everywhere for node!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok just went through and tried to clean that up

lib/shopify_app/controller_concerns/login_protection.rb Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
app/controllers/shopify_app/callback_controller.rb Outdated Show resolved Hide resolved
if embedded_param?
ShopifyApp::Logger.debug("Embedded param")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we really need this level of detail? If so, I would change the messaging to something like

Suggested change
ShopifyApp::Logger.debug("Embedded param")
ShopifyApp::Logger.debug("Detected embedded parameter and redirecting to ____")

Copy link
Contributor Author

@klenotiw klenotiw Nov 14, 2022

Choose a reason for hiding this comment

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

I say we just remove this since we already have a log in redirect_for_embedded. I think the original idea was to separate out all of the conditionals in the authenticate method.

redirect_for_embedded
else
start_oauth
end
elsif top_level?
ShopifyApp::Logger.debug("Top level redirect")
Copy link
Collaborator

Choose a reason for hiding this comment

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

this log is not informative enough for me to understand what is happening

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These logs were just to break up the conditionals in the authenticate method but I guess we can just remove them?

@@ -55,6 +56,7 @@ def has_active_payment?(session)
end

def has_subscription?(session)
ShopifyApp::Logger.debug("Checking if has subscription")
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think that's what is happening. Seeing the two lines below, I think we're making a API call using the session to check if the shop has a subscription (please validate though I'm only guessing)

@@ -16,8 +16,11 @@ module LoginProtection
ACCESS_TOKEN_REQUIRED_HEADER = "X-Shopify-API-Request-Failure-Unauthorized"

def activate_shopify_session
ShopifyApp::Logger.debug("Activating Shopify session")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Some of these method names are not ideal. What does activate shopify session mean here? Feel free to be more descriptive with the log and not just take the method name because the method name may not be even the ideal name to begin with

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe moving that log down to line 35 would be better. From what I can tell it sets the active session in the context.

lib/shopify_app/controller_concerns/login_protection.rb Outdated Show resolved Hide resolved
lib/shopify_app/session/jwt.rb Outdated Show resolved Hide resolved
lib/shopify_app/session/session_repository.rb Outdated Show resolved Hide resolved
@klenotiw klenotiw requested a review from andyw8 November 15, 2022 15:41
@klenotiw
Copy link
Contributor Author

@nelsonwittwer and @andyw8 I think this is ready for another round of reviews. Sorry this is taking a minute, I really appreciate the help.

@klenotiw klenotiw merged commit f338d67 into main Nov 15, 2022
@klenotiw klenotiw deleted the klenotiw/add-log-levels branch November 15, 2022 20:44
@klenotiw klenotiw mentioned this pull request Nov 15, 2022
4 tasks
@shopify-shipit shopify-shipit bot temporarily deployed to rubygems December 9, 2022 17:09 Inactive
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.

None yet

5 participants