Skip to content

Add Sentry integration across all MAUI app flavors#153

Merged
Redth merged 2 commits intomainfrom
redth/add-sentry-integration
Apr 17, 2026
Merged

Add Sentry integration across all MAUI app flavors#153
Redth merged 2 commits intomainfrom
redth/add-sentry-integration

Conversation

@Redth
Copy link
Copy Markdown
Owner

@Redth Redth commented Apr 17, 2026

Wires up Sentry error and performance reporting for every MAUI Sherpa app flavor (Mac Catalyst, Windows, standalone macOS/AppKit, and Linux GTK) so we actually have visibility into crashes and exceptions happening in the wild.

Approach

The DSN is never hardcoded. It's injected at build time via a SentryDsn MSBuild property (see Directory.Build.props), which emits an AssemblyMetadata("SentryDsn", ...) attribute only when a value is supplied. A small SentryConfig helper resolves the DSN at startup in this order:

  1. SENTRY_DSN environment variable (handy for local development)
  2. Assembly metadata baked in by CI
  3. Otherwise null, and Sentry initialization is skipped entirely

Both MauiProgram.CreateMauiApp (shared by MauiSherpa head and MauiSherpa.LinuxGtk) and MacOSMauiProgram.CreateMauiApp call builder.UseSentry(...) only when a DSN is present. Config matches the Sentry docs snippet (TracesSampleRate = 1.0, EnableLogs = true), with Debug = true only in DEBUG builds, and Release / Environment populated from AssemblyInformationalVersionAttribute so events are tagged with the app version and commit.

Action required: CI workflow change

The OAuth app used by this session lacks workflow scope, so I couldn't push the companion edits to .github/workflows/build.yml. Please apply this patch manually (it just appends -p:SentryDsn=${{ secrets.SENTRY_DSN }} to the 5 publish steps) and add a SENTRY_DSN repository secret:

--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -151,7 +151,8 @@ jobs:
             -r osx-arm64 \
             -p:CreatePackage=false \
             -p:AppVersion=${{ steps.version.outputs.app_version }} \
-            -p:AppCommitSha=${{ steps.version.outputs.commit_sha }}
+            -p:AppCommitSha=${{ steps.version.outputs.commit_sha }} \
+            -p:SentryDsn=${{ secrets.SENTRY_DSN }}
 
       - name: Publish macOS App (x64)
         run: |
@@ -161,7 +162,8 @@ jobs:
             -r osx-x64 \
             -p:CreatePackage=false \
             -p:AppVersion=${{ steps.version.outputs.app_version }} \
-            -p:AppCommitSha=${{ steps.version.outputs.commit_sha }}
+            -p:AppCommitSha=${{ steps.version.outputs.commit_sha }} \
+            -p:SentryDsn=${{ secrets.SENTRY_DSN }}
 
       - name: Create universal binary
         run: |
@@ -439,7 +441,8 @@ jobs:
             -p:WindowsAppSDKSelfContained=true `
             --self-contained true `
             -p:AppVersion=${{ steps.version.outputs.app_version }} `
-            -p:AppCommitSha=${{ steps.version.outputs.commit_sha }}
+            -p:AppCommitSha=${{ steps.version.outputs.commit_sha }} `
+            -p:SentryDsn=${{ secrets.SENTRY_DSN }}
 
       - name: Publish Windows App (arm64)
         run: |
@@ -451,7 +454,8 @@ jobs:
             -p:WindowsAppSDKSelfContained=true `
             --self-contained true `
             -p:AppVersion=${{ steps.version.outputs.app_version }} `
-            -p:AppCommitSha=${{ steps.version.outputs.commit_sha }}
+            -p:AppCommitSha=${{ steps.version.outputs.commit_sha }} `
+            -p:SentryDsn=${{ secrets.SENTRY_DSN }}
 
       - name: Create ZIP archives
         run: |
@@ -583,6 +587,7 @@ jobs:
             --disable-build-servers \
             -p:AppVersion=${{ steps.version.outputs.app_version }} \
             -p:AppCommitSha=${{ steps.version.outputs.commit_sha }} \
+            -p:SentryDsn=${{ secrets.SENTRY_DSN }} \
             -p:UseSharedCompilation=false \
             -nodeReuse:false \
             -maxcpucount:1 \

Without the secret, builds still succeed and Sentry simply stays disabled.

Notes for review

  • Sentry.Maui 6.4.0 is added to all three app csprojs (MauiSherpa, MauiSherpa.MacOS, MauiSherpa.LinuxGtk).
  • SentryConfig.cs lives in src/MauiSherpa/Services/ and is picked up by the standalone macOS project (via its linked Compile Include) and by the Linux GTK project (via its shared file glob), so there's only one copy.
  • Verified Mac Catalyst and standalone macOS builds pass with 0 errors, and confirmed with strings that the DSN lands in the assembly metadata when -p:SentryDsn=... is passed, and is absent otherwise.

Redth and others added 2 commits April 17, 2026 16:22
Wires up Sentry.Maui for Mac Catalyst, Windows, standalone macOS
(AppKit), and Linux GTK. The DSN is not kept in source: it is injected
at build time via a SentryDsn MSBuild property (Directory.Build.props),
which emits an AssemblyMetadata("SentryDsn", ...) attribute only when
a value is supplied.

A small SentryConfig helper resolves the DSN at startup from (1) the
SENTRY_DSN env var for local dev, then (2) the baked-in assembly
metadata for CI builds, otherwise null, in which case Sentry is not
initialized at all. Both MauiProgram and MacOSMauiProgram call
builder.UseSentry(...) only when a DSN is present, with Release and
Environment populated from AssemblyInformationalVersionAttribute.

The companion CI workflow change (passing -p:SentryDsn=... from a
SENTRY_DSN secret) needs to be applied separately because this OAuth
app lacks the workflow scope; the patch is included in the PR body.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Redth Redth merged commit 52b74f9 into main Apr 17, 2026
7 checks passed
@Redth Redth deleted the redth/add-sentry-integration branch April 17, 2026 20:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant