@@ -120,18 +120,15 @@ def _ensure_log_group_exists(self):
120120 logger .error ("Failed to create log group %s : %s" , self .log_group_name , error )
121121 raise
122122
123- def _get_metric_name (self , record ) -> Optional [str ]:
123+ def _get_metric_name (self , record : Any ) -> Optional [str ]:
124124 """Get the metric name from the metric record or data point."""
125- # For metrics in MetricsData format
126- if hasattr (record , "name" ) and record .name .strip ():
127- return record .name
128125 # For compatibility with older record format
129- if hasattr (record , "instrument" ) and hasattr (record .instrument , "name" ) and record .instrument .name . strip () :
126+ if hasattr (record , "instrument" ) and hasattr (record .instrument , "name" ) and record .instrument .name :
130127 return record .instrument .name
131128 # Return None if no valid metric name found
132129 return None
133130
134- def _get_unit (self , instrument_or_metric ) -> Optional [str ]:
131+ def _get_unit (self , instrument_or_metric : Any ) -> Optional [str ]:
135132 """Get CloudWatch unit from OTel instrument or metric unit."""
136133 # Check if we have an Instrument object or a metric with unit attribute
137134 if isinstance (instrument_or_metric , Instrument ):
@@ -198,7 +195,7 @@ def _create_metric_record(self, metric_name: str, metric_unit: str, metric_descr
198195
199196 return record
200197
201- def _convert_gauge (self , metric , dp ) -> Tuple [Any , int ]:
198+ def _convert_gauge (self , metric : Any , dp : Any ) -> Tuple [Any , int ]:
202199 """Convert a Gauge metric datapoint to a metric record.
203200
204201 Args:
@@ -225,7 +222,7 @@ def _convert_gauge(self, metric, dp) -> Tuple[Any, int]:
225222
226223 return record , timestamp_ms
227224
228- def _group_by_attributes_and_timestamp (self , record , timestamp_ms ) -> Tuple [str , int ]:
225+ def _group_by_attributes_and_timestamp (self , record : Any , timestamp_ms : int ) -> Tuple [str , int ]:
229226 """Group metric record by attributes and timestamp.
230227
231228 Args:
@@ -239,7 +236,7 @@ def _group_by_attributes_and_timestamp(self, record, timestamp_ms) -> Tuple[str,
239236 attrs_key = self ._get_attributes_key (record .attributes )
240237 return (attrs_key , timestamp_ms )
241238
242- def _create_emf_log (self , metric_records , resource : Resource , timestamp : Optional [int ] = None ) -> Dict :
239+ def _create_emf_log (self , metric_records : List [ Any ] , resource : Resource , timestamp : Optional [int ] = None ) -> Dict :
243240 """
244241 Create EMF log dictionary from metric records.
245242
@@ -305,31 +302,13 @@ def _create_emf_log(self, metric_records, resource: Resource, timestamp: Optiona
305302 return emf_log
306303
307304 # pylint: disable=no-member
308- def _send_log_event (self , log_event : Dict ):
305+ def _send_log_event (self , log_event : Dict [ str , Any ] ):
309306 """
310307 Send a log event to CloudWatch Logs.
311308
312309 Basic implementation for PR 1 - sends individual events directly.
313310 """
314311 try :
315- # Create log group and stream if they don't exist
316- try :
317- self .logs_client .create_log_group (logGroupName = self .log_group_name )
318- logger .debug ("Created log group: %s" , self .log_group_name )
319- except ClientError as error :
320- # Check if it's a ResourceAlreadyExistsException (botocore exception handling)
321- if error .response .get ("Error" , {}).get ("Code" ) == "ResourceAlreadyExistsException" :
322- logger .debug ("Log group %s already exists" , self .log_group_name )
323-
324- # Create log stream if it doesn't exist
325- try :
326- self .logs_client .create_log_stream (logGroupName = self .log_group_name , logStreamName = self .log_stream_name )
327- logger .debug ("Created log stream: %s" , self .log_stream_name )
328- except ClientError as error :
329- # Check if it's a ResourceAlreadyExistsException (botocore exception handling)
330- if error .response .get ("Error" , {}).get ("Code" ) == "ResourceAlreadyExistsException" :
331- logger .debug ("Log stream %s already exists" , self .log_stream_name )
332-
333312 # Send the log event
334313 response = self .logs_client .put_log_events (
335314 logGroupName = self .log_group_name , logStreamName = self .log_stream_name , logEvents = [log_event ]
@@ -343,7 +322,9 @@ def _send_log_event(self, log_event: Dict):
343322 raise
344323
345324 # pylint: disable=too-many-nested-blocks
346- def export (self , metrics_data : MetricsData , timeout_millis : Optional [int ] = None , ** kwargs ) -> MetricExportResult :
325+ def export (
326+ self , metrics_data : MetricsData , timeout_millis : Optional [int ] = None , ** kwargs : Any
327+ ) -> MetricExportResult :
347328 """
348329 Export metrics as EMF logs to CloudWatch.
349330
@@ -418,7 +399,7 @@ def force_flush(self, timeout_millis: int = 10000) -> bool:
418399 logger .debug ("CloudWatchEMFExporter force flushes the buffered metrics" )
419400 return True
420401
421- def shutdown (self , timeout_millis = None , ** kwargs ) :
402+ def shutdown (self , timeout_millis : Optional [ int ] = None , ** kwargs : Any ) -> bool :
422403 """
423404 Shutdown the exporter.
424405 Override to handle timeout and other keyword arguments, but do nothing.
@@ -438,7 +419,6 @@ def create_emf_exporter(
438419 log_group_name : str = "/aws/otel/python" ,
439420 log_stream_name : Optional [str ] = None ,
440421 aws_region : Optional [str ] = None ,
441- debug : bool = False ,
442422 ** kwargs ,
443423) -> CloudWatchEMFExporter :
444424 """
@@ -466,11 +446,6 @@ def create_emf_exporter(
466446 UpDownCounter : AggregationTemporality .DELTA ,
467447 }
468448
469- # Configure logging if debug is enabled
470- if debug :
471- logging .basicConfig (level = logging .DEBUG )
472- logger .setLevel (logging .DEBUG )
473-
474449 # Create and return the exporter
475450 return CloudWatchEMFExporter (
476451 namespace = namespace ,
0 commit comments