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

Add logger name to logrus integration #866

Merged
merged 2 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions logrus/logrusentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

// The identifier of the Logrus SDK.
const sdkIdentifier = "sentry.go.logrus"
const name = "logrus"

// These default log field keys are used to pass specific metadata in a way that
// Sentry understands. If they are found in the log fields, and the value is of
Expand Down Expand Up @@ -153,6 +154,7 @@ func (h *Hook) entryToEvent(l *logrus.Entry) *sentry.Event {
Extra: data,
Message: l.Message,
Timestamp: l.Time,
Logger: name,
}
key := h.key(FieldRequest)
if req, ok := s.Extra[key].(*http.Request); ok {
Expand Down
24 changes: 18 additions & 6 deletions logrus/logrusentry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ func Test_entryToEvent(t *testing.T) {
"empty entry": {
entry: &logrus.Entry{},
want: &sentry.Event{
Level: "fatal",
Extra: map[string]any{},
Level: "fatal",
Extra: map[string]any{},
Logger: "logrus",
},
},
"data fields": {
Expand All @@ -85,17 +86,19 @@ func Test_entryToEvent(t *testing.T) {
},
},
want: &sentry.Event{
Level: "fatal",
Extra: map[string]any{"bar": "oink", "foo": 123.4},
Level: "fatal",
Extra: map[string]any{"bar": "oink", "foo": 123.4},
Logger: "logrus",
},
},
"info level": {
entry: &logrus.Entry{
Level: logrus.InfoLevel,
},
want: &sentry.Event{
Level: "info",
Extra: map[string]any{},
Level: "info",
Extra: map[string]any{},
Logger: "logrus",
},
},
"message": {
Expand All @@ -106,6 +109,7 @@ func Test_entryToEvent(t *testing.T) {
Level: "fatal",
Extra: map[string]any{},
Message: "the only thing we have to fear is fear itself",
Logger: "logrus",
},
},
"timestamp": {
Expand All @@ -116,6 +120,7 @@ func Test_entryToEvent(t *testing.T) {
Level: "fatal",
Extra: map[string]any{},
Timestamp: time.Unix(1, 2).UTC(),
Logger: "logrus",
},
},
"http request": {
Expand All @@ -132,6 +137,7 @@ func Test_entryToEvent(t *testing.T) {
Method: http.MethodGet,
Headers: map[string]string{"Host": "example.com"},
},
Logger: "logrus",
},
},
"error": {
Expand All @@ -146,6 +152,7 @@ func Test_entryToEvent(t *testing.T) {
Exception: []sentry.Exception{
{Type: "*errors.errorString", Value: "things failed", Stacktrace: &sentry.Stacktrace{Frames: []sentry.Frame{}}},
},
Logger: "logrus",
},
},
"non-error": {
Expand All @@ -159,6 +166,7 @@ func Test_entryToEvent(t *testing.T) {
Extra: map[string]any{
"error": "this isn't really an error",
},
Logger: "logrus",
},
},
"error with stack trace": {
Expand Down Expand Up @@ -192,6 +200,7 @@ func Test_entryToEvent(t *testing.T) {
},
},
},
Logger: "logrus",
},
},
"user": {
Expand All @@ -208,6 +217,7 @@ func Test_entryToEvent(t *testing.T) {
User: sentry.User{
ID: "bob",
},
Logger: "logrus",
},
},
"user pointer": {
Expand All @@ -224,6 +234,7 @@ func Test_entryToEvent(t *testing.T) {
User: sentry.User{
ID: "alice",
},
Logger: "logrus",
},
},
"non-user": {
Expand All @@ -237,6 +248,7 @@ func Test_entryToEvent(t *testing.T) {
Extra: map[string]any{
"user": "just say no to drugs",
},
Logger: "logrus",
},
},
}
Expand Down
Loading