Add Sentry integration across all MAUI app flavors#153
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
SentryDsnMSBuild property (seeDirectory.Build.props), which emits anAssemblyMetadata("SentryDsn", ...)attribute only when a value is supplied. A smallSentryConfighelper resolves the DSN at startup in this order:SENTRY_DSNenvironment variable (handy for local development)Both
MauiProgram.CreateMauiApp(shared by MauiSherpa head and MauiSherpa.LinuxGtk) andMacOSMauiProgram.CreateMauiAppcallbuilder.UseSentry(...)only when a DSN is present. Config matches the Sentry docs snippet (TracesSampleRate = 1.0,EnableLogs = true), withDebug = trueonly in DEBUG builds, andRelease/Environmentpopulated fromAssemblyInformationalVersionAttributeso events are tagged with the app version and commit.Action required: CI workflow change
The OAuth app used by this session lacks
workflowscope, 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 aSENTRY_DSNrepository secret:Without the secret, builds still succeed and Sentry simply stays disabled.
Notes for review
Sentry.Maui6.4.0 is added to all three app csprojs (MauiSherpa, MauiSherpa.MacOS, MauiSherpa.LinuxGtk).SentryConfig.cslives insrc/MauiSherpa/Services/and is picked up by the standalone macOS project (via its linkedCompile Include) and by the Linux GTK project (via its shared file glob), so there's only one copy.stringsthat the DSN lands in the assembly metadata when-p:SentryDsn=...is passed, and is absent otherwise.