Skip to content

[SqlClient] Polyfill Stopwatch.GetElapsedTime#4300

Merged
martincostello merged 2 commits into
open-telemetry:mainfrom
martincostello:polyfill-stopwatch
Apr 29, 2026
Merged

[SqlClient] Polyfill Stopwatch.GetElapsedTime#4300
martincostello merged 2 commits into
open-telemetry:mainfrom
martincostello:polyfill-stopwatch

Conversation

@martincostello
Copy link
Copy Markdown
Member

Changes

Add a polyfill for Stopwatch.GetElapsedTime() for netstandard2.0 and net462 for reuse in other instrumentation.

Merge requirement checklist

  • CONTRIBUTING guidelines followed (license requirements, nullable enabled, static analysis, etc.)
  • Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • Changes in public API reviewed (if applicable)

Add a polyfill for `Stopwatch.GetElapsedTime()` for `netstandard2.0` and `net462` for reuse in other instrumentation.
@github-actions github-actions Bot added the comp:instrumentation.sqlclient Things related to OpenTelemetry.Instrumentation.SqlClient label Apr 24, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.20%. Comparing base (a8d688f) to head (51fe3ed).
⚠️ Report is 37 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@            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     
Flag Coverage Δ
unittests-Contrib.Shared.Tests 89.38% <ø> (ø)
unittests-Exporter.Geneva 55.10% <ø> (-0.04%) ⬇️
unittests-Exporter.InfluxDB 95.81% <ø> (ø)
unittests-Exporter.Instana 74.86% <ø> (ø)
unittests-Exporter.OneCollector 94.61% <ø> (ø)
unittests-Extensions 90.78% <ø> (ø)
unittests-Extensions.Enrichment 100.00% <ø> (ø)
unittests-Extensions.Enrichment.AspNetCore 86.27% <ø> (ø)
unittests-Extensions.Enrichment.Http 94.33% <ø> (ø)
unittests-Instrumentation.AWS 83.50% <ø> (ø)
unittests-Instrumentation.AspNet 76.61% <ø> (ø)
unittests-Instrumentation.AspNetCore 70.44% <ø> (ø)
unittests-Instrumentation.Cassandra 92.85% <ø> (ø)
unittests-Instrumentation.ConfluentKafka 78.52% <ø> (ø)
unittests-Instrumentation.ElasticsearchClient 80.60% <ø> (ø)
unittests-Instrumentation.EntityFrameworkCore 81.39% <ø> (ø)
unittests-Instrumentation.EventCounters 77.27% <ø> (ø)
unittests-Instrumentation.GrpcCore 91.27% <ø> (ø)
unittests-Instrumentation.GrpcNetClient 73.78% <ø> (ø)
unittests-Instrumentation.Hangfire 88.91% <ø> (ø)
unittests-Instrumentation.Http 74.62% <ø> (ø)
unittests-Instrumentation.Owin 88.62% <ø> (ø)
unittests-Instrumentation.Process 100.00% <ø> (ø)
unittests-Instrumentation.Quartz 78.76% <ø> (ø)
unittests-Instrumentation.Remoting 64.28% <ø> (ø)
unittests-Instrumentation.Runtime 100.00% <ø> (ø)
unittests-Instrumentation.ServiceFabricRemoting 40.83% <ø> (ø)
unittests-Instrumentation.SqlClient 84.36% <100.00%> (-0.21%) ⬇️
unittests-Instrumentation.StackExchangeRedis 93.63% <ø> (ø)
unittests-Instrumentation.Wcf 80.77% <ø> (ø)
unittests-OpAmp.Client 82.92% <ø> (-0.23%) ⬇️
unittests-PersistentStorage 69.13% <ø> (-2.90%) ⬇️
unittests-Resources.AWS 74.49% <ø> (ø)
unittests-Resources.Azure 88.31% <ø> (ø)
unittests-Resources.Container 67.34% <ø> (ø)
unittests-Resources.Gcp 71.42% <ø> (ø)
unittests-Resources.Host 72.26% <ø> (ø)
unittests-Resources.OperatingSystem 76.98% <ø> (ø)
unittests-Resources.Process 100.00% <ø> (ø)
unittests-Resources.ProcessRuntime 79.59% <ø> (ø)
unittests-Sampler.AWS 97.52% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...ion.SqlClient/Implementation/SqlTelemetryHelper.cs 93.47% <100.00%> (-0.76%) ⬇️

... and 8 files with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@martincostello martincostello marked this pull request as ready for review April 24, 2026 14:28
Copilot AI review requested due to automatic review settings April 24, 2026 14:28
@martincostello martincostello requested a review from a team as a code owner April 24, 2026 14:28
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.cs providing a Stopwatch.GetElapsedTime(long) implementation for non-NET TFMs.
  • 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.

Comment thread src/Shared/StopwatchExtensions.cs Outdated
Comment thread src/Shared/StopwatchExtensions.cs
Fix accidentally declaring the extension in the global namespace.
@martincostello martincostello added this pull request to the merge queue Apr 29, 2026
Merged via the queue into open-telemetry:main with commit 8ec3b95 Apr 29, 2026
316 of 317 checks passed
@martincostello martincostello deleted the polyfill-stopwatch branch April 29, 2026 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:instrumentation.sqlclient Things related to OpenTelemetry.Instrumentation.SqlClient

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants