Skip to content

Commit 5f910a3

Browse files
Ref: EfCore integration. (#1258)
* Add else if condition on EFCore integration.
1 parent cff966f commit 5f910a3

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/Sentry.DiagnosticSource/Internals/DiagnosticSource/SentryEFCoreListener.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public void OnNext(KeyValuePair<string, object?> value)
128128

129129
//Connection Span
130130
//A transaction may or may not show a connection with it.
131-
if (_logConnectionEnabled && value.Key == EFConnectionOpening)
131+
else if (_logConnectionEnabled && value.Key == EFConnectionOpening)
132132
{
133133
AddSpan(SentryEFSpanType.Connection, "db.connection", null);
134134
}

test/Sentry.DiagnosticSource.Tests/SentryEFCoreListenerTests.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace Sentry.DiagnosticSource.Tests
1010
{
1111
public class SentryEFCoreListenerTests
1212
{
13+
internal const string EFQueryStartCompiling = SentryEFCoreListener.EFQueryStartCompiling;
1314
internal const string EFQueryCompiling = SentryEFCoreListener.EFQueryCompiling;
1415
internal const string EFQueryCompiled = SentryEFCoreListener.EFQueryCompiled;
1516
internal const string EFConnectionOpening = SentryEFCoreListener.EFConnectionOpening;
@@ -173,6 +174,27 @@ public void OnNext_TakeSpanButNotSampled_LogWarningNotInvoked(string key, string
173174
Arg.Any<Exception>(),
174175
Arg.Any<object[]>());
175176
}
177+
[Theory]
178+
[InlineData(EFQueryStartCompiling)]
179+
[InlineData(EFQueryCompiling)]
180+
[InlineData(EFQueryCompiled)]
181+
[InlineData(EFConnectionOpening)]
182+
[InlineData(EFConnectionClosed)]
183+
[InlineData(EFCommandExecuting)]
184+
[InlineData(EFCommandFailed)]
185+
[InlineData(EFCommandExecuted)]
186+
public void OnNext_ConfigureScopeInvokedOnce(string key)
187+
{
188+
// Arrange
189+
var hub = _fixture.Hub;
190+
var interceptor = new SentryEFCoreListener(hub, _fixture.Options);
191+
192+
// Act
193+
interceptor.OnNext(new(key, null));
194+
195+
// Assert
196+
hub.Received(1).ConfigureScope(Arg.Any<Action<Scope>>());
197+
}
176198

177199
[Fact]
178200
public void OnNext_HappyPath_IsValid()

0 commit comments

Comments
 (0)