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

Improve debug-level logging in InstallProvider#handleInstallPath() #1451

Merged
merged 2 commits into from Mar 28, 2022

Conversation

seratch
Copy link
Member

@seratch seratch commented Mar 26, 2022

Summary

This pull request improves a debug-level logging in InstallProvider#handleInstallPath() method. We can release a patch version including this improvement.

Requirements (place an x in each [ ])

@seratch seratch added bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented pkg:oauth applies to `@slack/oauth-helper` labels Mar 26, 2022
@seratch seratch requested review from filmaj and srajiang March 26, 2022 06:15
@seratch seratch self-assigned this Mar 26, 2022
@seratch seratch added this to the oauth@2.5.1 milestone Mar 26, 2022
} catch(error) {
console.log(error)
}
await installer.handleInstallPath(req, res, {}, {
Copy link
Member Author

Choose a reason for hiding this comment

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

Updated the example app for verifying the behavior.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch!

@@ -330,7 +330,10 @@ export class InstallProvider {
}
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const _installOptions: InstallURLOptions = installOptions! || this.installUrlOptions!;
this.logger.debug(`Running handleInstallPath() with ${_installOptions}`);
if (this.logger.getLevel() <= LogLevel.DEBUG) {
const _printableOptions = JSON.stringify(_installOptions);
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the essential change in this PR

userScopes: ['chat:write'],
metadata: 'meta',
};
assert.deepEqual(JSON.stringify(options), '{"teamId":"T111","redirectUri":"https://www.example.com/slack/oauth_redirect","scopes":["commands","chat:write"],"userScopes":["chat:write"],"metadata":"meta"}');
Copy link
Member Author

Choose a reason for hiding this comment

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

just in case, added a simple test to make sure if the object does not have any issues with JSON.stringify

Copy link
Contributor

@filmaj filmaj left a comment

Choose a reason for hiding this comment

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

I left a tiny suggestion / optimization.

} catch(error) {
console.log(error)
}
await installer.handleInstallPath(req, res, {}, {
Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch!

@@ -330,7 +330,10 @@ export class InstallProvider {
}
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const _installOptions: InstallURLOptions = installOptions! || this.installUrlOptions!;
this.logger.debug(`Running handleInstallPath() with ${_installOptions}`);
if (this.logger.getLevel() <= LogLevel.DEBUG) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need this conditional here. The Logger class has this check built-in already. I think we can remove the if.

Copy link
Member Author

Choose a reason for hiding this comment

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

@filmaj I've added this if condition to avoid the cost to run JSON.stringify when the logging level INFO or above. That being said, we may want to simplify the logic rather than the slight efficiency improvement.

Copy link
Member Author

Choose a reason for hiding this comment

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

this is an ignorable cost. removed the if condition

Copy link
Member

@mwbrooks mwbrooks left a comment

Choose a reason for hiding this comment

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

LGTM and looks like Kaz addressed the earlier feedback!

@seratch seratch merged commit 24eab98 into slackapi:main Mar 28, 2022
@seratch seratch deleted the oauth-debug-log branch March 28, 2022 22:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented pkg:oauth applies to `@slack/oauth-helper`
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants