File tree 1 file changed +23
-2
lines changed
src/spaceone/core/service
1 file changed +23
-2
lines changed Original file line number Diff line number Diff line change 1
1
import copy
2
2
import functools
3
+ import json
3
4
import logging
4
5
import time
5
- from typing import Generator , Union , Literal
6
+ from typing import Generator , Union , Literal , Any
6
7
7
8
from opentelemetry import trace
8
9
from opentelemetry .trace import format_trace_id
@@ -244,7 +245,10 @@ def _pipeline(
244
245
if print_info_log :
245
246
246
247
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
+ )
248
252
249
253
return response_or_iterator
250
254
@@ -265,6 +269,23 @@ def _pipeline(
265
269
delete_transaction ()
266
270
267
271
272
+ def _get_response_size (response_or_iterator : Any ) -> int :
273
+ try :
274
+ print (type (response_or_iterator ))
275
+ if isinstance (response_or_iterator , dict ):
276
+ response_size = len (json .dumps (response_or_iterator , ensure_ascii = False ))
277
+ elif isinstance (response_or_iterator , (bytes , bytearray )):
278
+ response_size = len (response_or_iterator )
279
+ elif response_or_iterator is None :
280
+ response_size = 0
281
+ else :
282
+ response_size = - 1
283
+ except Exception :
284
+ response_size = - 1
285
+
286
+ return response_size
287
+
288
+
268
289
def _error_handler (
269
290
error_type : _ERROR_TYPE ,
270
291
error : ERROR_BASE ,
You can’t perform that action at this time.
0 commit comments