Skip to content

ddtrace/tracer: add abandoned spans debugger#2188

Merged
darccio merged 10 commits into
mainfrom
dario.castane/AIT-7944/abandoned-traces
Aug 31, 2023
Merged

ddtrace/tracer: add abandoned spans debugger#2188
darccio merged 10 commits into
mainfrom
dario.castane/AIT-7944/abandoned-traces

Conversation

@darccio

@darccio darccio commented Aug 29, 2023

Copy link
Copy Markdown
Member

What does this PR do?

Refactors and fixes concurrency issues in #2149.

For context, the original PR described the feature as "a debugging mode that the user can configure for finding and logging old, unfinished spans".

The issues fixed are:

  • A deadlock while calling span.String() when log() was generating its output at the same time.
  • Race conditions caused between the debugger and the tests sleeping a fixed time.
  • Tests couldn't be run multiple times using -count because of logSize global variable, as it was modified in the last subtest and never reverted to its original value.
  • Race conditions between the two debugger channels for registering spans starting and finishing. Sometimes, the select statement found both channels ready with values, so it chose one of them randomly.

The refactoring was mainly done in the data structures holding the spans, creating an evolution of the original ones that now avoid iterating over lists, and has reduced complexity.

Reviewer's Checklist

  • Changed code has unit tests for its functionality at or near 100% coverage.
  • There is a benchmark for any new code, or changes to existing code.
  • If this interacts with the agent in a new way, a system test has been added.

For Datadog employees:

  • If this PR touches code that handles credentials of any kind, such as Datadog API keys, I've requested a review from @DataDog/security-design-and-guidance.
  • This PR doesn't touch any of that.

Unsure? Have a question? Request a review!

@darccio
darccio requested review from a team August 29, 2023 13:58
Comment thread ddtrace/tracer/abandonedspans_test.go Outdated
Comment thread ddtrace/tracer/abandonedspans_test.go
Comment thread ddtrace/tracer/abandonedspans.go Outdated
@pr-commenter

pr-commenter Bot commented Aug 29, 2023

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2023-08-31 11:14:54

Comparing candidate commit 74c22fd in PR branch dario.castane/AIT-7944/abandoned-traces with baseline commit 1a1341a in branch main.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 40 metrics, 1 unstable metrics.

Comment thread ddtrace/tracer/abandonedspans_test.go Outdated
Comment thread ddtrace/tracer/abandonedspans_test.go
@darccio
darccio force-pushed the dario.castane/AIT-7944/abandoned-traces branch from c9de9c8 to f535f24 Compare August 29, 2023 15:12
Comment thread ddtrace/tracer/abandonedspans_test.go
@darccio
darccio force-pushed the dario.castane/AIT-7944/abandoned-traces branch from 8d9bac9 to 7802c36 Compare August 29, 2023 15:25

@ahmed-mez ahmed-mez left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Let's just make sure we agree on introducing generics with the team before merging it.

Comment thread ddtrace/tracer/abandonedspans.go
Comment thread ddtrace/tracer/span.go Outdated
Comment thread ddtrace/tracer/tracer.go Outdated
@darccio
darccio force-pushed the dario.castane/AIT-7944/abandoned-traces branch 3 times, most recently from ae4ffdd to cd4c5f0 Compare August 31, 2023 08:56
@darccio

darccio commented Aug 31, 2023

Copy link
Copy Markdown
Member Author

/merge

@dd-devflow

dd-devflow Bot commented Aug 31, 2023

Copy link
Copy Markdown

🚂 MergeQueue

Pull request added to the queue.

This build is going to start soon! (estimated merge in less than 0s)

you can cancel this operation by commenting your pull request with /merge -c!

@dd-devflow

dd-devflow Bot commented Aug 31, 2023

Copy link
Copy Markdown

🚨 MergeQueue

Gitlab CI pipeline didn't start for this change

If you need support, contact us on slack #ci-interfaces with those details!

@darccio

darccio commented Aug 31, 2023

Copy link
Copy Markdown
Member Author

The MergeQueue failed due to some mismatch between Github and Gitlab repositories. CI is working on it.

@darccio
darccio merged commit 16c1f8b into main Aug 31, 2023
@darccio
darccio deleted the dario.castane/AIT-7944/abandoned-traces branch August 31, 2023 11:43
paullegranddc added a commit to DataDog/dd-trace-rs that referenced this pull request Nov 6, 2025
# Motivation

This feature is inspired from the go tracer DataDog/dd-trace-go#2188

It's hard to understand and locate spans that are never finished.
This PR adds a debug mode to the tracer that will track the age and root span name of traces, and
* log warnings from time to time if the traces are older than some amount of time.
* log warning if some traces are still open during tracer shutdown

# Implementation

This feature should not add any cost to the tracer if it is not enabled, but requires storing some extra data associated with each trace.

In order to not use any extra memory if the feature is not enabled, I track it in an additional registry which is only used in debug mode.

This registry tracks the root span name, and the age of the trace.

The debug mode is controlled by 2 new configurations:
* DD_TRACE_DEBUG_OPEN_SPANS
* DD_TRACE_OPEN_SPAN_TIMEOUT

In order to test this feature correctly, I added extra code to intercept and store logs during integration tests.
This is done through a thread local Logger, which is overridden and propagated locally during tests.

Everything is hidden behind the test-utils feature and should thus be zero cost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants