diff --git a/src/Sentry.DiagnosticSource/Internal/DiagnosticSource/SentryDiagnosticSubscriber.cs b/src/Sentry.DiagnosticSource/Internal/DiagnosticSource/SentryDiagnosticSubscriber.cs index 1e8fd2c251..3005fb6e20 100644 --- a/src/Sentry.DiagnosticSource/Internal/DiagnosticSource/SentryDiagnosticSubscriber.cs +++ b/src/Sentry.DiagnosticSource/Internal/DiagnosticSource/SentryDiagnosticSubscriber.cs @@ -13,7 +13,9 @@ internal class SentryDiagnosticSubscriber : IObserver // Thus, we will create the instances lazily. private readonly Lazy _efListener; +#if !NETFRAMEWORK private readonly Lazy _sqlListener; +#endif public SentryDiagnosticSubscriber(IHub hub, SentryOptions options) { @@ -23,11 +25,13 @@ public SentryDiagnosticSubscriber(IHub hub, SentryOptions options) return new SentryEFCoreListener(hub, options); }); +#if !NETFRAMEWORK _sqlListener = new Lazy(() => { options.Log(SentryLevel.Debug, "Registering SQL Client integration."); return new SentrySqlListener(hub, options); }); +#endif } public void OnCompleted() { } @@ -44,13 +48,16 @@ public void OnNext(DiagnosticListener listener) break; } +#if !NETFRAMEWORK case "SqlClientDiagnosticListener": { listener.Subscribe(_sqlListener.Value); break; } +#endif } +#if !NETFRAMEWORK // By default, the EF listener will duplicate spans already given by the SQL Client listener. // Thus, we should disable those parts of the EF listener when they are both registered. if (_efListener.IsValueCreated && _sqlListener.IsValueCreated) @@ -59,5 +66,6 @@ public void OnNext(DiagnosticListener listener) efListener.DisableConnectionSpan(); efListener.DisableQuerySpan(); } +#endif } } diff --git a/src/Sentry.DiagnosticSource/Internal/DiagnosticSource/SentrySqlListener.cs b/src/Sentry.DiagnosticSource/Internal/DiagnosticSource/SentrySqlListener.cs index 159aaf141a..d141095386 100644 --- a/src/Sentry.DiagnosticSource/Internal/DiagnosticSource/SentrySqlListener.cs +++ b/src/Sentry.DiagnosticSource/Internal/DiagnosticSource/SentrySqlListener.cs @@ -1,3 +1,7 @@ +// SqlClient's DiagnosticSource integration is not supported on .NET Framework. +// See: https://github.com/dotnet/SqlClient/issues/1529#issuecomment-1063166442 +#if !NETFRAMEWORK + using Sentry.Extensibility; using Sentry.Internal.Extensions; @@ -274,3 +278,5 @@ private void TrySetConnectionStatistics(ISpan span, object? value) } } } + +#endif diff --git a/test/Sentry.DiagnosticSource.Tests/SentrySqlListenerExtensions.cs b/test/Sentry.DiagnosticSource.Tests/SentrySqlListenerExtensions.cs index 5c42679077..da90bafc5f 100644 --- a/test/Sentry.DiagnosticSource.Tests/SentrySqlListenerExtensions.cs +++ b/test/Sentry.DiagnosticSource.Tests/SentrySqlListenerExtensions.cs @@ -1,3 +1,4 @@ +#if !NETFRAMEWORK using Sentry.Internal.DiagnosticSource; namespace Sentry.DiagnosticSource.Tests; @@ -34,3 +35,5 @@ public static void ExecuteQueryFinishWithError(this SentrySqlListener listener, SentrySqlListener.SqlDataWriteCommandError, new { OperationId = operationId, ConnectionId = connectionId, Command = new { CommandText = query } })); } + +#endif diff --git a/test/Sentry.DiagnosticSource.Tests/SentrySqlListenerTests.cs b/test/Sentry.DiagnosticSource.Tests/SentrySqlListenerTests.cs index 17049e6f5b..5db1124f16 100644 --- a/test/Sentry.DiagnosticSource.Tests/SentrySqlListenerTests.cs +++ b/test/Sentry.DiagnosticSource.Tests/SentrySqlListenerTests.cs @@ -1,3 +1,4 @@ +#if !NETFRAMEWORK using Sentry.Internal.DiagnosticSource; using static Sentry.Internal.DiagnosticSource.SentrySqlListener; @@ -685,3 +686,5 @@ public void OnNext_ThrowsException_ExceptionIsolated() Assert.False(exceptionReceived); } } + +#endif