[SqlClient] Polyfill Stopwatch.GetElapsedTime#4300
Merged
martincostello merged 2 commits intoApr 29, 2026
Conversation
Add a polyfill for `Stopwatch.GetElapsedTime()` for `netstandard2.0` and `net462` for reuse in other instrumentation.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4300 +/- ##
==========================================
- Coverage 75.28% 75.20% -0.08%
==========================================
Files 467 467
Lines 18449 18443 -6
==========================================
- Hits 13889 13870 -19
- Misses 4560 4573 +13 Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a shared polyfill for Stopwatch.GetElapsedTime(long) to support netstandard2.0 / net462, and updates SqlClient instrumentation to rely on the unified API surface across TFMs.
Changes:
- Introduces
src/Shared/StopwatchExtensions.csproviding aStopwatch.GetElapsedTime(long)implementation for non-NETTFMs. - Simplifies SqlClient duration computation to always use
Stopwatch.GetElapsedTime(begin). - Wires the new shared file into the SqlClient project and solution.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Shared/StopwatchExtensions.cs | Adds a polyfill implementation of Stopwatch.GetElapsedTime for legacy TFMs. |
| src/OpenTelemetry.Instrumentation.SqlClient/OpenTelemetry.Instrumentation.SqlClient.csproj | Links the new shared polyfill file into the SqlClient build. |
| src/OpenTelemetry.Instrumentation.SqlClient/Implementation/SqlTelemetryHelper.cs | Replaces conditional duration calculation with a single Stopwatch.GetElapsedTime call. |
| opentelemetry-dotnet-contrib.slnx | Adds the new shared file to the solution structure. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Fix accidentally declaring the extension in the global namespace.
4 tasks
matt-hensley
approved these changes
Apr 29, 2026
Kielek
approved these changes
Apr 29, 2026
Merged
via the queue into
open-telemetry:main
with commit Apr 29, 2026
8ec3b95
316 of 317 checks passed
This file contains hidden or 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
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.
Changes
Add a polyfill for
Stopwatch.GetElapsedTime()fornetstandard2.0andnet462for reuse in other instrumentation.Merge requirement checklist
Unit tests added/updatedAppropriateCHANGELOG.mdfiles updated for non-trivial changesChanges in public API reviewed (if applicable)