Skip to content

Commit 27c9cc7

Browse files
authored
Fix error fingerprinting (#2237)
1 parent 5394475 commit 27c9cc7

File tree

3 files changed

+57
-19
lines changed

3 files changed

+57
-19
lines changed

_unit-test/error-handling-test.sh

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,48 +14,73 @@ send_envelope() {
1414
echo "Test Sending $1"
1515
}
1616

17+
##########################
18+
1719
export -f send_envelope
1820
echo "Testing initial send_event"
1921
export log_file=test_log.txt
2022
echo "Test Logs" >"$log_file"
2123
echo "Error Msg" >>"$log_file"
2224
breadcrumbs=$(generate_breadcrumb_json | sed '$d' | $jq -s -c)
23-
SEND_EVENT_RESPONSE=$(send_event "12345123451234512345123451234512" "Test exited with status 1" "{\"ignore\": \"me\"}" "$breadcrumbs")
25+
SEND_EVENT_RESPONSE=$(
26+
send_event \
27+
"'foo' exited with status 1" \
28+
"Test exited with status 1" \
29+
"Traceback: ignore me" \
30+
"{\"ignore\": \"me\"}" \
31+
"$breadcrumbs"
32+
)
2433
rm "$log_file"
25-
test "$SEND_EVENT_RESPONSE" == 'Test Sending sentry-envelope-12345123451234512345123451234512'
26-
ENVELOPE_CONTENTS=$(cat /tmp/sentry-envelope-12345123451234512345123451234512)
27-
test "$ENVELOPE_CONTENTS" == "$(cat _unit-test/snapshots/sentry-envelope-12345123451234512345123451234512)"
34+
expected_filename='sentry-envelope-f73e4da437c42a1d28b86a81ebcff35d'
35+
test "$SEND_EVENT_RESPONSE" == "Test Sending $expected_filename"
36+
ENVELOPE_CONTENTS=$(cat "/tmp/$expected_filename")
37+
test "$ENVELOPE_CONTENTS" == "$(cat _unit-test/snapshots/$expected_filename)"
2838
echo "Pass."
2939

40+
##########################
41+
3042
echo "Testing send_event duplicate"
31-
SEND_EVENT_RESPONSE=$(send_event "12345123451234512345123451234512" "Test exited with status 1" "{\"ignore\": \"me\"}" "$breadcrumbs")
43+
SEND_EVENT_RESPONSE=$(
44+
send_event \
45+
"'foo' exited with status 1" \
46+
"Test exited with status 1" \
47+
"Traceback: ignore me" \
48+
"{\"ignore\": \"me\"}" \
49+
"$breadcrumbs"
50+
)
3251
test "$SEND_EVENT_RESPONSE" == "Looks like you've already sent this error to us, we're on it :)"
3352
echo "Pass."
34-
rm '/tmp/sentry-envelope-12345123451234512345123451234512'
53+
rm "/tmp/$expected_filename"
54+
55+
##########################
3556

3657
echo "Testing cleanup without minimizing downtime"
3758
export REPORT_SELF_HOSTED_ISSUES=0
3859
export MINIMIZE_DOWNTIME=''
3960
export dc=':'
4061
echo "Test Logs" >"$log_file"
41-
CLEANUP_RESPONSE=$(cleanup ERROR)
62+
CLEANUP_RESPONSE=$(cleanup ERROR) # the linenumber of this line must match just below
4263
rm "$log_file"
43-
test "$CLEANUP_RESPONSE" == 'Error in _unit-test/error-handling-test.sh:41.
64+
test "$CLEANUP_RESPONSE" == 'Error in _unit-test/error-handling-test.sh:62.
4465
'\''local cmd="${BASH_COMMAND}"'\'' exited with status 0
4566
4667
Cleaning up...'
4768
echo "Pass."
4869

70+
##########################
71+
4972
echo "Testing cleanup while minimizing downtime"
5073
export REPORT_SELF_HOSTED_ISSUES=0
5174
export MINIMIZE_DOWNTIME=1
5275
echo "Test Logs" >"$log_file"
53-
CLEANUP_RESPONSE=$(cleanup ERROR)
76+
CLEANUP_RESPONSE=$(cleanup ERROR) # the linenumber of this line must match just below
5477
rm "$log_file"
55-
test "$CLEANUP_RESPONSE" == 'Error in _unit-test/error-handling-test.sh:53.
78+
test "$CLEANUP_RESPONSE" == 'Error in _unit-test/error-handling-test.sh:76.
5679
'\''local cmd="${BASH_COMMAND}"'\'' exited with status 0
5780
5881
*NOT* cleaning up, to clean your environment run "docker compose stop".'
5982
echo "Pass."
6083

84+
##########################
85+
6186
report_success
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
{"event_id":"12345123451234512345123451234512","dsn":"https://[email protected]/3"}
1+
{"event_id":"f73e4da437c42a1d28b86a81ebcff35d","dsn":"https://[email protected]/3"}
22
{"type":"event"}
3-
{"level":"error","exception":{"values":[{"type":"Error","value":"Test exited with status 1","stacktrace":{"frames":[{"ignore":"me"}]}}]},"breadcrumbs":{"values":[{"message":"Test Logs","category":"log","level":"info"}]}}
3+
{"level":"error","exception":{"values":[{"type":"Error","value":"Test exited with status 1","stacktrace":{"frames":[{"ignore":"me"}]}}]},"breadcrumbs":{"values":[{"message":"Test Logs","category":"log","level":"info"}]},"fingerprint":["f73e4da437c42a1d28b86a81ebcff35d"]}
44
{"type":"attachment","length":20,"content_type":"text/plain","filename":"install_log.txt"}
55
Test Logs
66
Error Msg

install/error-handling.sh

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,17 @@ generate_breadcrumb_json() {
2020

2121
send_event() {
2222
# Use traceback hash as the UUID since it is 32 characters long
23-
local event_hash=$1
23+
local cmd_exit=$1
2424
local error_msg=$2
25-
local traceback_json=$3
26-
local breadcrumbs=$4
27-
local envelope_file="sentry-envelope-${event_hash}"
25+
local traceback=$3
26+
local traceback_json=$4
27+
local breadcrumbs=$5
28+
local fingerprint_value=$(
29+
echo -n "$cmd_exit $error_msg $traceback" |
30+
docker run -i --rm busybox md5sum |
31+
cut -d' ' -f1
32+
)
33+
local envelope_file="sentry-envelope-${fingerprint_value}"
2834
local envelope_file_path="/tmp/$envelope_file"
2935
# If the envelope file exists, we've already sent it
3036
if [[ -f $envelope_file_path ]]; then
@@ -37,7 +43,7 @@ send_event() {
3743
local file_length=$(wc -c <$log_file | awk '{print $1}')
3844

3945
# Add header for initial envelope information
40-
$jq -n -c --arg event_id "$event_hash" \
46+
$jq -n -c --arg event_id "$fingerprint_value" \
4147
--arg dsn "$SENTRY_DSN" \
4248
'$ARGS.named' >"$envelope_file_path"
4349
# Add header to specify the event type of envelope to be sent
@@ -59,10 +65,18 @@ send_event() {
5965
--argjson stacktrace "$stacktrace" \
6066
'$ARGS.named'
6167
)
68+
69+
# It'd be a bit cleaner in the Sentry UI if we passed the inputs to
70+
# fingerprint_value hash rather than the hash itself (I believe the ultimate
71+
# hash ends up simply being a hash of our hash), but we want the hash locally
72+
# so that we can avoid resending the same event (design decision to avoid
73+
# spam in the system). It was also futzy to figure out how to get the
74+
# traceback in there properly. Meh.
6275
event_body=$(
6376
$jq -n -c --arg level error \
6477
--argjson exception "{\"values\":[$exception]}" \
6578
--argjson breadcrumbs "{\"values\": $breadcrumbs}" \
79+
--argjson fingerprint "[\"$fingerprint_value\"]" \
6680
'$ARGS.named'
6781
)
6882
echo "$event_body" >>$envelope_file_path
@@ -203,8 +217,7 @@ cleanup() {
203217

204218
# Only send event when report issues flag is set and if trap signal is not INT (ctrl+c)
205219
if [[ "$REPORT_SELF_HOSTED_ISSUES" == 1 && "$1" != "INT" ]]; then
206-
local event_hash=$(echo -n "$cmd_exit $traceback" | docker run -i --rm busybox md5sum | cut -d' ' -f1)
207-
send_event "$event_hash" "$error_msg" "$traceback_json" "$breadcrumbs"
220+
send_event "$cmd_exit" "$error_msg" "$traceback" "$traceback_json" "$breadcrumbs"
208221
fi
209222

210223
if [[ -n "$MINIMIZE_DOWNTIME" ]]; then

0 commit comments

Comments
 (0)