Skip to content

Commit eb05e4b

Browse files
authored
Add logger name to logrus integration (#866)
* add logger name to logrus integration * fix tests
1 parent c6c965c commit eb05e4b

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

Diff for: logrus/logrusentry.go

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
// The identifier of the Logrus SDK.
1515
const sdkIdentifier = "sentry.go.logrus"
16+
const name = "logrus"
1617

1718
// These default log field keys are used to pass specific metadata in a way that
1819
// Sentry understands. If they are found in the log fields, and the value is of
@@ -153,6 +154,7 @@ func (h *Hook) entryToEvent(l *logrus.Entry) *sentry.Event {
153154
Extra: data,
154155
Message: l.Message,
155156
Timestamp: l.Time,
157+
Logger: name,
156158
}
157159
key := h.key(FieldRequest)
158160
if req, ok := s.Extra[key].(*http.Request); ok {

Diff for: logrus/logrusentry_test.go

+18-6
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,9 @@ func Test_entryToEvent(t *testing.T) {
7373
"empty entry": {
7474
entry: &logrus.Entry{},
7575
want: &sentry.Event{
76-
Level: "fatal",
77-
Extra: map[string]any{},
76+
Level: "fatal",
77+
Extra: map[string]any{},
78+
Logger: "logrus",
7879
},
7980
},
8081
"data fields": {
@@ -85,17 +86,19 @@ func Test_entryToEvent(t *testing.T) {
8586
},
8687
},
8788
want: &sentry.Event{
88-
Level: "fatal",
89-
Extra: map[string]any{"bar": "oink", "foo": 123.4},
89+
Level: "fatal",
90+
Extra: map[string]any{"bar": "oink", "foo": 123.4},
91+
Logger: "logrus",
9092
},
9193
},
9294
"info level": {
9395
entry: &logrus.Entry{
9496
Level: logrus.InfoLevel,
9597
},
9698
want: &sentry.Event{
97-
Level: "info",
98-
Extra: map[string]any{},
99+
Level: "info",
100+
Extra: map[string]any{},
101+
Logger: "logrus",
99102
},
100103
},
101104
"message": {
@@ -106,6 +109,7 @@ func Test_entryToEvent(t *testing.T) {
106109
Level: "fatal",
107110
Extra: map[string]any{},
108111
Message: "the only thing we have to fear is fear itself",
112+
Logger: "logrus",
109113
},
110114
},
111115
"timestamp": {
@@ -116,6 +120,7 @@ func Test_entryToEvent(t *testing.T) {
116120
Level: "fatal",
117121
Extra: map[string]any{},
118122
Timestamp: time.Unix(1, 2).UTC(),
123+
Logger: "logrus",
119124
},
120125
},
121126
"http request": {
@@ -132,6 +137,7 @@ func Test_entryToEvent(t *testing.T) {
132137
Method: http.MethodGet,
133138
Headers: map[string]string{"Host": "example.com"},
134139
},
140+
Logger: "logrus",
135141
},
136142
},
137143
"error": {
@@ -146,6 +152,7 @@ func Test_entryToEvent(t *testing.T) {
146152
Exception: []sentry.Exception{
147153
{Type: "*errors.errorString", Value: "things failed", Stacktrace: &sentry.Stacktrace{Frames: []sentry.Frame{}}},
148154
},
155+
Logger: "logrus",
149156
},
150157
},
151158
"non-error": {
@@ -159,6 +166,7 @@ func Test_entryToEvent(t *testing.T) {
159166
Extra: map[string]any{
160167
"error": "this isn't really an error",
161168
},
169+
Logger: "logrus",
162170
},
163171
},
164172
"error with stack trace": {
@@ -192,6 +200,7 @@ func Test_entryToEvent(t *testing.T) {
192200
},
193201
},
194202
},
203+
Logger: "logrus",
195204
},
196205
},
197206
"user": {
@@ -208,6 +217,7 @@ func Test_entryToEvent(t *testing.T) {
208217
User: sentry.User{
209218
ID: "bob",
210219
},
220+
Logger: "logrus",
211221
},
212222
},
213223
"user pointer": {
@@ -224,6 +234,7 @@ func Test_entryToEvent(t *testing.T) {
224234
User: sentry.User{
225235
ID: "alice",
226236
},
237+
Logger: "logrus",
227238
},
228239
},
229240
"non-user": {
@@ -237,6 +248,7 @@ func Test_entryToEvent(t *testing.T) {
237248
Extra: map[string]any{
238249
"user": "just say no to drugs",
239250
},
251+
Logger: "logrus",
240252
},
241253
},
242254
}

0 commit comments

Comments
 (0)