Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use .NET 9 - Sentry SDK 5.0.0-alpha.1 #203

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,21 @@ jobs:

- name: Setup Android SDK
uses: android-actions/setup-android@07976c6290703d34c16d382cb36445f98bb43b1f # v3.2.0
with:
log-accepted-android-sdk-licenses: false

- name: Install .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.100

- name: Install Android workload (macOS)
- name: Install Workloads (macOS)
if: matrix.os == 'macos-latest'
run: sudo dotnet workload install maui-android
run: sudo dotnet workload restore

- name: Install Android workload (Windows/Linux)
- name: Install Workloads (Windows/Linux)
if: matrix.os != 'macos-latest'
run: dotnet workload install maui-android
run: dotnet workload restore

- name: Run batch build script
if: matrix.os == 'windows-latest'
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This Dockerfile builds the Server component of Symbol Collector.

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS builder
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS builder
WORKDIR /app

# Copy the whole solution into the first stage
Expand All @@ -16,7 +16,7 @@ RUN ls -lah ./server/
WORKDIR /app/server/src/SymbolCollector.Server/
RUN dotnet publish -c Release -o ../../out

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS runtime
# GCB changes the path to /workspace. If changing the path here, accuont for GCB
WORKDIR /app
COPY --from=builder /app/server/out ./
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ The build script `build.sh` is focused on building **all** the components which
#### Server and Console app

To build the Server, Libraries and the Console app (aka: everything except the Android app) you'll need:
* [.NET 8 SDK](https://dot.net)
* [.NET 9 SDK](https://dot.net)

#### Android app

Expand Down
7 changes: 4 additions & 3 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"sdk": {
"version": "8.0.0",
"rollForward": "latestMinor"
"version": "9.0.100",
"rollForward": "latestMinor",
"allowPrerelease": false
}
}
}
2 changes: 1 addition & 1 deletion run-local.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export apk=src/SymbolCollector.Android/bin/Release/net8.0-android/io.sentry.symbolcollector.android-Signed.apk
export apk=src/SymbolCollector.Android/bin/Release/net9.0-android/io.sentry.symbolcollector.android-Signed.apk
export package=io.sentry.symbolcollector.android
rm $apk
dotnet build src/SymbolCollector.Android -c Release
Expand Down
1 change: 0 additions & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<EmbedUntrackedSources>true</EmbedUntrackedSources>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="All" />
<PackageReference Include="UnoptimizedAssemblyDetector" PrivateAssets="All" />
</ItemGroup>
</Project>
18 changes: 8 additions & 10 deletions src/Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<SentryVersion>4.12.0</SentryVersion>
<SentryVersion>5.0.0-alpha.1</SentryVersion>
</PropertyGroup>

<ItemGroup>
<PackageVersion Include="Sentry.Extensions.Logging" Version="$(SentryVersion)" />
<PackageVersion Include="Sentry.AspNetCore" Version="$(SentryVersion)" />
Expand All @@ -16,14 +15,13 @@
<PackageVersion Include="Serilog.Enrichers.Environment" Version="2.2.0" />
<PackageVersion Include="Serilog.Formatting.Compact" Version="1.1.0" />
<PackageVersion Include="JustEat.StatsD" Version="4.2.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Http.Polly" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageVersion Include="Microsoft.Maui.Essentials" Version="8.0.3" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
<PackageVersion Include="System.Text.Json" Version="8.0.4" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Http.Resilience" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="9.0.0" />
<PackageVersion Include="Microsoft.Maui.Essentials" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.0" />
<PackageVersion Include="System.Text.Json" Version="9.0.0" />
<PackageVersion Include="System.CommandLine.DragonFruit" Version="0.3.0-alpha.21216.1" />
<PackageVersion Include="UnoptimizedAssemblyDetector" Version="0.1.1" />
</ItemGroup>
</Project>
</Project>
21 changes: 10 additions & 11 deletions src/SymbolCollector.Android.Library/Host.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Maui.ApplicationModel;
using Polly.Extensions.Http;
using SymbolCollector.Core;
using Xamarin.Android.Net;
using Context = Android.Content.Context;
Expand Down Expand Up @@ -92,16 +91,16 @@ public static IHost Init(Context context, string dsn)
"Failure in SSL library, usually a protocol error",
};
services.AddTransient<AndroidMessageHandler>();
services.AddHttpClient<ISymbolClient, SymbolClient>()
.ConfigurePrimaryHttpMessageHandler<AndroidMessageHandler>()
.AddPolicyHandler((s, r) =>
HttpPolicyExtensions.HandleTransientHttpError()
// Could be deleted if merged: https://github.com/App-vNext/Polly.Extensions.Http/pull/33
// On Android web get WebException instead of HttpResponseMessage which HandleTransientHttpError covers
.Or<IOException>(e => messages.Any(m => e.Message.Contains(m)))
.Or<WebException>(e => messages.Any(m => e.Message.Contains(m)))
.Or<SocketTimeoutException>()
.SentryPolicy(s));
services.AddHttpClient<ISymbolClient, SymbolClient>();
// .ConfigurePrimaryHttpMessageHandler<AndroidMessageHandler>()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surprised it works (CI does) without this @jamescrosswell

// .AddPolicyHandler((s, r) =>
// HttpPolicyExtensions.HandleTransientHttpError()
// // Could be deleted if merged: https://github.com/App-vNext/Polly.Extensions.Http/pull/33
// // On Android web get WebException instead of HttpResponseMessage which HandleTransientHttpError covers
// .Or<IOException>(e => messages.Any(m => e.Message.Contains(m)))
// .Or<WebException>(e => messages.Any(m => e.Message.Contains(m)))
// .Or<SocketTimeoutException>()
// .SentryPolicy(s));

services.AddSingleton<AndroidUploader>();
services.AddOptions().Configure<SymbolClientOptions>(o =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0-android</TargetFramework>
<TargetFramework>net9.0-android</TargetFramework>
<UseSentryCLI>false</UseSentryCLI>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/SymbolCollector.Android/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
android:versionCode="1"
android:versionName="1.22.0"
package="io.sentry.symbolcollector.android">
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="34" />
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="35" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application android:allowBackup="true"
Expand Down
2 changes: 1 addition & 1 deletion src/SymbolCollector.Android/SymbolCollector.Android.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0-android</TargetFramework>
<TargetFramework>net9.0-android</TargetFramework>
<OutputType>Exe</OutputType>
<!-- Disabled to get this to work with Xamarin.UITest -->
<AndroidUseAssemblyStore>False</AndroidUseAssemblyStore>
Expand Down
38 changes: 34 additions & 4 deletions src/SymbolCollector.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Http.Resilience;
using Microsoft.Extensions.Logging;
using Polly.Extensions.Http;
using Polly;
using Sentry.Protocol;
using Sentry.Profiling;
using SymbolCollector.Core;
Expand Down Expand Up @@ -48,9 +49,38 @@ static async Task<int> Main(
}

s.AddHttpClient<ISymbolClient, SymbolClient>()
.AddPolicyHandler((s, r) =>
HttpPolicyExtensions.HandleTransientHttpError()
.SentryPolicy(s));
.AddResilienceHandler("retry", builder =>
{
builder.AddRetry(new HttpRetryStrategyOptions
{
BackoffType = DelayBackoffType.Exponential,
#if RELEASE
// TODO: Until a proper re-entrancy is built in the clients, let it retry for a while
MaxRetryAttempts = 6,
#else
MaxRetryAttempts = 3,
#endif
OnRetry = arguments =>
{
var data = new Dictionary<string, string>
{
{ "RetryDelay", arguments.RetryDelay.ToString() },
{ "AttemptNumber", arguments.AttemptNumber.ToString() },
{ "Duration", arguments.Duration.ToString() },
{ "ThreadId", Thread.CurrentThread.ManagedThreadId.ToString() }
};
if (arguments.Outcome.Exception is { } e)
{
data.Add("exception", e.ToString());
}

SentrySdk.AddBreadcrumb(
$"Waiting {arguments.RetryDelay} following attempt {arguments.AttemptNumber} failed HTTP request.",
data: data);
return ValueTask.CompletedTask;
}
});
});

s.AddSingleton(Metrics);
s.AddSingleton<ConsoleUploader>();
Expand Down
2 changes: 1 addition & 1 deletion src/SymbolCollector.Console/SymbolCollector.Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<!-- This should be picked up from Directory.Build.props but after adding a dependency to-->
<!-- System.CommandLine.DragonFruit it will fail to `dotnet run` without it set here:-->
<NoWarn Condition="'$(Configuration)' == 'Debug'">$(NoWarn);CS1591</NoWarn>
Expand Down
32 changes: 0 additions & 32 deletions src/SymbolCollector.Core/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,35 +77,3 @@ private static string GetAppSettingsFilePath()
throw new InvalidOperationException($"Configuration file 'appsettings.json' was not found at {fileName}.");
}
}

public static class PollyExtensions
{
public static AsyncRetryPolicy<TResult> SentryPolicy<TResult>(this PolicyBuilder<TResult> policyBuilder, IServiceProvider services) =>
policyBuilder.WaitAndRetryAsync(new[]
{
TimeSpan.FromSeconds(1),
TimeSpan.FromSeconds(3),
TimeSpan.FromSeconds(6),
#if RELEASE
// TODO: Until a proper re-entrancy is built in the clients, add a last hope retry
TimeSpan.FromSeconds(12)
#endif
},
(result, span, retryAttempt, context) =>
{
var sentry = services.GetRequiredService<IHub>();

var data = new Dictionary<string, string> {
{"PollyRetryCount", retryAttempt.ToString()},
{"ThreadId", System.Threading.Thread.CurrentThread.ManagedThreadId.ToString()}
};
if (result.Exception is Exception e)
{
data.Add("exception", e.ToString());
}

sentry.AddBreadcrumb(
$"Waiting {span} following attempt {retryAttempt} failed HTTP request.",
data: data);
});
}
4 changes: 2 additions & 2 deletions src/SymbolCollector.Core/SymbolCollector.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0</TargetFrameworks>
<TargetFrameworks>net9.0</TargetFrameworks>
<UseSentryCLI>false</UseSentryCLI>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Sentry.Extensions.Logging" />
<PackageReference Include="Microsoft.Extensions.Hosting" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" />
<PackageReference Include="Microsoft.Extensions.Http.Resilience" />
<PackageReference Include="System.Text.Json" />
</ItemGroup>

Expand Down
7 changes: 1 addition & 6 deletions src/SymbolCollector.Server/BatchFinalizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,20 @@ public Task CloseBatch(
public class SymsorterBatchFinalizer : IBatchFinalizer
{
private readonly SymbolServiceOptions _options;
private readonly IMetricsPublisher _metrics;
private readonly ILogger<SymsorterBatchFinalizer> _logger;
private readonly ISymbolGcsWriter _gcsWriter;
private readonly BundleIdGenerator _bundleIdGenerator;
private readonly IHub _hub;
private readonly string _symsorterOutputPath;

public SymsorterBatchFinalizer(
IMetricsPublisher metrics,
IOptions<SymbolServiceOptions> options,
ISymbolGcsWriter gcsWriter,
BundleIdGenerator bundleIdGenerator,
IHub hub,
ILogger<SymsorterBatchFinalizer> logger)
{
_options = options?.Value ?? throw new ArgumentNullException(nameof(options));
_metrics = metrics;
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_gcsWriter = gcsWriter ?? throw new ArgumentNullException(nameof(gcsWriter));
_bundleIdGenerator = bundleIdGenerator;
Expand Down Expand Up @@ -89,7 +86,6 @@ traceHeader is not null
? _hub.StartTransaction("CloseBatch", "batch.close", traceHeader)
: _hub.StartTransaction("CloseBatch", "batch.close");

var handle = _metrics.BeginGcsBatchUpload();
_ = Task.Run(async () =>
{
// get logger factory and create a logger for symsorter
Expand Down Expand Up @@ -189,7 +185,6 @@ into fileGroup
{
_logger.LogError(e, "Failed attempting to delete symsorter directory.");
}
handle.Dispose();
}

}, gcsUploadCancellation)
Expand Down Expand Up @@ -292,4 +287,4 @@ private bool SortSymbols(string batchLocation, SymbolUploadBatch batch, string s
_logger.LogInformation("Symsorter processed: {count}", match.Groups["count"].Value);
return false;
}
}
}
4 changes: 4 additions & 0 deletions src/SymbolCollector.Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ private static IHostBuilder CreateHostBuilder(string[] args) =>
o.AddExceptionFilterForType<OperationCanceledException>();
o.MinimumBreadcrumbLevel = LogLevel.Debug;
o.CaptureFailedRequests = true;

// https://github.com/getsentry/symbol-collector/issues/205
// o.CaptureBlockingCalls = true;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should get a lauchdarkly account and test this out with it (+ dogfood our feature flag integration)


o.SetBeforeSend(@event =>
{
// Stop raising warning that endpoint was overriden
Expand Down
Loading
Loading