Skip to content

Commit 2bc00ae

Browse files
committed
Improve publication logging
Why these changes are being introduced: Our current logging doesn't capture much information. (It usually just says 'N/A'.) While DSpace errors are not useful, we should still probably try to capture what's there. Relevant ticket(s): N/A How this addresses that need: That adds some Copilot-suggested changes to enhance our logging in the DSpace publication results job. Side effects of this change: None.
1 parent 664187c commit 2bc00ae

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

app/jobs/dspace_publication_results_job.rb

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ class DspacePublicationResultsJob < ActiveJob::Base
44
MAX_MESSAGES = ENV.fetch('SQS_RESULT_MAX_MESSAGES', 10)
55
WAIT_TIME_SECONDS = ENV.fetch('SQS_RESULT_WAIT_TIME_SECONDS', 10)
66
IDLE_TIMEOUT = ENV.fetch('SQS_RESULT_IDLE_TIMEOUT', 0)
7+
MAX_ERROR_FIELD_LENGTH = 500
8+
MAX_TRACEBACK_LENGTH = 1000
79

810
queue_as :default
911

@@ -124,7 +126,7 @@ def update_publication_status(thesis, body, results, status)
124126
when 'success'
125127
update_handle(thesis, body, results)
126128
when 'error'
127-
error = body['DSpaceResponse']
129+
error = format_dss_error(body)
128130
thesis.publication_status = 'Publication error'
129131
thesis.save
130132
Rails.logger.info("Thesis #{thesis.id} updated to status #{thesis.publication_status}. Error from DSS: #{error}")
@@ -138,6 +140,42 @@ def update_publication_status(thesis, body, results, status)
138140
end
139141
end
140142

143+
def format_dss_error(body)
144+
details = []
145+
details << format_error_detail('ErrorInfo', body['ErrorInfo']) if body['ErrorInfo'].present?
146+
details << format_error_detail('DSpaceResponse', body['DSpaceResponse']) if body['DSpaceResponse'].present?
147+
details << format_error_detail('ExceptionMessage', body['ExceptionMessage']) if body['ExceptionMessage'].present?
148+
149+
traceback = format_traceback(body['ExceptionTraceback'])
150+
details << format_error_detail('ExceptionTraceback', traceback, max_length: MAX_TRACEBACK_LENGTH) if traceback.present?
151+
152+
return 'No error details provided by DSS' if details.empty?
153+
154+
details.join(' | ')
155+
end
156+
157+
def format_error_detail(label, value, max_length: MAX_ERROR_FIELD_LENGTH)
158+
normalized = value.to_s.gsub(/\s+/, ' ').strip
159+
if normalized.length > max_length
160+
normalized = "#{normalized[0...max_length]}...(truncated)"
161+
end
162+
163+
"#{label}: #{normalized}"
164+
end
165+
166+
def format_traceback(traceback)
167+
lines = if traceback.is_a?(Array)
168+
traceback
169+
elsif traceback.is_a?(String)
170+
traceback.split(/\r?\n/)
171+
else
172+
[]
173+
end
174+
175+
lines = lines.map { |line| line.to_s.strip }
176+
lines.reject(&:blank?).first(5).join(' || ')
177+
end
178+
141179
def poll_messages(queue_url, results)
142180
# https://docs.aws.amazon.com/sdk-for-ruby/v3/developer-guide/sqs-example-poll-messages.html
143181
# Poller retrieves messages until there are none left and deletes them as it goes

test/jobs/dspace_publication_results_job_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,13 @@ def teardown
179179
'validate checksums as no local files were attached to the record. This ' \
180180
'requires staff to manually check the ETD record and DSpace record and take ' \
181181
'appropriate action.'
182+
183+
# DSS error details are surfaced from error payload
184+
dss_error = results[:errors].find { |e| e.include?('ErrorInfo: Stuff broke') }
185+
assert_not_nil dss_error, 'Expected DSS error with "ErrorInfo: Stuff broke" to be surfaced in results[:errors]'
186+
assert_includes dss_error, 'ErrorInfo: Stuff broke'
187+
assert_includes dss_error, 'ExceptionMessage: 500 Server Error: Internal Server Error'
188+
assert_includes dss_error, 'ExceptionTraceback: Full unformatted stack trace of the Exception'
182189
end
183190

184191
test 'enqueues preservation submission prep job' do

0 commit comments

Comments
 (0)