Skip to content

Prevent leaks for SQL client instrumentation - #2799

Merged
stevejgordon merged 2 commits into
mainfrom
sqlclient-leak
Sep 1, 2026
Merged

stevejgordon merged 2 commits into
mainfrom
sqlclient-leak

Conversation

@stevejgordon

Copy link
Copy Markdown
Contributor

Fixes #2787

@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown

🤖 GitHub comments

Just comment with:

  • run docs-build : Re-trigger the docs validation. (use unformatted text in the comment!)

Copilot AI 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.

🟡 Changes recommended

Orphan cleanup can become quadratic and substantially delay transaction completion under high SQL concurrency.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Prevents SQL instrumentation from retaining orphaned spans by adding bounded lifecycle tracking and safe abandonment.

Changes:

  • Adds PendingSpanStore with expiration, capacity limits, and transaction cleanup.
  • Introduces thread-safe span abandonment and child-duration tracking.
  • Adds comprehensive unit and integration coverage.
File summaries
File Description
test/instrumentations/Elastic.Apm.SqlClient.Tests/SqlClientListenerTests.cs Tests timeout cleanup.
test/instrumentations/Elastic.Apm.SqlClient.Tests/SqlClientDiagnosticListenerUnitTests.cs Tests SQL span lifecycle scenarios.
test/Elastic.Apm.Tests/SpanTests.cs Tests abandonment and current-span behavior.
test/Elastic.Apm.Tests/HelpersTests/PendingSpanStoreTests.cs Tests store eviction and concurrency.
test/Elastic.Apm.Tests/ConstructorTests.cs Generalizes logger assertions.
test/Elastic.Apm.Tests/ChildDurationTimerTests.cs Tests child-duration calculations.
src/profiler/Elastic.Apm.Profiler.Managed/Integrations/AdoNet/DbSpanFactory.cs Uses static span creation.
src/instrumentations/Elastic.Apm.EntityFrameworkCore/EfCoreDiagnosticListener.cs Updates database span creation.
src/instrumentations/Elastic.Apm.EntityFramework6/Ef6Interceptor.cs Updates database span creation.
src/Elastic.Apm/Model/Transaction.cs Adds transaction-ending callbacks.
src/Elastic.Apm/Model/Span.cs Adds abandonment and revised duration tracking.
src/Elastic.Apm/Model/ExecutionSegmentCommon.cs Supports non-current spans.
src/Elastic.Apm/Model/DbSpanCommon.cs Adds static configurable span creation.
src/Elastic.Apm/Instrumentations/SqlClient/SqlClientDiagnosticSubscriber.cs Owns listener/store disposal.
src/Elastic.Apm/Instrumentations/SqlClient/SqlClientDiagnosticListener.cs Tracks and cleans pending SQL spans.
src/Elastic.Apm/Helpers/PendingSpanStore.cs Implements bounded pending-span storage.
Review details
  • Files reviewed: 16/16 changed files
  • Comments generated: 1
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/Elastic.Apm/Model/Span.cs Resolved

Copilot AI 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.

🔵 Needs a closer look

It changes core span/transaction lifecycle and timing bookkeeping (including concurrency-sensitive end/abandon semantics), which warrants careful human validation beyond automated review.

Review details
  • Files reviewed: 16/16 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@stevejgordon
stevejgordon requested a review from a team September 1, 2026 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Potential Memory Leak in SqlClientDiagnosticListener (ConcurrentDictionary<Guid, ISpan> is not released)

3 participants