Skip to content

Commit

Permalink
Merge branch 'feat/4.0.0' into feat/client-dispose-obsolete
Browse files Browse the repository at this point in the history
  • Loading branch information
vaind authored Nov 17, 2023
2 parents d6ecb2f + 2c0d18a commit 7d1d1d0
Show file tree
Hide file tree
Showing 22 changed files with 216 additions and 71 deletions.
48 changes: 32 additions & 16 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,28 @@

## Unreleased

### Fixes

- Don't add WinUI exception integration on mobile platforms ([#2821](https://github.com/getsentry/sentry-dotnet/pull/2821))

### API breaking Changes

#### Removed APIs

- A number of `[Obsolete]` options have been removed ([#2841](https://github.com/getsentry/sentry-dotnet/pull/2841))
- `BeforeSend` - use `SetBeforeSend` instead.
- `BeforeSendTransaction` - use `SetBeforeSendTransaction` instead.
- `BeforeBreadcrumb` - use `SetBeforeBreadcrumb` instead.
- `CreateHttpClientHandler` - use `CreateHttpMessageHandler` instead.
- `ReportAssemblies` - use `ReportAssembliesMode` instead.
- `KeepAggregateException` - This property is no longer used and has no replacement.
- `DisableTaskUnobservedTaskExceptionCapture` method has been renamed to `DisableUnobservedTaskExceptionCapture`.

#### Changed APIs

- `DebugImage` and `DebugMeta` moved to `Sentry.Protocol` namespace. ([#2815](https://github.com/getsentry/sentry-dotnet/pull/2815))
- `SentryClient.Dispose` is no longer obsolete ([#2842](https://github.com/getsentry/sentry-dotnet/pull/2842))

## 4.0.0-alpha.0

This release brings support for .NET 8 Native AOT publishing and cleans up some of the old APIs that have outlived their use.
Expand Down Expand Up @@ -43,14 +65,6 @@ Additionally, we're dropping support for some of the old target frameworks, plea
- Obsolete setter `Sentry.PlatformAbstractions.Runtime.Identifier` has been removed ([2764](https://github.com/getsentry/sentry-dotnet/pull/2764))
- `Sentry.Values<T>` is now internal as it is never exposed in the public API ([#2771](https://github.com/getsentry/sentry-dotnet/pull/2771))
- `TracePropagationTarget` class has been removed, use the `SubstringOrRegexPattern` class instead. ([#2763](https://github.com/getsentry/sentry-dotnet/pull/2763))
- A number of `[Obsolete]` options have been removed ([#2841](https://github.com/getsentry/sentry-dotnet/pull/2841))
- `BeforeSend` - use `SetBeforeSend` instead.
- `BeforeSendTransaction` - use `SetBeforeSendTransaction` instead.
- `BeforeBreadcrumb` - use `SetBeforeBreadcrumb` instead.
- `CreateHttpClientHandler` - use `CreateHttpMessageHandler` instead.
- `ReportAssemblies` - use `ReportAssembliesMode` instead.
- `KeepAggregateException` - This property is no longer used and has no replacement.
- `DisableTaskUnobservedTaskExceptionCapture` method has been renamed to `DisableUnobservedTaskExceptionCapture`.

#### Changed APIs

Expand Down Expand Up @@ -87,20 +101,22 @@ Additionally, we're dropping support for some of the old target frameworks, plea
- `DebugImage.ImageAddress` changed to `long?`. ([#2725](https://github.com/getsentry/sentry-dotnet/pull/2725))
- Contexts now inherits from `IDictionary` rather than `ConcurrentDictionary`. The specific dictionary being used is an implementation detail. ([#2729](https://github.com/getsentry/sentry-dotnet/pull/2729))
- Transaction names for ASP.NET Core are now consistently named `HTTP-VERB /path` (e.g. `GET /home`). Previously the leading forward slash was missing for some endpoints. ([#2808](https://github.com/getsentry/sentry-dotnet/pull/2808))
- `DebugImage` and `DebugMeta` moved to `Sentry.Protocol` namespace. ([#2815](https://github.com/getsentry/sentry-dotnet/pull/2815))
- `SentryClient.Dispose` is no longer obsolete ([#2842](https://github.com/getsentry/sentry-dotnet/pull/2842))

### Fixes

- Don't add WinUI exception integration on mobile platforms ([#2821](https://github.com/getsentry/sentry-dotnet/pull/2821))

### Features

#### Native AOT

Native AOT publishing for compilation support for .NET 7+ has been added to Sentry, Sentry.Serilog, Sentry.Profiling, Sentry.OpenTelemetry and Sentry.NLog. There are some functional differences when publishing Native AOT:
Native AOT publishing support for .NET 8 has been added to Sentry for the following platforms:

- Windows
- Linux
- macOS
- Mac Catalyst
- iOS

There are some functional differences when publishing Native AOT:

- `StackTraceMode.Enhanced` is ignored because it's not available when publishing Native AOT. The mechanism to generate these ehanced stack traces relies heavily on reflection which isn't compatible with trimming.
- `StackTraceMode.Enhanced` is ignored because it's not available when publishing Native AOT. The mechanism to generate these enhanced stack traces relies heavily on reflection which isn't compatible with trimming.
- Reflection cannot be leveraged for JSON Serialization and you may need to use `SentryOptions.AddJsonSerializerContext` to supply a serialization context for types that you'd like to send to Sentry (e.g. in the `Span.Context`). ([#2732](https://github.com/getsentry/sentry-dotnet/pull/2732), [#2793](https://github.com/getsentry/sentry-dotnet/pull/2793))
- WinUI applications: when publishing Native AOT, Sentry isn't able to automatically register an unhandled exception handler because that relies on reflection. You'll need to [register the unhandled event handler manually](https://github.com/getsentry/sentry-dotnet/issues/2778) instead.

Expand Down
4 changes: 2 additions & 2 deletions integration-test/common.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ BeforeAll {
if (-not (Test-Path env:CI))
{
Write-Host "Packaging $name, expected output path: $packagePath"
dotnet pack "$PSScriptRoot/../src/$name" -c Release --nologo --no-restore -p:Version=$packageVersion -p:IsPackable=true | ForEach-Object { Write-Host $_ }
dotnet pack "$PSScriptRoot/../src/$name" -c Release --nologo -p:Version=$packageVersion -p:IsPackable=true | ForEach-Object { Write-Host $_ }
if ($LASTEXITCODE -ne 0)
{
throw "Failed to package $name."
Expand Down Expand Up @@ -161,7 +161,7 @@ BeforeAll {
}

$packageVersion = GetSentryPackageVersion
dotnet add package $package --source $PSScriptRoot/packages --version $packageVersion | ForEach-Object { Write-Host $_ }
dotnet add package $package --source $PSScriptRoot/packages --version $packageVersion --no-restore | ForEach-Object { Write-Host $_ }
if ($LASTEXITCODE -ne 0)
{
throw "Failed to add package dependency to the test app project."
Expand Down
22 changes: 22 additions & 0 deletions integration-test/net4-console/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Sentry;
using Sentry.Extensibility;
using Sentry.Protocol.Envelopes;

// Initialize the Sentry SDK. (It is not necessary to dispose it.)
SentrySdk.Init(options =>
{
options.Dsn = "http://key@127.0.0.1:9999/123";
options.Debug = true;
options.Transport = new FakeTransport();
});

throw new ApplicationException("Something happened!");

internal class FakeTransport : ITransport
{
public virtual Task SendEnvelopeAsync(Envelope envelope, CancellationToken cancellationToken = default)
{
envelope.Serialize(Console.OpenStandardOutput(), null);
return Task.CompletedTask;
}
}
12 changes: 12 additions & 0 deletions integration-test/net4-console/console-app.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net462</TargetFramework>
<RootNamespace>console_app</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>10.0</LangVersion>
<SelfContained>true</SelfContained>
</PropertyGroup>

</Project>
36 changes: 35 additions & 1 deletion integration-test/runtime.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
. $PSScriptRoot/common.ps1

Describe 'Console app (<framework>)' -ForEach @(
Describe 'Console app NativeAOT (<framework>)' -ForEach @(
@{ framework = "net8.0" }
) {
BeforeAll {
Expand Down Expand Up @@ -102,3 +102,37 @@ internal class FakeTransport : ITransport
runConsoleApp $false | Should -AnyElementMatch 'This looks like a standard JIT/AOT application build.'
}
}

# This ensures we don't have a regression for https://github.com/getsentry/sentry-dotnet/issues/2825
Describe 'Console app regression (missing System.Reflection.Metadata)' {
AfterAll {
dotnet remove ./net4-console/console-app.csproj package Sentry
}

It "Ensure System.Reflection.Metadata is not missing" {
$path = './net4-console'
Remove-Item -Recurse -Force -Path @("$path/bin", "$path/obj") -ErrorAction SilentlyContinue
AddPackageReference $path 'Sentry'

function runConsoleApp()
{
$executable = { dotnet run --project $path -c Release }
Write-Host "::group::Executing $executable"
try
{
$executable.Invoke() | ForEach-Object {
Write-Host " $_"
$_
}
}
finally
{
Write-Host "::endgroup::"
}
}

$output = runConsoleApp
$output | Should -Not -AnyElementMatch 'Could not load file or assembly.'
$output | Should -AnyElementMatch '"exception":{"values":\[{"type":"System.ApplicationException","value":"Something happened!"'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<OutputType>Exe</OutputType>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<TargetFramework>net8.0</TargetFramework>
<PublishAot>true</PublishAot>
<TargetFrameworks>net8.0;net6.0;netstandard2.1;netstandard2.0;net462</TargetFrameworks>
<PublishAot Condition="$(TargetFramework.StartsWith('net8'))">true</PublishAot>
</PropertyGroup>

<PropertyGroup>
Expand Down
12 changes: 1 addition & 11 deletions samples/Sentry.Samples.Ios/Sentry.Samples.Ios.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<ImplicitUsings>true</ImplicitUsings>
<SupportedOSPlatformVersion>11.0</SupportedOSPlatformVersion>
<SelfContained>true</SelfContained>
<PublishAot>true</PublishAot>
</PropertyGroup>

<!--
Expand All @@ -19,17 +20,6 @@
<ProjectReference Include="..\..\src\Sentry\Sentry.csproj" />
</ItemGroup>

<!--
Use the arm64 runtime when building on arm64 Macs.
See https://github.com/xamarin/xamarin-macios/issues/17841
-->
<PropertyGroup>
<OSArchitecture>$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)</OSArchitecture>
<!-- Switch to this when running on an actual device -->
<!-- <RuntimeIdentifier Condition="'$(OSArchitecture)' == 'Arm64'">ios-arm64</RuntimeIdentifier>-->
<RuntimeIdentifier Condition="'$(OSArchitecture)' == 'Arm64' And ('$(_iOSRuntimeIdentifier)' == 'iossimulator-x64' Or ('$(_iOSRuntimeIdentifier)' == '' And '$(RuntimeIdentifier)' == ''))">iossimulator-arm64</RuntimeIdentifier>
</PropertyGroup>

<!--
To run on a device, you need to set the CodesignEntitlements property.
-->
Expand Down
2 changes: 2 additions & 0 deletions samples/Sentry.Samples.Maui/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public static MauiApp CreateMauiApp()
// By default, we will send the last 100 breadcrumbs with each event.
// If you want to see everything we can capture from MAUI, you may wish to use a larger value.
options.MaxBreadcrumbs = 1000;

options.Debug = true;
})

.ConfigureFonts(fonts =>
Expand Down
6 changes: 4 additions & 2 deletions samples/Sentry.Samples.Maui/Sentry.Samples.Maui.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>
<PublishReadyToRun>false</PublishReadyToRun>
<PublishAot Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios' or $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">true</PublishAot>

<!-- Display name -->
<ApplicationTitle>Sentry.Samples.Maui</ApplicationTitle>
Expand Down Expand Up @@ -58,11 +59,12 @@
<TargetPlatformIdentifier>$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)'))</TargetPlatformIdentifier>

<RuntimeIdentifier Condition="'$(TargetPlatformIdentifier)' == 'android' And '$(OSArchitecture)' == 'Arm64'">android-arm64</RuntimeIdentifier>
<RuntimeIdentifier Condition="'$(TargetPlatformIdentifier)' == 'ios' And '$(OSArchitecture)' == 'Arm64'">iossimulator-arm64</RuntimeIdentifier>
<RuntimeIdentifier Condition="'$(TargetPlatformIdentifier)' == 'ios' And '$(_IsPublishing)' == 'true'">ios-arm64</RuntimeIdentifier>
<RuntimeIdentifier Condition="'$(TargetPlatformIdentifier)' == 'ios' And '$(OSArchitecture)' == 'Arm64' And '$(_IsPublishing)' != 'true'">iossimulator-arm64</RuntimeIdentifier>
<RuntimeIdentifier Condition="'$(TargetPlatformIdentifier)' == 'maccatalyst' And '$(OSArchitecture)' == 'Arm64'">maccatalyst-arm64</RuntimeIdentifier>

<RuntimeIdentifier Condition="'$(TargetPlatformIdentifier)' == 'android' And '$(OSArchitecture)' == 'x64'">android-x64</RuntimeIdentifier>
<RuntimeIdentifier Condition="'$(TargetPlatformIdentifier)' == 'ios' And '$(OSArchitecture)' == 'x64'">iossimulator-x64</RuntimeIdentifier>
<RuntimeIdentifier Condition="'$(TargetPlatformIdentifier)' == 'ios' And '$(OSArchitecture)' == 'x64' And '$(_IsPublishing)' != 'true'">iossimulator-x64</RuntimeIdentifier>
<RuntimeIdentifier Condition="'$(TargetPlatformIdentifier)' == 'maccatalyst' And '$(OSArchitecture)' == 'x64'">maccatalyst-x64</RuntimeIdentifier>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/Sentry.AspNetCore/Sentry.AspNetCore.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net8.0;net6.0;netstandard2.0</TargetFrameworks>
<PackageTags>$(PackageTags);AspNetCore;MVC</PackageTags>
<Description>Official ASP.NET Core integration for Sentry - Open-source error tracking that helps developers monitor and fix crashes in real time.</Description>
</PropertyGroup>
Expand Down
12 changes: 8 additions & 4 deletions src/Sentry.AspNetCore/SentryTunnelMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ public async Task InvokeAsync(HttpContext context, RequestDelegate next)
var request = context.Request;
if (request.Method == "OPTIONS")
{
headers.Add("Access-Control-Allow-Origin", new[] { (string)request.Headers["Origin"]! });
headers.Add("Access-Control-Allow-Headers", new[] { "Origin, X-Requested-With, Content-Type, Accept" });
headers.Add("Access-Control-Allow-Methods", new[] { "POST, OPTIONS" });
headers.Add("Access-Control-Allow-Credentials", new[] { "true" });
if (request.Headers.TryGetValue("Origin", out var origin) && !string.IsNullOrEmpty(origin))
{
headers.Append("Access-Control-Allow-Origin", (string)origin!);
}

headers.Append("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
headers.Append("Access-Control-Allow-Methods", "POST, OPTIONS");
headers.Append("Access-Control-Allow-Credentials", "true");
response.StatusCode = 200;
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net8.0;net6.0;netstandard2.0</TargetFrameworks>
<PackageTags>$(PackageTags);Azure;Functions;Worker</PackageTags>
<Description>Official Azure Functions Worker SDK integration for Sentry - Open-source error tracking that helps developers monitor and fix crashes in real time.</Description>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Sentry.NLog/Sentry.NLog.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;netstandard2.0;net462</TargetFrameworks>
<TargetFrameworks>net8.0;net6.0;netstandard2.1;netstandard2.0;net462</TargetFrameworks>
<PackageTags>$(PackageTags);Logging;NLog</PackageTags>
<Description>Official NLog integration for Sentry - Open-source error tracking that helps developers monitor and fix crashes in real time.</Description>
<CLSCompliant>true</CLSCompliant>
Expand Down
2 changes: 1 addition & 1 deletion src/Sentry.OpenTelemetry/Sentry.OpenTelemetry.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<Description>Official OpenTelemetry integration for Sentry - Open-source error tracking that helps developers monitor and fix crashes in real time.</Description>
<PackageTags>$(PackageTags);OpenTelemetry</PackageTags>
<TargetFrameworks>net6.0;netstandard2.1;netstandard2.0;net462</TargetFrameworks>
<TargetFrameworks>net8.0;net6.0;netstandard2.1;netstandard2.0;net462</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/Sentry.Serilog/Sentry.Serilog.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;netstandard2.1;netstandard2.0;net462</TargetFrameworks>
<TargetFrameworks>net8.0;net6.0;netstandard2.1;netstandard2.0;net462</TargetFrameworks>
<PackageTags>$(PackageTags);Logging;Serilog</PackageTags>
<Description>Official Serilog integration for Sentry - Open-source error tracking that helps developers monitor and fix crashes in real time.</Description>
<CLSCompliant>true</CLSCompliant>
Expand Down
18 changes: 16 additions & 2 deletions src/Sentry/Internal/DebugStackTrace.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Sentry.Internal.Extensions;
using Sentry.Extensibility;
using Sentry.Native;
using Sentry.Internal.ILSpy;
using Sentry.Protocol;

Expand All @@ -17,8 +16,11 @@ internal class DebugStackTrace : SentryStackTrace
private readonly Dictionary<Guid, int> _debugImageIndexByModule = new();
private const int DebugImageMissing = -1;
private bool _debugImagesMerged;

#if NET6_0_OR_GREATER
private Dictionary<long, DebugImage>? _nativeDebugImages;
private HashSet<long> _usedNativeDebugImages = new();
#endif

/*
* NOTE: While we could improve these regexes, doing so might break exception grouping on the backend.
Expand Down Expand Up @@ -220,6 +222,7 @@ private IEnumerable<SentryStackFrame> CreateFrames(StackTrace stackTrace, bool i
}
}

#if NET6_0_OR_GREATER
/// <summary>
/// Native AOT implementation of CreateFrame.
/// Native frames have only limited method information at runtime (and even that can be disabled).
Expand All @@ -237,7 +240,15 @@ private IEnumerable<SentryStackFrame> CreateFrames(StackTrace stackTrace, bool i
frame.ImageAddress = imageAddress;
frame.InstructionAddress = stackFrame.GetNativeIP();

_nativeDebugImages ??= C.LoadDebugImages(_options.DiagnosticLogger);
#if __ANDROID__
// TODO there will be support for NativeAOT in the future.
_nativeDebugImages ??= new();
#elif __IOS__ || MACCATALYST
_nativeDebugImages ??= Sentry.iOS.C.LoadDebugImages(_options.DiagnosticLogger);
#else
_nativeDebugImages ??= Sentry.Native.C.LoadDebugImages(_options.DiagnosticLogger);
#endif

if (!_usedNativeDebugImages.Contains(imageAddress) && _nativeDebugImages.TryGetValue(imageAddress, out var debugImage))
{
_usedNativeDebugImages.Add(imageAddress);
Expand All @@ -261,6 +272,7 @@ internal static SentryStackFrame ParseNativeAOTToString(string info)
}
return frame;
}
#endif

/// <summary>
/// Default the implementation of CreateFrame.
Expand Down Expand Up @@ -352,7 +364,9 @@ internal static SentryStackFrame ParseNativeAOTToString(string info)
internal SentryStackFrame? CreateFrame(IStackFrame stackFrame)
{
var frame = TryCreateManagedFrame(stackFrame);
#if NET6_0_OR_GREATER
frame ??= TryCreateNativeAOTFrame(stackFrame);
#endif
if (frame is null)
{
return null;
Expand Down
9 changes: 9 additions & 0 deletions src/Sentry/Internal/Enricher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,16 @@ public void Apply(IEventLike eventLike)
// RuntimeInformation.OSDescription is throwing on Mono 5.12
if (!PlatformAbstractions.Runtime.Current.IsMono())
{
#if NETFRAMEWORK
// RuntimeInformation.* throws on .NET Framework on macOS/Linux
try {
eventLike.Contexts.OperatingSystem.RawDescription = RuntimeInformation.OSDescription;
} catch {
eventLike.Contexts.OperatingSystem.RawDescription = Environment.OSVersion.VersionString;
}
#else
eventLike.Contexts.OperatingSystem.RawDescription = RuntimeInformation.OSDescription;
#endif
}
}

Expand Down
Loading

0 comments on commit 7d1d1d0

Please sign in to comment.