@@ -163,10 +163,6 @@ def __init__(self, is_periodic=True, agentless=None):
163
163
self ._periodic_count = 0
164
164
self ._is_periodic = is_periodic
165
165
self ._integrations_queue = dict () # type: Dict[str, Dict]
166
- # Currently telemetry only supports reporting a single error.
167
- # If we'd like to report multiple errors in the future
168
- # we could hack it in by xor-ing error codes and concatenating strings
169
- self ._error = (0 , "" ) # type: Tuple[int, str]
170
166
self ._namespace = MetricNamespace ()
171
167
self ._logs = set () # type: Set[Dict[str, Any]]
172
168
self ._forked = False # type: bool
@@ -301,15 +297,6 @@ def add_integration(self, integration_name, patched, auto_patched=None, error_ms
301
297
self ._integrations_queue [integration_name ]["compatible" ] = error_msg == ""
302
298
self ._integrations_queue [integration_name ]["error" ] = error_msg
303
299
304
- def add_error (self , code , msg , filename , line_number ):
305
- # type: (int, str, Optional[str], Optional[int]) -> None
306
- """Add an error to be submitted with an event.
307
- Note that this overwrites any previously set errors.
308
- """
309
- if filename and line_number is not None :
310
- msg = "%s:%s: %s" % (filename , line_number , msg )
311
- self ._error = (code , msg )
312
-
313
300
def _app_started (self , register_app_shutdown = True ):
314
301
# type: (bool) -> None
315
302
"""Sent when TelemetryWriter is enabled or forks"""
@@ -330,10 +317,6 @@ def _app_started(self, register_app_shutdown=True):
330
317
331
318
payload = {
332
319
"configuration" : self ._flush_configuration_queue (),
333
- "error" : {
334
- "code" : self ._error [0 ],
335
- "message" : self ._error [1 ],
336
- },
337
320
"products" : products ,
338
321
} # type: Dict[str, Union[Dict[str, Any], List[Any]]]
339
322
# Add time to value telemetry metrics for single step instrumentation
@@ -343,9 +326,6 @@ def _app_started(self, register_app_shutdown=True):
343
326
"install_type" : config .INSTALL_TYPE ,
344
327
"install_time" : config .INSTALL_TIME ,
345
328
}
346
-
347
- # Reset the error after it has been reported.
348
- self ._error = (0 , "" )
349
329
self .add_event (payload , "app-started" )
350
330
351
331
def _app_heartbeat_event (self ):
@@ -524,18 +504,21 @@ def add_log(self, level, message, stack_trace="", tags=None):
524
504
# Logs are hashed using the message, level, tags, and stack_trace. This should prevent duplicatation.
525
505
self ._logs .add (data )
526
506
527
- def add_error_log (self , msg : str , exc : BaseException ) -> None :
507
+ def add_error_log (self , msg : str , exc : Union [ BaseException , tuple , None ] ) -> None :
528
508
if config .LOG_COLLECTION_ENABLED :
529
- stack_trace = self ._format_stack_trace (exc )
509
+ stack_trace = None if exc is None else self ._format_stack_trace (exc )
530
510
531
511
self .add_log (
532
512
TELEMETRY_LOG_LEVEL .ERROR ,
533
513
msg ,
534
514
stack_trace = stack_trace if stack_trace is not None else "" ,
535
515
)
536
516
537
- def _format_stack_trace (self , exc : BaseException ) -> Optional [str ]:
538
- exc_type , _ , exc_traceback = type (exc ), exc , getattr (exc , "__traceback__" , None )
517
+ def _format_stack_trace (self , exc : Union [BaseException , tuple ]) -> Optional [str ]:
518
+ if isinstance (exc , tuple ) and len (exc ) == 3 :
519
+ exc_type , _ , exc_traceback = exc
520
+ else :
521
+ exc_type , _ , exc_traceback = type (exc ), exc , getattr (exc , "__traceback__" , None )
539
522
540
523
if not exc_traceback :
541
524
return None
@@ -759,7 +742,8 @@ def _telemetry_excepthook(self, tp, value, root_traceback):
759
742
760
743
lineno = traceback .tb_frame .f_code .co_firstlineno
761
744
filename = traceback .tb_frame .f_code .co_filename
762
- self .add_error (1 , str (value ), filename , lineno )
745
+
746
+ self .add_error_log ("Unhandled exception from ddtrace code" , (tp , None , root_traceback ))
763
747
764
748
dir_parts = filename .split (os .path .sep )
765
749
# Check if exception was raised in the `ddtrace.contrib` package
0 commit comments