diff --git a/CHANGELOG.md b/CHANGELOG.md index ee7ab5d37f..7fa2f077c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Fixes - Redact Authorization headers before sending events to Sentry ([#4164](https://github.com/getsentry/sentry-dotnet/pull/4164)) +- Remove Strong Naming from Sentry.Hangfire ([#4099](https://github.com/getsentry/sentry-dotnet/pull/4099)) ### Features diff --git a/src/Sentry.Hangfire/Sentry.Hangfire.csproj b/src/Sentry.Hangfire/Sentry.Hangfire.csproj index d2f0ba0aa1..941dd8c94d 100644 --- a/src/Sentry.Hangfire/Sentry.Hangfire.csproj +++ b/src/Sentry.Hangfire/Sentry.Hangfire.csproj @@ -5,6 +5,7 @@ $(PackageTags);Hangfire net9.0;net8.0;net462 enable + false diff --git a/src/Sentry.Hangfire/SentryServerFilter.cs b/src/Sentry.Hangfire/SentryServerFilter.cs index c4cb4f3551..fab9a64212 100644 --- a/src/Sentry.Hangfire/SentryServerFilter.cs +++ b/src/Sentry.Hangfire/SentryServerFilter.cs @@ -17,7 +17,9 @@ public SentryServerFilter() : this(null, null) internal SentryServerFilter(IHub? hub, IDiagnosticLogger? logger) { _hub = hub ?? HubAdapter.Instance; - _logger = logger ?? _hub.GetSentryOptions()?.DiagnosticLogger; +#pragma warning disable CS0618 // Type or member is obsolete + _logger = logger ?? _hub.GetInternalSentryOptions()?.DiagnosticLogger; +#pragma warning restore CS0618 // Type or member is obsolete } public void OnPerforming(PerformingContext context) diff --git a/src/Sentry/Sentry.csproj b/src/Sentry/Sentry.csproj index 256506c9f3..6db7048663 100644 --- a/src/Sentry/Sentry.csproj +++ b/src/Sentry/Sentry.csproj @@ -173,7 +173,6 @@ - diff --git a/src/Sentry/SentryClientExtensions.cs b/src/Sentry/SentryClientExtensions.cs index 2af8b85f8c..73d394f205 100644 --- a/src/Sentry/SentryClientExtensions.cs +++ b/src/Sentry/SentryClientExtensions.cs @@ -114,4 +114,18 @@ public static Task FlushAsync(this ISentryClient client) HubAdapter => SentrySdk.CurrentOptions, _ => SentryOptionsForTestingOnly }; + + /// + /// + /// Gets internal SentryOptions for integrations like Hangfire that don't support strong assembly names. + /// + /// + /// *** This is not meant for external use !!! *** + /// > + /// + /// + /// + [Obsolete("This method is meant for external usage only")] + public static SentryOptions? GetInternalSentryOptions(this ISentryClient clientOrHub) => + clientOrHub.GetSentryOptions(); } diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet8_0.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet8_0.verified.txt index f70df81000..2b8f31a57a 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet8_0.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet8_0.verified.txt @@ -484,6 +484,8 @@ namespace Sentry public static void Flush(this Sentry.ISentryClient client) { } public static void Flush(this Sentry.ISentryClient client, System.TimeSpan timeout) { } public static System.Threading.Tasks.Task FlushAsync(this Sentry.ISentryClient client) { } + [System.Obsolete("This method is meant for external usage only")] + public static Sentry.SentryOptions? GetInternalSentryOptions(this Sentry.ISentryClient clientOrHub) { } } public static class SentryConstants { diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet9_0.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet9_0.verified.txt index f70df81000..2b8f31a57a 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet9_0.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet9_0.verified.txt @@ -484,6 +484,8 @@ namespace Sentry public static void Flush(this Sentry.ISentryClient client) { } public static void Flush(this Sentry.ISentryClient client, System.TimeSpan timeout) { } public static System.Threading.Tasks.Task FlushAsync(this Sentry.ISentryClient client) { } + [System.Obsolete("This method is meant for external usage only")] + public static Sentry.SentryOptions? GetInternalSentryOptions(this Sentry.ISentryClient clientOrHub) { } } public static class SentryConstants { diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt index 3060d147e9..5f9c1d34fe 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt @@ -472,6 +472,8 @@ namespace Sentry public static void Flush(this Sentry.ISentryClient client) { } public static void Flush(this Sentry.ISentryClient client, System.TimeSpan timeout) { } public static System.Threading.Tasks.Task FlushAsync(this Sentry.ISentryClient client) { } + [System.Obsolete("This method is meant for external usage only")] + public static Sentry.SentryOptions? GetInternalSentryOptions(this Sentry.ISentryClient clientOrHub) { } } public static class SentryConstants { diff --git a/test/Sentry.Tests/SentrySdkTests.cs b/test/Sentry.Tests/SentrySdkTests.cs index ed99d7a746..fd6abadb00 100644 --- a/test/Sentry.Tests/SentrySdkTests.cs +++ b/test/Sentry.Tests/SentrySdkTests.cs @@ -676,14 +676,18 @@ public void Implements_Client() [Fact] public void Implements_ClientExtensions() { - var clientExtensions = typeof(SentryClientExtensions).GetMembers(BindingFlags.Public | BindingFlags.Static) + string[] excludedMembers = [nameof(SentryClientExtensions.GetSentryOptions), nameof(SentryClientExtensions.GetInternalSentryOptions)]; + var clientExtensions = typeof(SentryClientExtensions) + .GetMembers(BindingFlags.Public | BindingFlags.Static) + .Where(x => !excludedMembers.Contains(x.Name)) // Remove the extension argument: Method(this ISentryClient client, ... .Select(m => m.ToString()! .Replace($"({typeof(ISentryClient).FullName}", "(") .Replace("(, ", "(")); - var sentrySdk = typeof(SentrySdk).GetMembers(BindingFlags.Public | BindingFlags.Static); - Assert.Empty(clientExtensions.Except(sentrySdk.Select(m => m.ToString()))); + var sentrySdk = typeof(SentrySdk).GetMembers(BindingFlags.Public | BindingFlags.Static); + var values = clientExtensions.Except(sentrySdk.Select(m => m.ToString())); + Assert.Empty(values); } [Fact]