-
Notifications
You must be signed in to change notification settings - Fork 683
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
Adding Debug Logs #1545
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
There was a problem hiding this 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.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
app/controllers/shopify_app/extension_verification_controller.rb
Outdated
Show resolved
Hide resolved
if embedded_param? | ||
ShopifyApp::Utils::Logger.debug("Embedded param") |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
@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? |
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 |
There was a problem hiding this comment.
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
We also need a CHANGELOG entry. |
docs/shopify_app/logging.md
Outdated
|
||
## 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. |
There was a problem hiding this comment.
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)
There was a problem hiding this 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") |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
@@ -32,6 +35,7 @@ def activate_shopify_session | |||
ShopifyAPI::Context.activate_session(current_shopify_session) | |||
yield | |||
ensure | |||
ShopifyApp::Logger.debug("Deactivating Session") |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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
app/controllers/concerns/shopify_app/ensure_authenticated_links.rb
Outdated
Show resolved
Hide resolved
app/controllers/shopify_app/extension_verification_controller.rb
Outdated
Show resolved
Hide resolved
if embedded_param? | ||
ShopifyApp::Logger.debug("Embedded param") |
There was a problem hiding this comment.
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
ShopifyApp::Logger.debug("Embedded param") | |
ShopifyApp::Logger.debug("Detected embedded parameter and redirecting to ____") |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
@nelsonwittwer and @andyw8 I think this is ready for another round of reviews. Sorry this is taking a minute, I really appreciate the help. |
38976f2
to
92f127e
Compare
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
Checklist
Before submitting the PR, please consider if any of the following are needed:
CHANGELOG.md
if the changes would impact usersREADME.md
, if appropriate./docs
, if necessary