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

Apex log integration(Initial commit) #220

Merged
merged 1 commit into from
Nov 30, 2021
Merged

Conversation

chimanjain
Copy link
Contributor

No description provided.

@chimanjain chimanjain requested a review from kyrylo November 25, 2021 12:46
@chimanjain chimanjain closed this Nov 25, 2021
@chimanjain chimanjain deleted the apex-log-integration branch November 25, 2021 12:47
@chimanjain chimanjain restored the apex-log-integration branch November 25, 2021 12:57
@chimanjain chimanjain reopened this Nov 25, 2021
apexlog/apexlog.go Outdated Show resolved Hide resolved
apexlog/apexlog.go Outdated Show resolved Hide resolved
apexlog/apexlog.go Outdated Show resolved Hide resolved
//
// Valid names are "debug" "info", "warning", "error", and "fatal". If the name is not
// recognized, "error" severity is used.
func setGobrakeSeverity(severity string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This name is misleading because it doesn't actually set Gobrake's severity (the library, or the notifier). It just sets state in our handler.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed the name.


msg := fmt.Sprint(args...)

var theErr error
Copy link
Contributor

Choose a reason for hiding this comment

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

I have never seen this name being used in Go. Can we use the standard name err instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

} else {
notice = Gobrake.Notice(msg, req, depth)
}
notice.Context["severity"] = severityName[s]
Copy link
Contributor

Choose a reason for hiding this comment

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

If s implemented String(), we could call:

Suggested change
notice.Context["severity"] = severityName[s]
notice.Context["severity"] = s.String()

}

var notice *gobrake.Notice
if theErr != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since you use if else ... you can flip the branches so that we don't negate without a good reason. It's just easier to read if this... then that vs if not this... then that.

apexlog/apexlog.go Outdated Show resolved Hide resolved
}
}()

select {}
Copy link
Contributor

Choose a reason for hiding this comment

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

This example looks rather complex IMO. What we could do is to:

  1. Set severity to warning
  2. Send a debug log and explain it won't be delivered
  3. Send a fatal log and explain that it will be delivered
  4. Set severity to debug
  5. Send a debug log and explain that it will be delivered

No need for goroutines.

func New(notifier *gobrake.Notifier, severity string) *Handler {
setGobrakeSeverity(severity)
var v Handler
Gobrake = notifier
Copy link
Contributor

Choose a reason for hiding this comment

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

What will happen if two projects use this apexlog integration? Probably only one integration will win and the other one will stop sending logs. Can we make sure we support this scenario?

I am actually not sure why we store notifier on package-level. We store it on the handler itself on the next line, so why not to use it from there?

)

func main() {
// Initialize the airbrake notifier
Copy link
Contributor

Choose a reason for hiding this comment

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

This is still present.

// Insert the airbrake notifier instance and set the severity level.
// The acceptable severity levels are "debug" "info", "warning", "error", and "fatal".
// If the severity level is not recognized, "error" severity is used.
airbrakeHandler := apexlog.New(airbrake, "error")
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 pass a string instead of severity.

apexlog/apexlog.go Outdated Show resolved Hide resolved
apexlog/apexlog.go Outdated Show resolved Hide resolved

// HandleLog method is used for sending notices to airbrake.
func (h *Handler) HandleLog(e *log.Entry) error {
h.notifyAirbrake(0, severity(e.Level), e.Message)
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't need to have 0 (depth) as a function parameter because it never changes. Let's just remove it and hardcode it to 0 on line 93.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's just a variable, so that we can build on it in future if we want to or if we want to add some another variable and need some reference.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you provide an example of a possible scenario in the future where we want to pass anything other than 0 here?

"user": "tobi",
})

for range time.Tick(time.Millisecond * 500) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need a timer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This example is use used for the apex/log package(the one they used in their package), so we can show that the middleware will work without making any modifications to apex/log and it will be easier for developers to understand who are using apex/log already.

Copy link
Contributor

Choose a reason for hiding this comment

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

I gave this a run locally and I sent 160 errors to Airbrake within ~15 seconds. I don't think it's a good idea to run this on a loop because our users can leave this running for some time and then they will run out of their error quota or will have to pay more than needed.

I think we need to print these messages without a loop and make the program exit by itself so that we won't waste error quota.

examples/apexlog/main.go Show resolved Hide resolved
@kyrylo
Copy link
Contributor

kyrylo commented Nov 29, 2021

Is this ready for another review?

@chimanjain
Copy link
Contributor Author

Yes

@kyrylo
Copy link
Contributor

kyrylo commented Nov 29, 2021

Ok, thanks. Please write "PTAL" once you are done with the code. This will help me understand the state of the PR 🙂

"user": "tobi",
})

for range time.Tick(time.Millisecond * 500) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I gave this a run locally and I sent 160 errors to Airbrake within ~15 seconds. I don't think it's a good idea to run this on a loop because our users can leave this running for some time and then they will run out of their error quota or will have to pay more than needed.

I think we need to print these messages without a loop and make the program exit by itself so that we won't waste error quota.

"user": "tobi",
})

fmt.Println("Check your Airbrake dashboard at https://airbrake.io/projects/:ProjectId to see these log messages")
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 print the real project id being used so that users can actually click on the link
  • It would be nice to explain that some of the log messages won't be delivered to Airbrake due to severity settings. As of now this message implies all of the messages will be delivered, which isn't actually the case

InfoLog: "info",
WarnLog: "warn",
ErrorLog: "error",
FatalLog: "fatal",
Copy link
Contributor

Choose a reason for hiding this comment

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

When I send ctx.Fatal("oops"), it exits the program but never reports anything to Airbrake.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The apex/log package exits the application internally denying us to log it in airbrake

Copy link
Contributor

Choose a reason for hiding this comment

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

If we cannot support this, we shouldn't be exposing this severity in our integration because it doesn't do anything useful. In doing so, we should probably document this behavior. If I set up FataLog severity, nothing at all would be sent to Airbrake, which is misleading (I would think that only fatal logs would be sent).

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, I will remove that.

@chimanjain
Copy link
Contributor Author

PTAL

@kyrylo
Copy link
Contributor

kyrylo commented Nov 29, 2021

Did you see these comments?

They don't appear to be resolved.

@chimanjain chimanjain requested a review from kyrylo November 30, 2021 11:28
@chimanjain
Copy link
Contributor Author

PTAL

@chimanjain chimanjain merged commit ade184b into master Nov 30, 2021
@chimanjain chimanjain deleted the apex-log-integration branch November 30, 2021 12:58
@chimanjain chimanjain restored the apex-log-integration branch December 1, 2021 11:47
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