Skip to content

Commit fdf9c3c

Browse files
fix(telemetry): ensure integrations are queued on startup (#3471) (#3505)
Currently integrations are not sent to the trace agent (telemetry is enabled after patching occurs). This change ensures integrations are queued when ``patch`` or ``patch_all()`` is called. If telemetry is never enabled we will queue configuration data for up to 64 integrations and these values will persist in memory. The cost of each integration entry is ~100 bytes. ## Checklist - [ ] Added to the correct milestone. - [ ] Tests provided or description of manual testing performed is included in the code or PR. - [ ] Library documentation is updated. - [ ] [Corp site](https://github.com/DataDog/documentation/) documentation is updated (link to the PR). (cherry picked from commit 9df403f) Co-authored-by: Munir Abdinur <[email protected]>
1 parent 43de6c2 commit fdf9c3c

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

ddtrace/internal/telemetry/writer.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ def __init__(self, agent_url=None):
4040
# type: (Optional[str]) -> None
4141
super(TelemetryWriter, self).__init__(interval=_get_interval_or_default())
4242

43-
self._enabled = False # type: bool
43+
# _enabled is None at startup, and is only set to true or false
44+
# after the config has been processed
45+
self._enabled = None # type: Optional[bool]
4446
self._agent_url = agent_url or get_trace_url()
4547

4648
self._encoder = JSONEncoderV2()
@@ -145,7 +147,7 @@ def add_integration(self, integration_name, auto_enabled):
145147
:param bool auto_enabled: True if module is enabled in _monkey.PATCH_MODULES
146148
"""
147149
with self._lock:
148-
if not self._enabled:
150+
if self._enabled is not None and not self._enabled:
149151
return
150152

151153
integration = {
@@ -217,17 +219,18 @@ def _restart(self):
217219
def disable(self):
218220
# type: () -> None
219221
"""
220-
Disable the telemetry collection service.
222+
Disable the telemetry collection service and drop the existing integrations and events
221223
Once disabled, telemetry collection can be re-enabled by calling ``enable`` again.
222224
"""
223225
with self._lock:
226+
self._integrations_queue = []
227+
self._enabled = False
224228
if self.status == ServiceStatus.STOPPED:
225229
return
226230

227231
forksafe.unregister(self._restart)
228232

229233
self.stop()
230-
self._enabled = False
231234

232235
self.join()
233236

tests/tracer/telemetry/test_writer.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ def telemetry_writer():
4343
@pytest.fixture
4444
def telemetry_writer_disabled():
4545
telemetry_writer = TelemetryWriter()
46-
# TelemetryWriter should be disabled by default
47-
assert telemetry_writer._enabled is False
46+
# TelemetryWriter _enabled should be None by default
47+
assert telemetry_writer._enabled is None
48+
telemetry_writer._enabled = False
4849
yield telemetry_writer
4950

5051

0 commit comments

Comments
 (0)