@@ -216,14 +216,43 @@ def check_spider_attributes(self, spider):
216216
217217
218218 def get_settings (self , spider ):
219+ import logging
220+ logger = logging .getLogger (__name__ )
221+
219222 default_scrapy_settings = default_settings .__dict__
220223 full_settings = spider .settings .copy_to_dict ()
221224 self .spider_settings = {}
225+ non_serializable_settings = []
226+
222227 for key , value in full_settings .items ():
223228 if key not in default_scrapy_settings and self .include_setting (key ):
224- self .spider_settings [key ] = value
229+ if self ._is_serializable (value ):
230+ self .spider_settings [key ] = value
231+ else :
232+ non_serializable_settings .append (key )
225233 elif default_scrapy_settings .get (key ) != value and self .include_setting (key ):
226- self .spider_settings [key ] = value
234+ if self ._is_serializable (value ):
235+ self .spider_settings [key ] = value
236+ else :
237+ non_serializable_settings .append (key )
238+
239+ # Log warning about non-serializable settings
240+ if non_serializable_settings :
241+ logger .warning (
242+ f"ScrapeOps: Excluded { len (non_serializable_settings )} non-serializable settings from monitoring: "
243+ f"{ ', ' .join (non_serializable_settings )} . "
244+ f"These settings contain functions or other objects that cannot be sent to ScrapeOps. "
245+ f"To suppress this warning, add these setting names to SCRAPEOPS_SETTINGS_EXCLUSION_LIST in your settings.py file."
246+ )
247+
248+ def _is_serializable (self , value ):
249+ """Check if a value can be JSON serialized."""
250+ import json
251+ try :
252+ json .dumps (value )
253+ return True
254+ except (TypeError , ValueError ):
255+ return False
227256
228257 def include_setting (self , key ):
229258 exclusion_terms = ['API_KEY' , 'APIKEY' , 'SECRET_KEY' , 'SECRETKEY' , 'PASSWORD' , 'CONNECTION_STRING' ]
0 commit comments