Skip to content

Commit a44fa4a

Browse files
authored
Handle fingerprint (#31)
* Handle fingerprint * Document fingerprint
1 parent 6055761 commit a44fa4a

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ The following attributes are interpreted by `slogsentry.DefaultConverter`:
144144
| "user" | group (see below) | |
145145
| "error" | any | `error` |
146146
| "request" | any | `*http.Request` |
147+
| "fingerprint" | any | `[]string` |
147148
| other attributes | * | |
148149

149150
Other attributes will be injected in `context` Sentry field.

converter.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ func attrToSentryEvent(attr slog.Attr, event *sentry.Event) {
107107
}
108108
}
109109
}
110+
case k == "fingerprint" && kind == slog.KindAny:
111+
if fingerprint, ok := v.Any().([]string); ok {
112+
event.Fingerprint = fingerprint
113+
}
110114
case kind == slog.KindGroup:
111115
event.Contexts[k] = slogcommon.AttrsToMap(v.Group()...)
112116
default:

converter_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ func TestAttrToSentryEvent(t *testing.T) {
162162
}},
163163
},
164164
},
165+
"fingerprint": {
166+
attr: slog.Attr{Key: "fingerprint", Value: slog.AnyValue([]string{"value1", "value2"})},
167+
expected: &sentry.Event{Fingerprint: []string{"value1", "value2"}},
168+
},
165169
}
166170

167171
for name, tc := range tests {
@@ -177,6 +181,7 @@ func TestAttrToSentryEvent(t *testing.T) {
177181
assert.Equal(t, tc.expected.Transaction, event.Transaction)
178182
assert.Equal(t, tc.expected.User, event.User)
179183
assert.Equal(t, tc.expected.Request, event.Request)
184+
assert.Equal(t, tc.expected.Fingerprint, event.Fingerprint)
180185
if len(tc.expected.Tags) == 0 {
181186
assert.Empty(t, event.Tags)
182187
} else {

0 commit comments

Comments
 (0)