-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Log ancestors of current span when anomaly found #796
Merged
Conversation
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
Datadog believes that a lingering unfinished celery span from a previous request might be becoming the active context for all future Django requests, causing them to become parented to it. To gather evidence, we'll need to learn not just what the trace root span is, but whether there are unexpected intermediary spans as well. There may be a great many ancestors, especially with the trace concatenation in play, so we'll walk upwards from the current span towards the root until a limit is reached. This should allow us to find if the current Django request's span has a parent, and what it is. - New setting `DATADOG_DIAGNOSTICS_LOG_SPAN_DEPTH` to control walk depth - Move anomaly logging to its own method. - Log ancestry of N proximal spans, and adjust formatting of logging to be more compact. Changes relating to testing: - Add comment on how to do manual testing -- calling finish() on the root span lets us fake an anomaly. - Lift `current_span` to early in `log_diagnostics`. This is helpful during manual testing when `DD_DJANGO_INSTRUMENT_MIDDLEWARE=false`, because in that case, the current span *is* the root span. But finishing that span means we can no longer call current_root_span to retrieve it! Retrieving it before that point allows this trick to still work with our code. - Need to move middleware setup out of `setUp` method because we need to be able to adjust Django settings before the middleware is constructed. `run_middleware` now takes an optional `middleware` param. - Add intermediary span in unit tests so that truncation can be more clearly observed, and to help demonstrate that walk and print order is as expected. - Rename test local-root span to be in line with other naming. Don't need the "test_" prefix.
Manual testing: Uncommented
When LMS is started with
When deployed, we're expecting something like the latter, but with additional span lines above the |
robrap
approved these changes
Sep 10, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Datadog believes that a lingering unfinished celery span from a previous request might be becoming the active context for all future Django requests, causing them to become parented to it. To gather evidence, we'll need to learn not just what the trace root span is, but whether there are unexpected intermediary spans as well.
There may be a great many ancestors, especially with the trace concatenation in play, so we'll walk upwards from the current span towards the root until a limit is reached. This should allow us to find if the current Django request's span has a parent, and what it is.
DATADOG_DIAGNOSTICS_LOG_SPAN_DEPTH
to control walk depthChanges relating to testing:
current_span
to early inlog_diagnostics
. This is helpful during manual testing whenDD_DJANGO_INSTRUMENT_MIDDLEWARE=false
, because in that case, the current span is the root span. But finishing that span means we can no longer call current_root_span to retrieve it! Retrieving it before that point allows this trick to still work with our code.setUp
method because we need to be able to adjust Django settings before the middleware is constructed.run_middleware
now takes an optionalmiddleware
param.Merge checklist:
Check off if complete or not applicable: