File tree Expand file tree Collapse file tree 2 files changed +14
-7
lines changed
src/clusterfuzz/_internal Expand file tree Collapse file tree 2 files changed +14
-7
lines changed Original file line number Diff line number Diff line change @@ -182,7 +182,7 @@ def get_logging_config_dict(name):
182
182
183
183
def truncate (msg , limit ):
184
184
"""We need to truncate the message in the middle if it gets too long."""
185
- if len (msg ) <= limit :
185
+ if not isinstance ( msg , str ) or len (msg ) <= limit :
186
186
return msg
187
187
188
188
half = limit // 2
@@ -225,7 +225,12 @@ def format(self, record: logging.LogRecord) -> str:
225
225
entry ['task_payload' ] = initial_payload
226
226
227
227
entry ['location' ] = getattr (record , 'location' , {'error' : True })
228
- entry ['extras' ] = getattr (record , 'extras' , {})
228
+ # This is needed to truncate the extras value, as it can be used
229
+ # to log exceptions stacktrace.
230
+ entry ['extras' ] = {
231
+ k : truncate (v , STACKDRIVER_LOG_MESSAGE_LIMIT )
232
+ for k , v in getattr (record , 'extras' , {}).items ()
233
+ }
229
234
update_entry_with_exc (entry , record .exc_info )
230
235
231
236
if not entry ['extras' ]:
Original file line number Diff line number Diff line change @@ -190,6 +190,10 @@ def get_record(self):
190
190
levelname = 'INFO' ,
191
191
exc_info = 'exc_info' ,
192
192
created = 10 ,
193
+ # This extras field is needed because the call
194
+ # getattr(record, 'extras', {}) returns None and not the
195
+ # default for the case of running against a mock
196
+ extras = {},
193
197
location = {
194
198
'path' : 'path' ,
195
199
'line' : 123 ,
@@ -208,16 +212,16 @@ def test_format_record(self):
208
212
'message' : 'log message' ,
209
213
'created' : '1970-01-01T00:00:10Z' ,
210
214
'docker_image' : '' ,
215
+ 'extras' : {
216
+ 'a' : 1
217
+ },
211
218
'severity' : 'INFO' ,
212
219
'bot_name' : 'linux-bot' ,
213
220
'task_payload' : 'fuzz fuzzer1 job1' ,
214
221
'fuzz_target' : 'fuzz_target1' ,
215
222
'name' : 'logger_name' ,
216
223
'pid' : 1337 ,
217
224
'release' : 'prod' ,
218
- 'extras' : {
219
- 'a' : 1 ,
220
- },
221
225
'location' : {
222
226
'path' : 'path' ,
223
227
'line' : 123 ,
@@ -231,7 +235,6 @@ def test_format_record(self):
231
235
def test_no_extras (self ):
232
236
"""Test format record with no extras."""
233
237
record = self .get_record ()
234
- record .extras = None
235
238
self .assertEqual ({
236
239
'message' : 'log message' ,
237
240
'created' : '1970-01-01T00:00:10Z' ,
@@ -255,7 +258,6 @@ def test_worker_bot_name(self):
255
258
"""Test format record with a worker bot name."""
256
259
os .environ ['WORKER_BOT_NAME' ] = 'worker'
257
260
record = self .get_record ()
258
- record .extras = None
259
261
260
262
self .assertEqual ({
261
263
'docker_image' : '' ,
You can’t perform that action at this time.
0 commit comments