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
Comment on lines +16 to +18

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

thought: indirect consumption

User applications that consume Sentry indirectly, via a netstandard2.0 library that is referenced from a .NET Framework application. In this case there would be a netfx SqlClient, but still the netstandard2.0 asset of Sentry is consumed that includes the SentrySqlListener. But this is a bit of a corner-case, not really a problem (as the SentrySqlListener wouldn't work either way). Also, this would be easily "fixable" in user code by multi-targeting that Sentry-consuming library to net462+.


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

Comment on lines +1 to +4

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

question: docs

Should we mention this limitation of SqlClient on .NET Framework in both our README.md and the docs? (perhaps also linking to the related issue in dotnet/SqlClient)

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