diff --git a/opentelemetry-dotnet-contrib.slnx b/opentelemetry-dotnet-contrib.slnx
index 252df3e1d3..1a4fb2448d 100644
--- a/opentelemetry-dotnet-contrib.slnx
+++ b/opentelemetry-dotnet-contrib.slnx
@@ -214,6 +214,7 @@
+
diff --git a/src/OpenTelemetry.Instrumentation.SqlClient/Implementation/SqlTelemetryHelper.cs b/src/OpenTelemetry.Instrumentation.SqlClient/Implementation/SqlTelemetryHelper.cs
index a0d8f78011..554ea7a2ca 100644
--- a/src/OpenTelemetry.Instrumentation.SqlClient/Implementation/SqlTelemetryHelper.cs
+++ b/src/OpenTelemetry.Instrumentation.SqlClient/Implementation/SqlTelemetryHelper.cs
@@ -93,17 +93,5 @@ public static TagList GetTagListFromConnectionInfo(string? dataSource, string? d
}
internal static double CalculateDurationFromTimestamp(long begin)
- {
-#if NET
- var duration = Stopwatch.GetElapsedTime(begin);
-#else
- var end = Stopwatch.GetTimestamp();
- var timestampToTicks = TimeSpan.TicksPerSecond / (double)Stopwatch.Frequency;
- var delta = end - begin;
- var ticks = (long)(timestampToTicks * delta);
- var duration = new TimeSpan(ticks);
-#endif
-
- return duration.TotalSeconds;
- }
+ => Stopwatch.GetElapsedTime(begin).TotalSeconds;
}
diff --git a/src/OpenTelemetry.Instrumentation.SqlClient/OpenTelemetry.Instrumentation.SqlClient.csproj b/src/OpenTelemetry.Instrumentation.SqlClient/OpenTelemetry.Instrumentation.SqlClient.csproj
index 84763fa654..c26dad640c 100644
--- a/src/OpenTelemetry.Instrumentation.SqlClient/OpenTelemetry.Instrumentation.SqlClient.csproj
+++ b/src/OpenTelemetry.Instrumentation.SqlClient/OpenTelemetry.Instrumentation.SqlClient.csproj
@@ -38,6 +38,7 @@
+
diff --git a/src/Shared/StopwatchExtensions.cs b/src/Shared/StopwatchExtensions.cs
new file mode 100644
index 0000000000..0f88139981
--- /dev/null
+++ b/src/Shared/StopwatchExtensions.cs
@@ -0,0 +1,25 @@
+// Copyright The OpenTelemetry Authors
+// SPDX-License-Identifier: Apache-2.0
+
+#if !NET
+
+namespace System.Diagnostics;
+
+internal static class StopwatchExtensions
+{
+ extension(Stopwatch)
+ {
+ public static TimeSpan GetElapsedTime(long begin)
+ {
+ var end = Stopwatch.GetTimestamp();
+
+ var timestampToTicks = TimeSpan.TicksPerSecond / (double)Stopwatch.Frequency;
+ var delta = end - begin;
+ var ticks = (long)(timestampToTicks * delta);
+
+ return new TimeSpan(ticks);
+ }
+ }
+}
+
+#endif