Skip to content

Commit 7ddacf9

Browse files
authored
Merge branch 'main' into fix-linux-musl-arm64
2 parents 46f3953 + 060d446 commit 7ddacf9

24 files changed

+370
-82
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@
22

33
## Unreleased
44

5+
### Features
6+
7+
- Sentry now includes an EXPERIMENTAL StringStackTraceFactory. This factory isn't as feature rich as the full `SentryStackTraceFactory`. However, it may provide better results if you are compiling your application AOT and not getting useful stack traces from the full stack trace factory. ([#4362](https://github.com/getsentry/sentry-dotnet/pull/4362))
8+
59
### Fixes
610

11+
- Source context for class libraries when running on Android in Release mode ([#4294](https://github.com/getsentry/sentry-dotnet/pull/4294))
712
- Native AOT: don't load SentryNative on unsupported platforms ([#4347](https://github.com/getsentry/sentry-dotnet/pull/4347))
813
- Fixed issue introduced in release 5.12.0 that might prevent other middleware or user code from reading request bodies ([#4373](https://github.com/getsentry/sentry-dotnet/pull/4373))
14+
- SentryTunnelMiddleware overwrites the X-Forwarded-For header ([#4375](https://github.com/getsentry/sentry-dotnet/pull/4375))
915
- Native AOT support for `linux-musl-arm64` ([#4365](https://github.com/getsentry/sentry-dotnet/pull/4365))
1016

1117
### Dependencies

src/Sentry.Android.AssemblyReader/V2/AndroidAssemblyStoreReaderV2.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,19 @@ public static bool TryReadStore(string inputFile, IList<string> supportedAbis, D
100100
return assembly;
101101
}
102102

103+
// If the assembly name ends with .dll or .exe, try to find it without the extension.
103104
if ((IsFileType(".dll") || IsFileType(".exe")) && FindBestAssembly(name[..^4], out assembly))
104105
{
105106
return assembly;
106107
}
107108

109+
// Conversely, if there is no extension, try with the dll extension (sometimes required for class libraries).
110+
// See: https://github.com/getsentry/sentry-dotnet/issues/4278#issuecomment-2986009125
111+
if (!IsFileType(".dll") && !IsFileType(".exe") && FindBestAssembly(name + ".dll", out assembly))
112+
{
113+
return assembly;
114+
}
115+
108116
return null;
109117

110118
bool IsFileType(string extension)
@@ -119,10 +127,12 @@ private bool FindBestAssembly(string name, out ExplorerStoreItem? explorerAssemb
119127
{
120128
if (explorer.AssembliesByName?.TryGetValue(name, out var assembly) is true)
121129
{
130+
_logger?.Invoke("Found best assembly {0} in APK AssemblyStore for target arch {1}", name, explorer.TargetArch);
122131
explorerAssembly = new(explorer, assembly);
123132
return true;
124133
}
125134
}
135+
_logger?.Invoke("No best assembly for {0} in APK AssemblyStore", name);
126136
explorerAssembly = null;
127137
return false;
128138
}

src/Sentry.Android.AssemblyReader/V2/AssemblyStoreExplorer.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ private AssemblyStoreExplorer(Stream storeStream, string path, DebugLogger? logg
3333
{
3434
foreach (var item in Assemblies)
3535
{
36+
logger?.Invoke("Assembly {0} indexed from AssemblyStore {1}", item.Name, path);
3637
dict.Add(item.Name, item);
3738
}
3839
}

src/Sentry.AspNetCore/SentryTunnelMiddleware.cs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Microsoft.AspNetCore.Http;
22
using Microsoft.Extensions.DependencyInjection;
3+
using Microsoft.Extensions.Primitives;
34
using Sentry.Internal.Extensions;
45

56
namespace Sentry.AspNetCore;
@@ -98,10 +99,9 @@ public async Task InvokeAsync(HttpContext context, RequestDelegate next)
9899
Method = HttpMethod.Post,
99100
Content = new StreamContent(memoryStream),
100101
};
101-
var clientIp = context.Connection?.RemoteIpAddress?.ToString();
102-
if (clientIp != null)
102+
if (CreateXForwardedForHeader(context) is { } forwardedFor)
103103
{
104-
sentryRequest.Headers.Add("X-Forwarded-For", context.Connection?.RemoteIpAddress?.ToString());
104+
sentryRequest.Headers.Add("X-Forwarded-For", forwardedFor);
105105
}
106106
var responseMessage = await client.SendAsync(sentryRequest).ConfigureAwait(false);
107107
// We send the response back to the client, whatever it was
@@ -122,6 +122,25 @@ public async Task InvokeAsync(HttpContext context, RequestDelegate next)
122122
}
123123
}
124124

125+
private static string? CreateXForwardedForHeader(HttpContext context)
126+
{
127+
var existingForwardedFor = context.Request.Headers["X-Forwarded-For"];
128+
var clientIp = context.Connection?.RemoteIpAddress?.ToString();
129+
if (clientIp is null)
130+
{
131+
return existingForwardedFor.Count > 0 ? existingForwardedFor.ToString() : null;
132+
}
133+
134+
if (existingForwardedFor.Count == 0)
135+
{
136+
return clientIp;
137+
}
138+
139+
return string.IsNullOrEmpty(existingForwardedFor)
140+
? clientIp
141+
: $"{existingForwardedFor}, {clientIp}";
142+
}
143+
125144
private bool IsHostAllowed(string host) =>
126145
host.EndsWith(".sentry.io", StringComparison.OrdinalIgnoreCase) ||
127146
host.Equals("sentry.io", StringComparison.OrdinalIgnoreCase) ||

src/Sentry.Maui.CommunityToolkit.Mvvm/SentryOptionsExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public static class SentryOptionsExtensions
1212
/// </summary>
1313
public static SentryMauiOptions AddCommunityToolkitIntegration(this SentryMauiOptions options)
1414
{
15-
options.AddDefaultEventBinder<MauiCommunityToolkitMvvmEventsBinder>();
15+
options.AddIntegrationEventBinder<MauiCommunityToolkitMvvmEventsBinder>();
1616
return options;
1717
}
1818
}

src/Sentry.Maui/Internal/MauiButtonEventsBinder.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public void Bind(VisualElement element, Action<BreadcrumbEvent> addBreadcrumb)
2121
/// <inheritdoc />
2222
public void UnBind(VisualElement element)
2323
{
24+
_addBreadcrumbCallback = null;
2425
if (element is Button button)
2526
{
2627
button.Clicked -= OnButtonOnClicked;

src/Sentry.Maui/Internal/MauiImageButtonEventsBinder.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ namespace Sentry.Maui.Internal;
33
/// <inheritdoc />
44
public class MauiImageButtonEventsBinder : IMauiElementEventBinder
55
{
6-
private Action<BreadcrumbEvent>? addBreadcrumbCallback;
6+
private Action<BreadcrumbEvent>? _addBreadcrumbCallback;
77

88
/// <inheritdoc />
99
public void Bind(VisualElement element, Action<BreadcrumbEvent> addBreadcrumb)
1010
{
11-
addBreadcrumbCallback = addBreadcrumb;
11+
_addBreadcrumbCallback = addBreadcrumb;
1212

1313
if (element is ImageButton image)
1414
{
@@ -21,6 +21,7 @@ public void Bind(VisualElement element, Action<BreadcrumbEvent> addBreadcrumb)
2121
/// <inheritdoc />
2222
public void UnBind(VisualElement element)
2323
{
24+
_addBreadcrumbCallback = null;
2425
if (element is ImageButton image)
2526
{
2627
image.Clicked -= OnButtonOnClicked;
@@ -31,11 +32,11 @@ public void UnBind(VisualElement element)
3132

3233

3334
private void OnButtonOnClicked(object? sender, EventArgs _)
34-
=> addBreadcrumbCallback?.Invoke(new(sender, nameof(ImageButton.Clicked)));
35+
=> _addBreadcrumbCallback?.Invoke(new(sender, nameof(ImageButton.Clicked)));
3536

3637
private void OnButtonOnPressed(object? sender, EventArgs _)
37-
=> addBreadcrumbCallback?.Invoke(new(sender, nameof(ImageButton.Pressed)));
38+
=> _addBreadcrumbCallback?.Invoke(new(sender, nameof(ImageButton.Pressed)));
3839

3940
private void OnButtonOnReleased(object? sender, EventArgs _)
40-
=> addBreadcrumbCallback?.Invoke(new(sender, nameof(ImageButton.Released)));
41+
=> _addBreadcrumbCallback?.Invoke(new(sender, nameof(ImageButton.Released)));
4142
}

src/Sentry.Maui/SentryMauiAppBuilderExtensions.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,16 @@ public static MauiAppBuilder UseSentry(this MauiAppBuilder builder,
5656
services.AddSingleton<IConfigureOptions<SentryMauiOptions>, SentryMauiOptionsSetup>();
5757
services.AddSingleton<Disposer>();
5858

59-
// Resolve the configured options and register any element event binders from these
59+
// Add default event binders
60+
services.AddSingleton<IMauiElementEventBinder, MauiButtonEventsBinder>();
61+
services.AddSingleton<IMauiElementEventBinder, MauiImageButtonEventsBinder>();
62+
services.AddSingleton<IMauiElementEventBinder, MauiGestureRecognizerEventsBinder>();
63+
services.AddSingleton<IMauiElementEventBinder, MauiVisualElementEventsBinder>();
64+
65+
// Resolve the configured options and register any event binders that have been injected by integrations
6066
var options = new SentryMauiOptions();
6167
configureOptions?.Invoke(options);
62-
foreach (var eventBinder in options.DefaultEventBinders)
68+
foreach (var eventBinder in options.IntegrationEventBinders)
6369
{
6470
eventBinder.Register(services);
6571
}

src/Sentry.Maui/SentryMauiOptions.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,14 @@ public SentryMauiOptions()
2323
#if !PLATFORM_NEUTRAL
2424
CacheDirectoryPath = Microsoft.Maui.Storage.FileSystem.CacheDirectory;
2525
#endif
26-
AddDefaultEventBinder<MauiButtonEventsBinder>();
27-
AddDefaultEventBinder<MauiImageButtonEventsBinder>();
28-
AddDefaultEventBinder<MauiGestureRecognizerEventsBinder>();
29-
AddDefaultEventBinder<MauiVisualElementEventsBinder>();
3026
}
3127

32-
internal List<IMauiElementEventBinderRegistration> DefaultEventBinders { get; } = [];
28+
internal List<IMauiElementEventBinderRegistration> IntegrationEventBinders { get; } = [];
3329

34-
internal void AddDefaultEventBinder<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TEventBinder>()
30+
internal void AddIntegrationEventBinder<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TEventBinder>()
3531
where TEventBinder : class, IMauiElementEventBinder
3632
{
37-
DefaultEventBinders.Add(new MauiElementEventBinderRegistration<TEventBinder>());
33+
IntegrationEventBinders.Add(new MauiElementEventBinderRegistration<TEventBinder>());
3834
}
3935

4036
/// <summary>

src/Sentry/Extensibility/ISentryStackTraceFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace Sentry.Extensibility;
22

33
/// <summary>
4-
/// Factory to <see cref="SentryStackTrace" /> from an <see cref="Exception" />.
4+
/// Factory to create a <see cref="SentryStackTrace" /> from an <see cref="Exception" />.
55
/// </summary>
66
public interface ISentryStackTraceFactory
77
{

0 commit comments

Comments
 (0)