@@ -39,12 +39,10 @@ def __init__(
3939 max_queue_size = max_queue_size ,
4040 )
4141
42- # Code based off of:
4342 # https://github.com/open-telemetry/opentelemetry-python/blob/main/opentelemetry-sdk/src/opentelemetry/sdk/_shared_internal/__init__.py#L143
4443 def _export (self , batch_strategy : BatchLogExportStrategy ) -> None :
4544 """
46- Overrides the batching behavior of upstream's export method. Preserves existing batching behavior but
47- will intermediarly export small log batches if the size of the data in the batch is at or
45+ Preserves existing batching behavior but will intermediarly export small log batches if the size of the data in the batch is at or
4846 above AWS CloudWatch's maximum request size limit of 1 MB.
4947
5048 - Data size of exported batches will ALWAYS be <= 1 MB except for the case below:
@@ -91,7 +89,8 @@ def _export(self, batch_strategy: BatchLogExportStrategy) -> None:
9189 _logger .exception ("Exception while exporting logs." )
9290 detach (token )
9391
94- def _get_size_of_log (self , log_data : LogData ) -> int :
92+ @staticmethod
93+ def _get_size_of_log (log_data : LogData ) -> int :
9594 """
9695 Estimates the size of a given LogData based on the size of the body + a buffer
9796 amount representing a rough guess of other data present in the log.
@@ -100,11 +99,12 @@ def _get_size_of_log(self, log_data: LogData) -> int:
10099 body = log_data .log_record .body
101100
102101 if body :
103- size += self ._get_size_of_any_value (body )
102+ size += AwsBatchLogRecordProcessor ._get_size_of_any_value (body )
104103
105104 return size
106105
107- def _get_size_of_any_value (self , val : AnyValue ) -> int :
106+ @staticmethod
107+ def _get_size_of_any_value (val : AnyValue ) -> int :
108108 """
109109 Recursively calculates the size of an AnyValue type in bytes.
110110 """
@@ -114,19 +114,17 @@ def _get_size_of_any_value(self, val: AnyValue) -> int:
114114 return len (val )
115115
116116 if isinstance (val , bool ):
117- if val :
118- return 4 # len(True) = 4
119- return 5 # len(False) = 5
120-
117+ return 4 if val else 5
118+
121119 if isinstance (val , int ) or isinstance (val , float ):
122120 return len (str (val ))
123121
124122 if isinstance (val , Sequence ):
125123 for content in val :
126- size += self ._get_size_of_any_value (content )
124+ size += AwsBatchLogRecordProcessor ._get_size_of_any_value (content )
127125
128126 if isinstance (val , Mapping ):
129127 for _ , content in val .items ():
130- size += self ._get_size_of_any_value (content )
128+ size += AwsBatchLogRecordProcessor ._get_size_of_any_value (content )
131129
132130 return size
0 commit comments