@@ -14,13 +14,7 @@ send_envelope() {
1414}
1515
1616generate_breadcrumb_json () {
17- # Based on https://stackoverflow.com/a/1521498
18- while IFS=" " read -r line || [ -n " $line " ]; do
19- jq -n -c --arg message " $line " \
20- --arg category log \
21- --arg level info \
22- ' $ARGS.named'
23- done < $log_path
17+ cat $log_path | $jq -R -c ' split("\n") | {"message": (.[0]//""), "category": "log", "level": "info"}'
2418}
2519
2620send_event () {
@@ -42,7 +36,7 @@ send_event() {
4236 local file_length=$( wc -c < $log_path | awk ' {print $1}' )
4337
4438 # Add header for initial envelope information
45- jq -n -c --arg event_id " $event_hash " \
39+ $ jq -n -c --arg event_id " $event_hash " \
4640 --arg dsn " $SENTRY_DSN " \
4741 ' $ARGS.named' > $envelope_file_path
4842 # Add header to specify the event type of envelope to be sent
@@ -56,24 +50,24 @@ send_event() {
5650 # Then we need the exception payload
5751 # https://develop.sentry.dev/sdk/event-payloads/exception/
5852 # but first we need to make the stacktrace which goes in the exception payload
59- frames=$( echo " $traceback_json " | jq -s -c)
60- stacktrace=$( jq -n -c --argjson frames " $frames " ' $ARGS.named' )
53+ frames=$( echo " $traceback_json " | $ jq -s -c)
54+ stacktrace=$( $ jq -n -c --argjson frames " $frames " ' $ARGS.named' )
6155 exception=$(
62- jq -n -c --arg " type" Error \
56+ $ jq -n -c --arg " type" Error \
6357 --arg value " $error_msg " \
6458 --argjson stacktrace " $stacktrace " \
6559 ' $ARGS.named'
6660 )
6761 event_body=$(
68- jq -n -c --arg level error \
62+ $ jq -n -c --arg level error \
6963 --argjson exception " {\" values\" :[$exception ]}" \
7064 --argjson breadcrumbs " {\" values\" : $breadcrumbs }" \
7165 ' $ARGS.named'
7266 )
7367 echo " $event_body " >> $envelope_file_path
7468 # Add attachment to the event
7569 attachment=$(
76- jq -n -c --arg " type" attachment \
70+ $ jq -n -c --arg " type" attachment \
7771 --arg length $file_length \
7872 --arg content_type " text/plain" \
7973 --arg filename install_log.txt \
@@ -173,7 +167,7 @@ cleanup() {
173167 # Create the breadcrumb payload now before stacktrace is printed
174168 # https://develop.sentry.dev/sdk/event-payloads/breadcrumbs/
175169 # Use sed to remove the last line, that is reported through the error message
176- breadcrumbs=$( generate_breadcrumb_json | sed ' $d' | jq -s -c)
170+ breadcrumbs=$( generate_breadcrumb_json | sed ' $d' | $ jq -s -c)
177171 printf -v err ' %s' " Error in ${BASH_SOURCE[1]} :${BASH_LINENO[0]} ."
178172 printf -v cmd_exit ' %s' " '$cmd ' exited with status $retcode "
179173 printf ' %s\n%s\n' " $err " " $cmd_exit "
@@ -187,15 +181,15 @@ cleanup() {
187181 local lineno=${BASH_LINENO[$i - 1]}
188182 local funcname=${FUNCNAME[$i]}
189183 JSON=$(
190- jq -n -c --arg filename $src \
184+ $ jq -n -c --arg filename $src \
191185 --arg " function" $funcname \
192186 --arg lineno " $lineno " \
193187 ' {"filename": $filename, "function": $function, "lineno": $lineno|tonumber}'
194188 )
195189 # If we're in the stacktrace of the file we failed on, we can add a context line with the command run that failed
196190 if [[ $i -eq 1 ]]; then
197191 JSON=$(
198- jq -n -c --arg cmd " $cmd " \
192+ $ jq -n -c --arg cmd " $cmd " \
199193 --argjson json " $JSON " \
200194 ' $json + {"context_line": $cmd}'
201195 )
0 commit comments