File tree Expand file tree Collapse file tree 1 file changed +22
-2
lines changed
src/spaceone/core/service Expand file tree Collapse file tree 1 file changed +22
-2
lines changed Original file line number Diff line number Diff line change 11import copy
22import functools
3+ import json
34import logging
45import time
5- from typing import Generator , Union , Literal
6+ from typing import Generator , Union , Literal , Any
67
78from opentelemetry import trace
89from opentelemetry .trace import format_trace_id
@@ -244,7 +245,10 @@ def _pipeline(
244245 if print_info_log :
245246
246247 process_time = time .time () - start_time
247- _LOGGER .info (f"(RESPONSE) => SUCCESS (Time = { process_time :.2f} s)" )
248+ response_size = _get_response_size (response_or_iterator )
249+ _LOGGER .info (
250+ f"(RESPONSE) => SUCCESS (Time = { process_time :.2f} s, Size = { response_size } bytes)" ,
251+ )
248252
249253 return response_or_iterator
250254
@@ -265,6 +269,22 @@ def _pipeline(
265269 delete_transaction ()
266270
267271
272+ def _get_response_size (response_or_iterator : Any ) -> int :
273+ try :
274+ if isinstance (response_or_iterator , dict ):
275+ response_size = len (json .dumps (response_or_iterator , ensure_ascii = False ))
276+ elif isinstance (response_or_iterator , (bytes , bytearray )):
277+ response_size = len (response_or_iterator )
278+ elif response_or_iterator is None :
279+ response_size = 0
280+ else :
281+ response_size = - 1
282+ except Exception :
283+ response_size = - 1
284+
285+ return response_size
286+
287+
268288def _error_handler (
269289 error_type : _ERROR_TYPE ,
270290 error : ERROR_BASE ,
You can’t perform that action at this time.
0 commit comments