-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add datadog_diagnostics plugin app
See #692
- Loading branch information
Showing
6 changed files
with
71 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Datadog Diagnostics | ||
################### | ||
|
||
When installed in the LMS as a plugin app, the ``datadog_diagnostics`` app adds additional logging for debugging our Datadog integration. | ||
|
||
This is intended as a temporary situation while we debug the `trace concatenation issue <https://github.com/edx/edx-arch-experiments/issues/692>`_. | ||
|
||
Usage | ||
***** | ||
|
||
In LMS: | ||
|
||
- Install ``edx-arch-experiments`` as a dependency |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
""" | ||
App for emitting additional diagnostic information for the Datadog integration. | ||
""" | ||
|
||
from logging import getLogger | ||
|
||
from django.apps import AppConfig | ||
|
||
log = getLogger("missing_span_logger") | ||
|
||
|
||
class MissingSpanProccessor: | ||
"""Datadog span processor that logs unfinished spans at shutdown.""" | ||
spans_started = 0 | ||
spans_finished = 0 | ||
open_spans = {} | ||
|
||
def on_span_start(self, span): | ||
self.spans_started += 1 | ||
self.open_spans[span.span_id] = span | ||
|
||
def on_span_finish(self, span): | ||
self.spans_finished += 1 | ||
del self.open_spans[span.span_id] | ||
|
||
def shutdown(self, _timeout): | ||
log.info(f"Spans created = {self.spans_started}; spans finished = {self.spans_finished}") | ||
for span in self.open_spans.values(): | ||
log.error(f"Span created but not finished: {span._pprint()}") # pylint: disable=protected-access | ||
|
||
|
||
class DatadogDiagnostics(AppConfig): | ||
""" | ||
Django application to log diagnostic information for Datadog. | ||
""" | ||
name = 'edx_arch_experiments.datadog_diagnostics' | ||
|
||
# Mark this as a plugin app | ||
plugin_app = {} | ||
|
||
def ready(self): | ||
try: | ||
from ddtrace import tracer # pylint: disable=import-outside-toplevel | ||
tracer._span_processors.append(MissingSpanProccessor()) # pylint: disable=protected-access | ||
log.info("Attached MissingSpanProccessor for Datadog diagnostics") | ||
except ImportError: | ||
log.warning( | ||
"Unable to attach MissingSpanProccessor for Datadog diagnostics" | ||
" -- ddtrace module not found." | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters