Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ internal class SentryDiagnosticSubscriber : IObserver<DiagnosticListener>
// Thus, we will create the instances lazily.

private readonly Lazy<SentryEFCoreListener> _efListener;
#if !NETFRAMEWORK
private readonly Lazy<SentrySqlListener> _sqlListener;
#endif

public SentryDiagnosticSubscriber(IHub hub, SentryOptions options)
{
Expand All @@ -23,11 +25,13 @@ public SentryDiagnosticSubscriber(IHub hub, SentryOptions options)
return new SentryEFCoreListener(hub, options);
});

#if !NETFRAMEWORK
_sqlListener = new Lazy<SentrySqlListener>(() =>
{
options.Log(SentryLevel.Debug, "Registering SQL Client integration.");
return new SentrySqlListener(hub, options);
});
#endif
}

public void OnCompleted() { }
Expand All @@ -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)
Expand All @@ -59,5 +66,6 @@ public void OnNext(DiagnosticListener listener)
efListener.DisableConnectionSpan();
efListener.DisableQuerySpan();
}
#endif
}
}
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -274,3 +278,5 @@ private void TrySetConnectionStatistics(ISpan span, object? value)
}
}
}

#endif
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if !NETFRAMEWORK
using Sentry.Internal.DiagnosticSource;

namespace Sentry.DiagnosticSource.Tests;
Expand Down Expand Up @@ -34,3 +35,5 @@ public static void ExecuteQueryFinishWithError(this SentrySqlListener listener,
SentrySqlListener.SqlDataWriteCommandError,
new { OperationId = operationId, ConnectionId = connectionId, Command = new { CommandText = query } }));
}

#endif
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if !NETFRAMEWORK
using Sentry.Internal.DiagnosticSource;
using static Sentry.Internal.DiagnosticSource.SentrySqlListener;

Expand Down Expand Up @@ -685,3 +686,5 @@ public void OnNext_ThrowsException_ExceptionIsolated()
Assert.False(exceptionReceived);
}
}

#endif
Loading