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 secret Sentry DSN value #4210

Merged
merged 2 commits into from
Jan 29, 2025
Merged

Conversation

jmartinesp
Copy link
Member

Content

  • Make the Sentry DSN configurable by either using a gradle property or an env variable.
  • Add extra context logging for Sentry so we can have a better understanding of how the user was using the app before it crashed.

Motivation and context

We realised our DSN entry has been shipped along with the code and it was being used in several forks as is, resulting in wrong bug reports coming into our Sentry dashboard and making it very hard to debug actual issues in the app.

Tests

It's kind of difficult to test: Sentry will silently do nothing AFAICT if the DSN is not provided.

One possible test is to make the app crash and check the issue is not reported, then add the local property or env variable, make it crash again and check the new crash is there.

Tested devices

  • Physical
  • Emulator
  • OS version(s): 14

Checklist

  • Changes have been tested on an Android device or Android emulator with API 24
  • UI change has been tested on both light and dark themes
  • Accessibility has been taken into account. See https://github.com/element-hq/element-x-android/blob/develop/CONTRIBUTING.md#accessibility
  • Pull request is based on the develop branch
  • Pull request title will be used in the release note, it clearly define what will change for the user
  • Pull request includes screenshots or videos if containing UI changes
  • You've made a self review of your PR

We realised our DSN entry has been shipped along with the code and it was being used in several forks as is, resulting in wrong bug reports coming into our Sentry dashboard and making it very hard to debug actual issues in the app.
@jmartinesp jmartinesp added the PR-Build For changes related to build, tools, CI/CD label Jan 28, 2025
@jmartinesp jmartinesp requested a review from a team as a code owner January 28, 2025 15:23
@jmartinesp jmartinesp requested review from bmarty and removed request for a team January 28, 2025 15:23
Copy link
Contributor

github-actions bot commented Jan 28, 2025

📱 Scan the QR code below to install the build (arm64 only) for this PR.
QR code
If you can't scan the QR code you can install the build via this link: https://i.diawi.com/GXiwVj

Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

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

Perfect, thanks for handling this!

@@ -9,7 +9,7 @@ package io.element.android.services.analyticsproviders.sentry

object SentryConfig {
const val NAME = "Sentry"
const val DNS = "https://[email protected]/59"
const val DNS = BuildConfig.SENTRY_DSN
Copy link
Member

Choose a reason for hiding this comment

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

Maybe take the opportunity to fix the typo DNS -> DSN

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops, I completely missed it 😅 .

value = (System.getenv("ELEMENT_ANDROID_SENTRY_DSN")
?: readLocalProperty("services.analyticsproviders.sentry.dsn")
?: ""
).let { "\"$it\"" }
Copy link
Member

Choose a reason for hiding this comment

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

According to the doc:

image

So it's maybe safer to set default value to null, or do not call options.dsn = SentryConfig.DNS if SentryConfig.DNS is empty (maybe the latter is simpler, and we may Timber a warning in this case).

Copy link

codecov bot commented Jan 28, 2025

Codecov Report

Attention: Patch coverage is 0% with 6 lines in your changes missing coverage. Please review.

Project coverage is 80.19%. Comparing base (ebfb47e) to head (a2053db).
Report is 14 commits behind head on develop.

Files with missing lines Patch % Lines
...alyticsproviders/sentry/SentryAnalyticsProvider.kt 0.00% 6 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4210      +/-   ##
===========================================
- Coverage    80.19%   80.19%   -0.01%     
===========================================
  Files         2022     2022              
  Lines        53271    53273       +2     
  Branches      6443     6444       +1     
===========================================
  Hits         42723    42723              
- Misses        8330     8332       +2     
  Partials      2218     2218              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

} else {
Timber.w("No Sentry DSN provided, Sentry will not be initialized")
return
}
Copy link
Member

Choose a reason for hiding this comment

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

I was thinking of something like

val dsn = SentryConfig.DSN.takeIf { it.isNotBlank() }
if (dsn == null)
    Timber.w("No Sentry DSN provided, Sentry will not report anything")
}

but this is probably equivalent.

@jmartinesp jmartinesp merged commit 9b5b762 into develop Jan 29, 2025
26 of 28 checks passed
@jmartinesp jmartinesp deleted the misc/jme/use-secret-sentry-dsn branch January 29, 2025 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR-Build For changes related to build, tools, CI/CD
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants