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

Only run fixTwitterEmbeds if conditions are met #330

Merged
merged 3 commits into from
Dec 4, 2024

Conversation

zuuring
Copy link
Member

@zuuring zuuring commented Nov 26, 2024

Notes

This resolves an issue where Valkyrie was posting INFO fixTwitterEmbeds for every message whether it matches the regex pattern or not. Now we only run the twitter embed if it matches.

### Notes
This resolves an issue where Valkyrie was posting `INFO fixTwitterEmbeds` for every message whether it matches the regex pattern or not. Now we only run the twitter embed if it matches.
`fixTwitterEmbeds: failed to process new message ${message.content}: ${err}`,
if (message.content?.match(twitterUrlRegExp)) {
robot.logger.info(
`fixTwitterEmbeds: processing new message ${message.content}`,
Copy link
Contributor

Choose a reason for hiding this comment

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

We should also probably never log message content unless we're debugging.

Instead, let's log the channel, from user, and timestamp.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also we should maybe still always log that we're processing every message, but at the debug level, and making sure that production isn't set to show debug level logs...

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds good and should I also look through other helpers and move any logger.info over to logger.debug when we want to separate that? On a case-by-case basis ofc!

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, def makes sense to adjust log level.

What we need to peek at is what changes we might need to make so that debug shows on local testing instances but not on production instances.

Copy link
Member Author

Choose a reason for hiding this comment

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

I ended up adding robot.logger.debug to the mix so that we only log those if this flag is set export HUBOT_LOG_LEVEL="debug" which is nicely already built into Hubot! This is probably a good time to start moving other scripts over to the debug level as well. 🥲

Copy link
Contributor

Choose a reason for hiding this comment

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

We still need to not log message content on info level though. I think we want to:

  • Change this log to only log channel, from, and timestamp.
  • Maybe, add a debug log that logs the message content.

@zuuring zuuring requested a review from Shadowfiend November 29, 2024 09:05
Copy link
Contributor

@Shadowfiend Shadowfiend left a comment

Choose a reason for hiding this comment

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

Few more notes here.

oldMessage?.content?.match(twitterUrlRegExp)
) {
robot.logger.info(
`fixTwitterEmbeds: processing updated message ${newMessage.content}`,
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like we now log this twice? And same note as above re: leaving message content out of the info level.

workingTwitterEmbeds(newMessage, robot.logger, oldMessage).catch(
(err) => {
robot.logger.error(
`fixTwitterEmbeds: failed to process updated message ${newMessage.content}: ${err}`,
Copy link
Contributor

Choose a reason for hiding this comment

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

Same deal re: message content.

Actually I would also log the message id at info level, and only log the message content once alongside message id. That way we don't need to repeatedly spit the message content into the console.

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 pushed a new commit with a bunch of refactoring as well hiding the whole content behind the logger.debug and then for logger.info we take user, channel, messageId and timestamp!

This changes the `fixTwitterEmbeds` to run a main `processTwitterMessage` where we output the specific user, channel, timestamp and message id to `logger.info` while outputting the entire message to `logger.debug`
)
}
}

discordClient.on("messageCreate", (message) => {
robot.logger.debug(
`fixTwitterEmbeds: processing new message ${message.content}`,
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's include the message id here so we can cross-correlate to the other logs.

Copy link
Contributor

@Shadowfiend Shadowfiend left a comment

Choose a reason for hiding this comment

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

Already an improvement, left a small note but let's ship it.

@Shadowfiend Shadowfiend merged commit b04ac65 into main Dec 4, 2024
7 checks passed
@Shadowfiend Shadowfiend deleted the fix-twitter-embed-checks branch December 4, 2024 21:02
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.

2 participants