File tree 1 file changed +22
-2
lines changed
src/spaceone/core/service
1 file changed +22
-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,22 @@ def _pipeline(
265
269
delete_transaction ()
266
270
267
271
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
+
268
288
def _error_handler (
269
289
error_type : _ERROR_TYPE ,
270
290
error : ERROR_BASE ,
You can’t perform that action at this time.
0 commit comments