11from http .client import RemoteDisconnected
22import os
33import socket
4+ from typing import TYPE_CHECKING # noqa:F401
45from typing import Dict
5- from typing import Optional
6+ from typing import Optional # noqa:F401
67
78import ddtrace
89from ddtrace import config
1112from ddtrace .internal .ci_visibility .constants import MODULE_TYPE
1213from ddtrace .internal .ci_visibility .constants import SESSION_TYPE
1314from ddtrace .internal .ci_visibility .constants import SUITE_TYPE
14- from ddtrace .internal .logger import get_logger
15- from ddtrace .internal .utils .http import Response
1615from ddtrace .internal .utils .time import StopWatch
17- from ddtrace .vendor .dogstatsd import DogStatsd
16+ from ddtrace .vendor .dogstatsd import DogStatsd # noqa:F401
1817
1918from .. import agent
2019from .. import service
3938from .telemetry .payload import record_endpoint_payload_request_time
4039
4140
42- log = get_logger (__name__ )
41+ if TYPE_CHECKING : # pragma: no cover
42+ from typing import List # noqa:F401
43+
44+ from ddtrace .internal .utils .http import Response # noqa:F401
4345
4446
4547class CIVisibilityEventClient (WriterClientBase ):
46- def __init__ (self ) -> None :
48+ def __init__ (self ):
4749 encoder = CIVisibilityEncoderV01 (0 , 0 )
4850 encoder .set_metadata (
4951 "*" ,
@@ -55,7 +57,7 @@ def __init__(self) -> None:
5557 "_dd.test.is_user_provided_service" : "true" if config ._is_user_provided_service else "false" ,
5658 },
5759 )
58- super ().__init__ (encoder )
60+ super (CIVisibilityEventClient , self ).__init__ (encoder )
5961
6062 def set_metadata (self , event_type : str , metadata : Dict [str , str ]) -> None :
6163 if isinstance (self .encoder , CIVisibilityEncoderV01 ):
@@ -67,16 +69,14 @@ def set_test_session_name(self, test_session_name: str) -> None:
6769
6870
6971class CIVisibilityCoverageClient (WriterClientBase ):
70- def __init__ (
71- self , intake_url : str , headers : Optional [Dict [str , str ]] = None , itr_suite_skipping_mode : bool = False
72- ) -> None :
72+ def __init__ (self , intake_url , headers = None , itr_suite_skipping_mode = False ):
7373 encoder = CIVisibilityCoverageEncoderV02 (0 , 0 )
7474 if itr_suite_skipping_mode :
7575 encoder ._set_itr_suite_skipping_mode (itr_suite_skipping_mode )
7676 self ._intake_url = intake_url
7777 if headers :
7878 self ._headers = headers
79- super ().__init__ (encoder )
79+ super (CIVisibilityCoverageClient , self ).__init__ (encoder )
8080
8181
8282class CIVisibilityProxiedCoverageClient (CIVisibilityCoverageClient ):
@@ -102,18 +102,18 @@ class CIVisibilityWriter(HTTPWriter):
102102
103103 def __init__ (
104104 self ,
105- intake_url : str = "" ,
106- processing_interval : Optional [float ] = None ,
107- timeout : Optional [float ] = None ,
108- dogstatsd : Optional [DogStatsd ] = None ,
109- sync_mode : bool = False ,
110- report_metrics : bool = False , # unused, but required for inheritance
111- api_version : Optional [ str ] = None , # unused, but required for inheritance
112- reuse_connections : Optional [bool ] = None ,
113- headers : Optional [Dict [str , str ]] = None ,
114- use_evp : bool = False ,
115- coverage_enabled : bool = False ,
116- itr_suite_skipping_mode : bool = False ,
105+ intake_url = "" , # type: str
106+ processing_interval = None , # type : Optional[float]
107+ timeout = None , # type : Optional[float]
108+ dogstatsd = None , # type : Optional[DogStatsd]
109+ sync_mode = False , # type: bool
110+ report_metrics = False , # type: bool
111+ api_version = None , # type: Optional[str]
112+ reuse_connections = None , # type : Optional[bool]
113+ headers = None , # type : Optional[Dict[str, str]]
114+ use_evp = False , # type: bool
115+ coverage_enabled = False , # type: bool
116+ itr_suite_skipping_mode = False , # type: bool
117117 ):
118118 if processing_interval is None :
119119 processing_interval = config ._trace_writer_interval_seconds
@@ -129,15 +129,9 @@ def __init__(
129129 if not intake_url :
130130 intake_url = "%s.%s" % (AGENTLESS_BASE_URL , os .getenv ("DD_SITE" , AGENTLESS_DEFAULT_SITE ))
131131
132- ## Validate API key if headers are provided
133- # if headers and "dd-api-key" in headers and not headers["dd-api-key"]:
134- # log.warning("Empty API key provided to CIVisibilityWriter. This may cause authentication issues.")
135- # # Remove empty API key to prevent sending empty credentials
136- # headers = {k: v for k, v in headers.items() if k != "dd-api-key"}
137-
138- clients : list [WriterClientBase ] = (
132+ clients = (
139133 [CIVisibilityProxiedEventClient ()] if use_evp else [CIVisibilityAgentlessEventClient ()]
140- )
134+ ) # type: List[WriterClientBase]
141135 if coverage_enabled :
142136 if not intake_cov_url :
143137 intake_cov_url = "%s.%s" % (AGENTLESS_COVERAGE_BASE_URL , os .getenv ("DD_SITE" , AGENTLESS_DEFAULT_SITE ))
@@ -153,23 +147,23 @@ def __init__(
153147 )
154148 )
155149
156- super ().__init__ (
150+ super (CIVisibilityWriter , self ).__init__ (
157151 intake_url = intake_url ,
158152 clients = clients ,
159153 processing_interval = processing_interval ,
160154 timeout = timeout ,
161155 dogstatsd = dogstatsd ,
162156 sync_mode = sync_mode ,
163- report_metrics = report_metrics ,
164157 reuse_connections = reuse_connections ,
165158 headers = headers ,
166159 )
167160
168- def stop (self , timeout : Optional [ float ] = None ) -> None :
161+ def stop (self , timeout = None ):
169162 if self .status != service .ServiceStatus .STOPPED :
170- super ().stop (timeout = timeout )
163+ super (CIVisibilityWriter , self ).stop (timeout = timeout )
171164
172- def recreate (self ) -> "CIVisibilityWriter" :
165+ def recreate (self ):
166+ # type: () -> HTTPWriter
173167 return self .__class__ (
174168 intake_url = self .intake_url ,
175169 processing_interval = self ._interval ,
@@ -178,8 +172,9 @@ def recreate(self) -> "CIVisibilityWriter":
178172 sync_mode = self ._sync_mode ,
179173 )
180174
181- def _put (self , data : bytes , headers : Dict [str , str ], client : WriterClientBase , no_trace : bool ) -> Response :
182- request_error : Optional [REQUEST_ERROR_TYPE ] = None
175+ def _put (self , data , headers , client , no_trace ):
176+ # type: (bytes, Dict[str, str], WriterClientBase, bool) -> Response
177+ request_error = None # type: Optional[REQUEST_ERROR_TYPE]
183178
184179 with StopWatch () as sw :
185180 try :
0 commit comments