Skip to content

Commit cb26cc7

Browse files
authored
feat: Add datadog_diagnostics plugin app (#722)
See #692 Testing setup: https://2u-internal.atlassian.net/wiki/spaces/ENG/pages/1173618788/Running+Datadog+in+devstack And then in lms-shell: ``` make requirements pip install ddtrace pip install -e /edx/src/archexp/ ./wrap-datadog.sh ./server.sh ``` Expect to see this log message: `Attached MissingSpanProccessor for Datadog diagnostics` NOTE: This prints "Spans created = 0; spans finished = 0" in devstack when shut down with ctrl-c, but not when restarted due to autoreload (where it prints correct info). Something is initializing Django twice and one span processor is getting span info while the other is printing at shutdown. There's more to debug here, but it seems stable enough to least try deploying it.
1 parent 1d4ba69 commit cb26cc7

File tree

6 files changed

+71
-1
lines changed

6 files changed

+71
-1
lines changed

CHANGELOG.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ Change Log
1414
Unreleased
1515
~~~~~~~~~~
1616

17+
[3.4.0] - 2024-07-10
18+
~~~~~~~~~~~~~~~~~~~~
19+
Added
20+
-----
21+
* Added ``datadog_diagnostics`` plugin app
22+
1723
[3.3.2] - 2024-04-19
1824
~~~~~~~~~~~~~~~~~~~~
1925
Changed

edx_arch_experiments/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
A plugin to include applications under development by the architecture team at 2U.
33
"""
44

5-
__version__ = '3.3.2'
5+
__version__ = '3.4.0'
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Datadog Diagnostics
2+
###################
3+
4+
When installed in the LMS as a plugin app, the ``datadog_diagnostics`` app adds additional logging for debugging our Datadog integration.
5+
6+
This is intended as a temporary situation while we debug the `trace concatenation issue <https://github.com/edx/edx-arch-experiments/issues/692>`_.
7+
8+
Usage
9+
*****
10+
11+
In LMS:
12+
13+
- Install ``edx-arch-experiments`` as a dependency

edx_arch_experiments/datadog_diagnostics/__init__.py

Whitespace-only changes.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
"""
2+
App for emitting additional diagnostic information for the Datadog integration.
3+
"""
4+
5+
import logging
6+
7+
from django.apps import AppConfig
8+
9+
log = logging.getLogger(__name__)
10+
11+
12+
class MissingSpanProcessor:
13+
"""Datadog span processor that logs unfinished spans at shutdown."""
14+
spans_started = 0
15+
spans_finished = 0
16+
open_spans = {}
17+
18+
def on_span_start(self, span):
19+
self.spans_started += 1
20+
self.open_spans[span.span_id] = span
21+
22+
def on_span_finish(self, span):
23+
self.spans_finished += 1
24+
del self.open_spans[span.span_id]
25+
26+
def shutdown(self, _timeout):
27+
log.info(f"Spans created = {self.spans_started}; spans finished = {self.spans_finished}")
28+
for span in self.open_spans.values():
29+
log.error(f"Span created but not finished: {span._pprint()}") # pylint: disable=protected-access
30+
31+
32+
class DatadogDiagnostics(AppConfig):
33+
"""
34+
Django application to log diagnostic information for Datadog.
35+
"""
36+
name = 'edx_arch_experiments.datadog_diagnostics'
37+
38+
# Mark this as a plugin app
39+
plugin_app = {}
40+
41+
def ready(self):
42+
try:
43+
from ddtrace import tracer # pylint: disable=import-outside-toplevel
44+
tracer._span_processors.append(MissingSpanProcessor()) # pylint: disable=protected-access
45+
log.info("Attached MissingSpanProcessor for Datadog diagnostics")
46+
except ImportError:
47+
log.warning(
48+
"Unable to attach MissingSpanProcessor for Datadog diagnostics"
49+
" -- ddtrace module not found."
50+
)

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ def is_requirement(line):
164164
"arch_experiments = edx_arch_experiments.apps:EdxArchExperimentsConfig",
165165
"config_watcher = edx_arch_experiments.config_watcher.apps:ConfigWatcher",
166166
"codejail_service = edx_arch_experiments.codejail_service.apps:CodejailService",
167+
"datadog_diagnostics = edx_arch_experiments.datadog_diagnostics.apps:DatadogDiagnostics",
167168
],
168169
"cms.djangoapp": [
169170
"config_watcher = edx_arch_experiments.config_watcher.apps:ConfigWatcher",

0 commit comments

Comments
 (0)