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.
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 {
AbhiPrasad
left a comment
There was a problem hiding this comment.
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.
| 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.
| 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.
We should short-circuit this if EnableLogs is set to false.
# Conflicts: # log.go # logrus/logrusentry.go
|
added test & README examples |
AbhiPrasad
left a comment
There was a problem hiding this comment.
nice, great work @giortzisg.
Description
Closes #1028.
Adding
logrusintegration, by introducinglogHook. Refactored and deprecated existing logic ofNewandNewFromClientfunctionality, separating them into two different constructors for events and logs. These areNewEventHookandNewLogHookmethods for creating hooks with a new Sentry client, and correspondingFromClientmethods for using an existing client. These replace the deprecatedNewandNewFromClientmethods. Example of logrus hook usage: