diff --git a/CHANGELOG.md b/CHANGELOG.md
index 14fed51855..96b002b1c0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -27,6 +27,7 @@
### Features
- The SDK now makes use of the new SessionEndStatus `Unhandled` when capturing an unhandled but non-terminal exception, i.e. through the UnobservedTaskExceptionIntegration ([#4633](https://github.com/getsentry/sentry-dotnet/pull/4633), [#4653](https://github.com/getsentry/sentry-dotnet/pull/4653))
+- The SDK now provides a `IsSessionActive` to allow checking the session state ([#4662](https://github.com/getsentry/sentry-dotnet/pull/4662))
- The SDK now makes use of the new SessionEndStatus `Unhandled` when capturing an unhandled but non-terminal exception, i.e. through the UnobservedTaskExceptionIntegration ([#4633](https://github.com/getsentry/sentry-dotnet/pull/4633))
### Fixes
diff --git a/src/Sentry/Extensibility/DisabledHub.cs b/src/Sentry/Extensibility/DisabledHub.cs
index 9592b23023..5144243eed 100644
--- a/src/Sentry/Extensibility/DisabledHub.cs
+++ b/src/Sentry/Extensibility/DisabledHub.cs
@@ -19,6 +19,11 @@ public class DisabledHub : IHub, IDisposable
///
public bool IsEnabled => false;
+ ///
+ /// Always returns false.
+ ///
+ public bool IsSessionActive => false;
+
private DisabledHub()
{
}
diff --git a/src/Sentry/Extensibility/HubAdapter.cs b/src/Sentry/Extensibility/HubAdapter.cs
index 086a1ad351..c864a7b3b9 100644
--- a/src/Sentry/Extensibility/HubAdapter.cs
+++ b/src/Sentry/Extensibility/HubAdapter.cs
@@ -37,6 +37,11 @@ private HubAdapter() { }
///
public SentryStructuredLogger Logger { [DebuggerStepThrough] get => SentrySdk.Logger; }
+ ///
+ /// Forwards the call to .
+ ///
+ public bool IsSessionActive { [DebuggerStepThrough] get => SentrySdk.IsSessionActive; }
+
///
/// Forwards the call to .
///
diff --git a/src/Sentry/IHub.cs b/src/Sentry/IHub.cs
index 1579a7d659..9df09f7d2f 100644
--- a/src/Sentry/IHub.cs
+++ b/src/Sentry/IHub.cs
@@ -88,6 +88,11 @@ public TransactionContext ContinueTrace(
string? name = null,
string? operation = null);
+ ///
+ /// Gets a value indicating whether there is an active session.
+ ///
+ public bool IsSessionActive { get; }
+
///
/// Starts a new session.
///
diff --git a/src/Sentry/Internal/Hub.cs b/src/Sentry/Internal/Hub.cs
index c27e0eb95e..a8bd8e1056 100644
--- a/src/Sentry/Internal/Hub.cs
+++ b/src/Sentry/Internal/Hub.cs
@@ -35,6 +35,8 @@ internal class Hub : IHub, IDisposable
public bool IsEnabled => _isEnabled;
+ public bool IsSessionActive => _sessionManager.IsSessionActive;
+
internal SentryOptions Options => _options;
private Scope CurrentScope => ScopeManager.GetCurrent().Key;
diff --git a/src/Sentry/SentrySdk.cs b/src/Sentry/SentrySdk.cs
index 3df33363f6..d3a296da00 100644
--- a/src/Sentry/SentrySdk.cs
+++ b/src/Sentry/SentrySdk.cs
@@ -751,6 +751,9 @@ public static TransactionContext ContinueTrace(
string? operation = null)
=> CurrentHub.ContinueTrace(traceHeader, baggageHeader, name, operation);
+ ///
+ public static bool IsSessionActive { [DebuggerStepThrough] get => CurrentHub.IsSessionActive; }
+
///
[DebuggerStepThrough]
public static void StartSession()
diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet10_0.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet10_0.verified.txt
index e8d1b7df21..20946b3dcf 100644
--- a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet10_0.verified.txt
+++ b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet10_0.verified.txt
@@ -186,6 +186,7 @@ namespace Sentry
}
public interface IHub : Sentry.ISentryClient, Sentry.ISentryScopeManager
{
+ bool IsSessionActive { get; }
Sentry.SentryId LastEventId { get; }
Sentry.SentryStructuredLogger Logger { get; }
void BindException(System.Exception exception, Sentry.ISpan span);
@@ -826,6 +827,7 @@ namespace Sentry
public static class SentrySdk
{
public static bool IsEnabled { get; }
+ public static bool IsSessionActive { get; }
public static Sentry.SentryId LastEventId { get; }
public static Sentry.SentryStructuredLogger Logger { get; }
public static void AddBreadcrumb(Sentry.Breadcrumb breadcrumb, Sentry.SentryHint? hint = null) { }
@@ -1370,6 +1372,7 @@ namespace Sentry.Extensibility
{
public static readonly Sentry.Extensibility.DisabledHub Instance;
public bool IsEnabled { get; }
+ public bool IsSessionActive { get; }
public Sentry.SentryId LastEventId { get; }
public Sentry.SentryStructuredLogger Logger { get; }
public void BindClient(Sentry.ISentryClient client) { }
@@ -1416,6 +1419,7 @@ namespace Sentry.Extensibility
{
public static readonly Sentry.Extensibility.HubAdapter Instance;
public bool IsEnabled { get; }
+ public bool IsSessionActive { get; }
public Sentry.SentryId LastEventId { get; }
public Sentry.SentryStructuredLogger Logger { get; }
public void AddBreadcrumb(string message, string? category = null, string? type = null, System.Collections.Generic.IDictionary? data = null, Sentry.BreadcrumbLevel level = 0) { }
diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet8_0.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet8_0.verified.txt
index e8d1b7df21..20946b3dcf 100644
--- a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet8_0.verified.txt
+++ b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet8_0.verified.txt
@@ -186,6 +186,7 @@ namespace Sentry
}
public interface IHub : Sentry.ISentryClient, Sentry.ISentryScopeManager
{
+ bool IsSessionActive { get; }
Sentry.SentryId LastEventId { get; }
Sentry.SentryStructuredLogger Logger { get; }
void BindException(System.Exception exception, Sentry.ISpan span);
@@ -826,6 +827,7 @@ namespace Sentry
public static class SentrySdk
{
public static bool IsEnabled { get; }
+ public static bool IsSessionActive { get; }
public static Sentry.SentryId LastEventId { get; }
public static Sentry.SentryStructuredLogger Logger { get; }
public static void AddBreadcrumb(Sentry.Breadcrumb breadcrumb, Sentry.SentryHint? hint = null) { }
@@ -1370,6 +1372,7 @@ namespace Sentry.Extensibility
{
public static readonly Sentry.Extensibility.DisabledHub Instance;
public bool IsEnabled { get; }
+ public bool IsSessionActive { get; }
public Sentry.SentryId LastEventId { get; }
public Sentry.SentryStructuredLogger Logger { get; }
public void BindClient(Sentry.ISentryClient client) { }
@@ -1416,6 +1419,7 @@ namespace Sentry.Extensibility
{
public static readonly Sentry.Extensibility.HubAdapter Instance;
public bool IsEnabled { get; }
+ public bool IsSessionActive { get; }
public Sentry.SentryId LastEventId { get; }
public Sentry.SentryStructuredLogger Logger { get; }
public void AddBreadcrumb(string message, string? category = null, string? type = null, System.Collections.Generic.IDictionary? data = null, Sentry.BreadcrumbLevel level = 0) { }
diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet9_0.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet9_0.verified.txt
index e8d1b7df21..20946b3dcf 100644
--- a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet9_0.verified.txt
+++ b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet9_0.verified.txt
@@ -186,6 +186,7 @@ namespace Sentry
}
public interface IHub : Sentry.ISentryClient, Sentry.ISentryScopeManager
{
+ bool IsSessionActive { get; }
Sentry.SentryId LastEventId { get; }
Sentry.SentryStructuredLogger Logger { get; }
void BindException(System.Exception exception, Sentry.ISpan span);
@@ -826,6 +827,7 @@ namespace Sentry
public static class SentrySdk
{
public static bool IsEnabled { get; }
+ public static bool IsSessionActive { get; }
public static Sentry.SentryId LastEventId { get; }
public static Sentry.SentryStructuredLogger Logger { get; }
public static void AddBreadcrumb(Sentry.Breadcrumb breadcrumb, Sentry.SentryHint? hint = null) { }
@@ -1370,6 +1372,7 @@ namespace Sentry.Extensibility
{
public static readonly Sentry.Extensibility.DisabledHub Instance;
public bool IsEnabled { get; }
+ public bool IsSessionActive { get; }
public Sentry.SentryId LastEventId { get; }
public Sentry.SentryStructuredLogger Logger { get; }
public void BindClient(Sentry.ISentryClient client) { }
@@ -1416,6 +1419,7 @@ namespace Sentry.Extensibility
{
public static readonly Sentry.Extensibility.HubAdapter Instance;
public bool IsEnabled { get; }
+ public bool IsSessionActive { get; }
public Sentry.SentryId LastEventId { get; }
public Sentry.SentryStructuredLogger Logger { get; }
public void AddBreadcrumb(string message, string? category = null, string? type = null, System.Collections.Generic.IDictionary? data = null, Sentry.BreadcrumbLevel level = 0) { }
diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt
index 538d76be9f..252b4599b9 100644
--- a/test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt
+++ b/test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt
@@ -174,6 +174,7 @@ namespace Sentry
}
public interface IHub : Sentry.ISentryClient, Sentry.ISentryScopeManager
{
+ bool IsSessionActive { get; }
Sentry.SentryId LastEventId { get; }
Sentry.SentryStructuredLogger Logger { get; }
void BindException(System.Exception exception, Sentry.ISpan span);
@@ -802,6 +803,7 @@ namespace Sentry
public static class SentrySdk
{
public static bool IsEnabled { get; }
+ public static bool IsSessionActive { get; }
public static Sentry.SentryId LastEventId { get; }
public static Sentry.SentryStructuredLogger Logger { get; }
public static void AddBreadcrumb(Sentry.Breadcrumb breadcrumb, Sentry.SentryHint? hint = null) { }
@@ -1346,6 +1348,7 @@ namespace Sentry.Extensibility
{
public static readonly Sentry.Extensibility.DisabledHub Instance;
public bool IsEnabled { get; }
+ public bool IsSessionActive { get; }
public Sentry.SentryId LastEventId { get; }
public Sentry.SentryStructuredLogger Logger { get; }
public void BindClient(Sentry.ISentryClient client) { }
@@ -1392,6 +1395,7 @@ namespace Sentry.Extensibility
{
public static readonly Sentry.Extensibility.HubAdapter Instance;
public bool IsEnabled { get; }
+ public bool IsSessionActive { get; }
public Sentry.SentryId LastEventId { get; }
public Sentry.SentryStructuredLogger Logger { get; }
public void AddBreadcrumb(string message, string? category = null, string? type = null, System.Collections.Generic.IDictionary? data = null, Sentry.BreadcrumbLevel level = 0) { }