31
31
from ..utils .version import version as tracer_version
32
32
from . import modules
33
33
from .constants import TELEMETRY_APM_PRODUCT
34
+ from .constants import TELEMETRY_EVENT_TYPE
34
35
from .constants import TELEMETRY_LOG_LEVEL
35
36
from .constants import TELEMETRY_NAMESPACE
36
- from .constants import TELEMETRY_TYPE_LOGS
37
37
from .data import get_application
38
38
from .data import get_host_info
39
39
from .data import get_python_config_vars
@@ -216,7 +216,7 @@ def __init__(self, is_periodic=True, agentless=None):
216
216
self .enable ()
217
217
# Force app started for unit tests
218
218
if config .FORCE_START and (app_started := self ._app_started_payload ()):
219
- self ._events_queue .append ({"payload" : app_started , "request_type" : "app-started" })
219
+ self ._events_queue .append ({"payload" : app_started , "request_type" : TELEMETRY_EVENT_TYPE . STARTED })
220
220
get_logger ("ddtrace" ).addHandler (DDTelemetryErrorHandler (self ))
221
221
222
222
def enable (self ):
@@ -635,7 +635,7 @@ def periodic(self, force_flush=False, shutting_down=False):
635
635
)
636
636
637
637
if logs := self ._report_logs ():
638
- events .append ({"payload" : {"logs" : list (logs )}, "request_type" : TELEMETRY_TYPE_LOGS })
638
+ events .append ({"payload" : {"logs" : list (logs )}, "request_type" : TELEMETRY_EVENT_TYPE . LOGS })
639
639
640
640
# Queue metrics if not at heartbeat interval
641
641
if self ._is_periodic and force_flush is False :
@@ -649,34 +649,39 @@ def periodic(self, force_flush=False, shutting_down=False):
649
649
# At heartbeat interval, collect and send all telemetry data
650
650
if app_started_payload := self ._app_started_payload ():
651
651
# app-started should be the first event in the batch
652
- events = [{"payload" : app_started_payload , "request_type" : "app-started" }] + events
652
+ events = [{"payload" : app_started_payload , "request_type" : TELEMETRY_EVENT_TYPE . STARTED }] + events
653
653
654
654
if products := self ._report_app_products ():
655
- events .append ({"payload" : {"products" : products }, "request_type" : "app-product-change" })
655
+ events .append ({"payload" : {"products" : products }, "request_type" : TELEMETRY_EVENT_TYPE . PRODUCT_CHANGE })
656
656
657
657
if ints := self ._report_integrations ():
658
- events .append ({"payload" : {"integrations" : ints }, "request_type" : "app-integrations-change" })
658
+ events .append ({"payload" : {"integrations" : ints }, "request_type" : TELEMETRY_EVENT_TYPE . INTEGRATIONS_CHANGE })
659
659
660
660
if endpoints := self ._report_app_endpoints ():
661
- events .append ({"payload" : endpoints , "request_type" : "app-endpoints" })
661
+ events .append ({"payload" : endpoints , "request_type" : TELEMETRY_EVENT_TYPE . ENDPOINTS })
662
662
663
663
if configs := self ._report_configuration_queue ():
664
- events .append ({"payload" : {"configuration" : configs }, "request_type" : "app-client-configuration-change" })
664
+ events .append (
665
+ {
666
+ "payload" : {"configuration" : configs },
667
+ "request_type" : TELEMETRY_EVENT_TYPE .CLIENT_CONFIGURATION_CHANGE ,
668
+ }
669
+ )
665
670
666
671
if deps := self ._report_app_dependencies ():
667
- events .append ({"payload" : {"dependencies" : deps }, "request_type" : "app-dependencies-loaded" })
672
+ events .append ({"payload" : {"dependencies" : deps }, "request_type" : TELEMETRY_EVENT_TYPE . DEPENDENCIES_LOADED })
668
673
669
674
if shutting_down and not self ._forked :
670
- events .append ({"payload" : {}, "request_type" : "app-closing" })
675
+ events .append ({"payload" : {}, "request_type" : TELEMETRY_EVENT_TYPE . SHUTDOWN })
671
676
672
677
# Always include a heartbeat to keep RC connections alive
673
678
# Extended heartbeat should be queued after app-dependencies-loaded event. This
674
679
# ensures that that imported dependencies are accurately reported.
675
680
if heartbeat_payload := self ._app_heartbeat_payload ():
676
681
# Extended heartbeat report dependencies while regular heartbeats report empty payloads
677
- events .append ({"payload" : heartbeat_payload , "request_type" : "app-extended-heartbeat" })
682
+ events .append ({"payload" : heartbeat_payload , "request_type" : TELEMETRY_EVENT_TYPE . EXTENDED_HEARTBEAT })
678
683
else :
679
- events .append ({"payload" : {}, "request_type" : "app-heartbeat" })
684
+ events .append ({"payload" : {}, "request_type" : TELEMETRY_EVENT_TYPE . HEARTBEAT })
680
685
681
686
# Get any queued events and combine with current batch
682
687
if queued_events := self ._flush_events_queue ():
@@ -781,7 +786,7 @@ def _telemetry_excepthook(self, tp, value, root_traceback):
781
786
self .add_integration (integration_name , True , error_msg = error_msg )
782
787
783
788
if app_started := self ._app_started_payload (False ):
784
- self ._events_queue .append ({"payload" : app_started , "request_type" : "app-started" })
789
+ self ._events_queue .append ({"payload" : app_started , "request_type" : TELEMETRY_EVENT_TYPE . STARTED })
785
790
786
791
self .app_shutdown ()
787
792
0 commit comments