-
Notifications
You must be signed in to change notification settings - Fork 241
Add logrus logs integration #1036
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
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1036 +/- ##
==========================================
+ Coverage 85.63% 86.26% +0.63%
==========================================
Files 55 55
Lines 5526 5664 +138
==========================================
+ Hits 4732 4886 +154
+ Misses 651 637 -14
+ Partials 143 141 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Pull Request Overview
This PR adds Logrus logging integration with Sentry by refactoring the existing hook constructors and introducing a new logHook alongside the existing eventHook.
- Introduces separate constructors (NewEventHook and NewLogHook) and corresponding FromClient methods.
- Refactors and deprecates the old New and NewFromClient methods.
- Adds a new logHook implementation to handle logs with Sentry's logger integration.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
File | Description |
---|---|
logrus/logrusentry.go | Refactored hooks into eventHook and introduced logHook for logs. |
logrus/go.mod | Added new test and indirect dependencies. |
log.go | Updated sentryLogger to add a default "sentry.origin" attribute. |
Comments suppressed due to low confidence (2)
log.go:147
- There is an inconsistency between the default 'sentry.origin' attribute values in log.go ('auto.logger.log') and in logrusentry.go (set as 'auto.logger.logrus'). Consider reconciling these values to ensure consistent tagging across logging outputs.
if _, ok := attrs["sentry.origin"]; !ok {
logrus/logrusentry.go:237
- A new logHook implementation has been introduced. Please ensure that comprehensive unit tests are added to cover its behavior, including log level handling and data type conversions.
type logHook struct {
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.
Can we add a test that shows that both log and event hooks can coexist together?
We also need to update the README.
logrus/logrusentry.go
Outdated
// Handle request field | ||
key := h.key(FieldRequest) | ||
if req, ok := entry.Data[key].(*http.Request); ok { | ||
h.logger.SetAttributes(attribute.String("http.method", req.Method)) |
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.
h.logger.SetAttributes(attribute.String("http.method", req.Method)) | |
h.logger.SetAttributes(attribute.String("http.request.method", req.Method)) |
logrus/logrusentry.go
Outdated
key := h.key(FieldRequest) | ||
if req, ok := entry.Data[key].(*http.Request); ok { | ||
h.logger.SetAttributes(attribute.String("http.method", req.Method)) | ||
h.logger.SetAttributes(attribute.String("http.url", req.URL.String())) |
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.
h.logger.SetAttributes(attribute.String("http.url", req.URL.String())) | |
h.logger.SetAttributes(attribute.String("url.full", req.URL.String())) |
if err != nil { | ||
return nil, err | ||
} | ||
|
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.
We should short-circuit this if EnableLogs
is set to false
.
# Conflicts: # log.go # logrus/logrusentry.go
added test & README examples |
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.
nice, great work @giortzisg.
Description
Closes #1028.
Adding
logrus
integration, by introducinglogHook
. Refactored and deprecated existing logic ofNew
andNewFromClient
functionality, separating them into two different constructors for events and logs. These areNewEventHook
andNewLogHook
methods for creating hooks with a new Sentry client, and correspondingFromClient
methods for using an existing client. These replace the deprecatedNew
andNewFromClient
methods. Example of logrus hook usage: