Skip to content

Commit

Permalink
Disable sentry if keys are not set
Browse files Browse the repository at this point in the history
  • Loading branch information
paullinator committed Jun 5, 2024
1 parent bd50d49 commit 42790b2
Show file tree
Hide file tree
Showing 8 changed files with 202 additions and 184 deletions.
262 changes: 134 additions & 128 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,12 @@ def enableProguardInReleaseBuilds = false
* this variant is about 6MiB larger per architecture than default.
*/
def jscFlavor = 'org.webkit:android-jsc:+'
def sentrySlug = "SENTRY_ORGANIZATION_SLUG"

if (!sentrySlug.contains('SENTRY_ORGANIZATION')) {
apply from: new File(["node", "--print", "require.resolve('@sentry/react-native/package.json')"].execute().text.trim(), "../sentry.gradle")
}

apply from: new File(["node", "--print", "require.resolve('@sentry/react-native/package.json')"].execute().text.trim(), "../sentry.gradle")
android {
ndkVersion rootProject.ext.ndkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
Expand Down Expand Up @@ -169,138 +173,140 @@ apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"
import io.sentry.android.gradle.extensions.InstrumentationFeature
import io.sentry.android.gradle.instrumentation.logcat.LogcatLevel

sentry {
// Disables or enables debug log output, e.g. for for sentry-cli.
// Default is disabled.
debug = false

// The slug of the Sentry organization to use for uploading proguard mappings/source contexts.
org = "SENTRY_ORGANIZATION_SLUG"

// The slug of the Sentry project to use for uploading proguard mappings/source contexts.
projectName = "SENTRY_PROJECT_SLUG"

// The authentication token to use for uploading proguard mappings/source contexts.
// WARNING: Do not expose this token in your build.gradle files, but rather set an environment
// variable and read it into this property.
authToken = System.getenv("SENTRY_MAP_UPLOAD_AUTH_TOKEN")

// The url of your Sentry instance. If you're using SAAS (not self hosting) you do not have to
// set this. If you are self hosting you can set your URL here
url = "SENTRY_MAP_UPLOAD_URL"

// Disables or enables the handling of Proguard mapping for Sentry.
// If enabled the plugin will generate a UUID and will take care of
// uploading the mapping to Sentry. If disabled, all the logic
// related to proguard mapping will be excluded.
// Default is enabled.
includeProguardMapping = true

// Whether the plugin should attempt to auto-upload the mapping file to Sentry or not.
// If disabled the plugin will run a dry-run and just generate a UUID.
// The mapping file has to be uploaded manually via sentry-cli in this case.
// Default is enabled.
autoUploadProguardMapping = true

// Experimental flag to turn on support for GuardSquare's tools integration (Dexguard and External Proguard).
// If enabled, the plugin will try to consume and upload the mapping file produced by Dexguard and External Proguard.
// Default is disabled.
dexguardEnabled = false

// Disables or enables the automatic configuration of Native Symbols
// for Sentry. This executes sentry-cli automatically so
// you don't need to do it manually.
// Default is disabled.
uploadNativeSymbols = true

// Whether the plugin should attempt to auto-upload the native debug symbols to Sentry or not.
// If disabled the plugin will run a dry-run.
// Default is enabled.
autoUploadNativeSymbols = true

// Does or doesn't include the source code of native code for Sentry.
// This executes sentry-cli with the --include-sources param. automatically so
// you don't need to do it manually.
// This option has an effect only when [uploadNativeSymbols] is enabled.
// Default is disabled.
includeNativeSources = true

// Generates a JVM (Java, Kotlin, etc.) source bundle and uploads your source code to Sentry.
// This enables source context, allowing you to see your source
// code as part of your stack traces in Sentry.
includeSourceContext = true

// Configure additional directories to be included in the source bundle which is used for
// source context. The directories should be specified relative to the Gradle module/project's
// root. For example, if you have a custom source set alongside 'main', the parameter would be
// 'src/custom/java'.
additionalSourceDirsForSourceContext = []

// Enable or disable the tracing instrumentation.
// Does auto instrumentation for specified features through bytecode manipulation.
// Default is enabled.
tracingInstrumentation {
enabled = true

// Specifies a set of instrumentation features that are eligible for bytecode manipulation.
// Defaults to all available values of InstrumentationFeature enum class.
features = [InstrumentationFeature.DATABASE, InstrumentationFeature.FILE_IO, InstrumentationFeature.OKHTTP, InstrumentationFeature.COMPOSE]

// Enable or disable logcat instrumentation through bytecode manipulation.
if (!sentrySlug.contains('SENTRY_ORGANIZATION')) {
sentry {
// Disables or enables debug log output, e.g. for for sentry-cli.
// Default is disabled.
debug = false

// The slug of the Sentry organization to use for uploading proguard mappings/source contexts.
org = "SENTRY_ORGANIZATION_SLUG"

// The slug of the Sentry project to use for uploading proguard mappings/source contexts.
projectName = "SENTRY_PROJECT_SLUG"

// The authentication token to use for uploading proguard mappings/source contexts.
// WARNING: Do not expose this token in your build.gradle files, but rather set an environment
// variable and read it into this property.
authToken = System.getenv("SENTRY_MAP_UPLOAD_AUTH_TOKEN")

// The url of your Sentry instance. If you're using SAAS (not self hosting) you do not have to
// set this. If you are self hosting you can set your URL here
url = "SENTRY_MAP_UPLOAD_URL"

// Disables or enables the handling of Proguard mapping for Sentry.
// If enabled the plugin will generate a UUID and will take care of
// uploading the mapping to Sentry. If disabled, all the logic
// related to proguard mapping will be excluded.
// Default is enabled.
logcat {
enabled = false
includeProguardMapping = true

// Specifies a minimum log level for the logcat breadcrumb logging.
// Defaults to LogcatLevel.WARNING.
minLevel = LogcatLevel.WARNING
}
// Whether the plugin should attempt to auto-upload the mapping file to Sentry or not.
// If disabled the plugin will run a dry-run and just generate a UUID.
// The mapping file has to be uploaded manually via sentry-cli in this case.
// Default is enabled.
autoUploadProguardMapping = true

// The set of glob patterns to exclude from instrumentation. Classes matching any of these
// patterns in the project's sources and dependencies JARs won't be instrumented by the Sentry
// Gradle plugin.
//
// Don't include the file extension. Filtering is done on compiled classes and
// the .class suffix isn't included in the pattern matching.
//
// Example usage:
// ```
// excludes = ['com/example/donotinstrument/**', '**/*Test']
// ```
//
// Only supported when using Android Gradle plugin (AGP) version 7.4.0 and above.
excludes = []
}
// Experimental flag to turn on support for GuardSquare's tools integration (Dexguard and External Proguard).
// If enabled, the plugin will try to consume and upload the mapping file produced by Dexguard and External Proguard.
// Default is disabled.
dexguardEnabled = false

// Enable auto-installation of Sentry components (sentry-android SDK and okhttp, timber and fragment integrations).
// Default is enabled.
// Only available v3.1.0 and above.
autoInstallation {
enabled = true
// Disables or enables the automatic configuration of Native Symbols
// for Sentry. This executes sentry-cli automatically so
// you don't need to do it manually.
// Default is disabled.
uploadNativeSymbols = true

// Specifies a version of the sentry-android SDK and fragment, timber and okhttp integrations.
//
// This is also useful, when you have the sentry-android SDK already included into a transitive dependency/module and want to
// align integration versions with it (if it's a direct dependency, the version will be inferred).
//
// NOTE: if you have a higher version of the sentry-android SDK or integrations on the classpath, this setting will have no effect
// as Gradle will resolve it to the latest version.
// Whether the plugin should attempt to auto-upload the native debug symbols to Sentry or not.
// If disabled the plugin will run a dry-run.
// Default is enabled.
autoUploadNativeSymbols = true

// Does or doesn't include the source code of native code for Sentry.
// This executes sentry-cli with the --include-sources param. automatically so
// you don't need to do it manually.
// This option has an effect only when [uploadNativeSymbols] is enabled.
// Default is disabled.
includeNativeSources = true

// Generates a JVM (Java, Kotlin, etc.) source bundle and uploads your source code to Sentry.
// This enables source context, allowing you to see your source
// code as part of your stack traces in Sentry.
includeSourceContext = true

// Configure additional directories to be included in the source bundle which is used for
// source context. The directories should be specified relative to the Gradle module/project's
// root. For example, if you have a custom source set alongside 'main', the parameter would be
// 'src/custom/java'.
additionalSourceDirsForSourceContext = []

// Enable or disable the tracing instrumentation.
// Does auto instrumentation for specified features through bytecode manipulation.
// Default is enabled.
tracingInstrumentation {
enabled = true

// Specifies a set of instrumentation features that are eligible for bytecode manipulation.
// Defaults to all available values of InstrumentationFeature enum class.
features = [InstrumentationFeature.DATABASE, InstrumentationFeature.FILE_IO, InstrumentationFeature.OKHTTP, InstrumentationFeature.COMPOSE]

// Enable or disable logcat instrumentation through bytecode manipulation.
// Default is enabled.
logcat {
enabled = false

// Specifies a minimum log level for the logcat breadcrumb logging.
// Defaults to LogcatLevel.WARNING.
minLevel = LogcatLevel.WARNING
}

// The set of glob patterns to exclude from instrumentation. Classes matching any of these
// patterns in the project's sources and dependencies JARs won't be instrumented by the Sentry
// Gradle plugin.
//
// Don't include the file extension. Filtering is done on compiled classes and
// the .class suffix isn't included in the pattern matching.
//
// Example usage:
// ```
// excludes = ['com/example/donotinstrument/**', '**/*Test']
// ```
//
// Only supported when using Android Gradle plugin (AGP) version 7.4.0 and above.
excludes = []
}

// Enable auto-installation of Sentry components (sentry-android SDK and okhttp, timber and fragment integrations).
// Default is enabled.
// Only available v3.1.0 and above.
autoInstallation {
enabled = true

// Specifies a version of the sentry-android SDK and fragment, timber and okhttp integrations.
//
// This is also useful, when you have the sentry-android SDK already included into a transitive dependency/module and want to
// align integration versions with it (if it's a direct dependency, the version will be inferred).
//
// NOTE: if you have a higher version of the sentry-android SDK or integrations on the classpath, this setting will have no effect
// as Gradle will resolve it to the latest version.
//
// Defaults to the latest published Sentry version.
sentryVersion = '7.9.0'
}

// Disables or enables dependencies metadata reporting for Sentry.
// If enabled, the plugin will collect external dependencies and
// upload them to Sentry as part of events. If disabled, all the logic
// related to the dependencies metadata report will be excluded.
//
// Defaults to the latest published Sentry version.
sentryVersion = '7.9.0'
}
// Default is enabled.
includeDependenciesReport = true

// Disables or enables dependencies metadata reporting for Sentry.
// If enabled, the plugin will collect external dependencies and
// upload them to Sentry as part of events. If disabled, all the logic
// related to the dependencies metadata report will be excluded.
//
// Default is enabled.
includeDependenciesReport = true

// Whether the plugin should send telemetry data to Sentry.
// If disabled the plugin won't send telemetry data.
// This is auto disabled if running against a self hosted instance of Sentry.
// Default is enabled.
telemetry = true
// Whether the plugin should send telemetry data to Sentry.
// If disabled the plugin won't send telemetry data.
// This is auto disabled if running against a self hosted instance of Sentry.
// Default is enabled.
telemetry = true
}
}
42 changes: 23 additions & 19 deletions android/app/src/main/java/co/edgesecure/app/MainApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,27 +51,31 @@ class MainApplication : Application(), ReactApplication {
// Retrieve the version string from the app's BuildConfig
val versionString = BuildConfig.VERSION_NAME

SentryAndroid.init(this) { options ->
options.dsn = "SENTRY_DSN_URL"

if (versionString == "99.99.99") {
options.environment = "development"
} else if (versionString.contains("-")) {
options.environment = "testing"
} else {
options.environment = "production"
}
if ("SENTRY_DSN_URL".contains("SENTRY_DSN")) {
// Sentry disabled. Need to add sentry keys to env.json
} else {
SentryAndroid.init(this) { options ->
options.dsn = "SENTRY_DSN_URL"

if (versionString == "99.99.99") {
options.environment = "development"
} else if (versionString.contains("-")) {
options.environment = "testing"
} else {
options.environment = "production"
}

// Add a callback that will be used before the event is sent to Sentry.
// With this callback, you can modify the event or, when returning null, also discard the event.
options.beforeSend =
BeforeSendCallback { event: SentryEvent, hint: Hint ->
if (SentryLevel.DEBUG == event.level) {
null
} else {
event
// Add a callback that will be used before the event is sent to Sentry.
// With this callback, you can modify the event or, when returning null, also discard the event.
options.beforeSend =
BeforeSendCallback { event: SentryEvent, hint: Hint ->
if (SentryLevel.DEBUG == event.level) {
null
} else {
event
}
}
}
}
}

// Disable RTL:
Expand Down
2 changes: 1 addition & 1 deletion android/sentry.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ auth.token=SENTRY_MAP_UPLOAD_AUTH_TOKEN
defaults.org=SENTRY_ORGANIZATION_SLUG
defaults.project=SENTRY_PROJECT_SLUG

defaults.url=https://sentryuploadurl.mydomain.com
defaults.url=SENTRY_MAP_UPLOAD_URL
45 changes: 25 additions & 20 deletions ios/edge/AppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -42,26 +42,31 @@ - (BOOL)application:(UIApplication *)application
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSString *versionString = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
[SentrySDK startWithConfigureOptions:^(SentryOptions *options) {
options.dsn = @"SENTRY_DSN_URL";
options.debug = YES; // Enabled debug when first installing is always helpful

// Check if the version string is equal to "99.99.99" or contains a "-"
if ([versionString isEqualToString:@"99.99.99"]) {
options.environment = @"development";
} else if ([versionString containsString:@"-"]) {
options.environment = @"testing";
} else {
options.environment = @"production";
}

// Enable tracing to capture 100% of transactions for performance monitoring.
// Use 'options.tracesSampleRate' to set the sampling rate.
// We recommend setting a sample rate in production.
// options.enableTracing = YES;
options.tracesSampleRate = @0.2;
options.enableCaptureFailedRequests = NO;
}];
NSString *dsnUrl = @"SENTRY_DSN_URL";
if ([dsnUrl containsString:@"SENTRY_DSN"]) {
NSLog(@"Please set the SENTRY_DSN_URL in env.json. Sentry disabbled");
} else {
[SentrySDK startWithConfigureOptions:^(SentryOptions *options) {
options.dsn = @"SENTRY_DSN_URL";
options.debug = YES; // Enabled debug when first installing is always helpful

// Check if the version string is equal to "99.99.99" or contains a "-"
if ([versionString isEqualToString:@"99.99.99"]) {
options.environment = @"development";
} else if ([versionString containsString:@"-"]) {
options.environment = @"testing";
} else {
options.environment = @"production";
}

// Enable tracing to capture 100% of transactions for performance monitoring.
// Use 'options.tracesSampleRate' to set the sampling rate.
// We recommend setting a sample rate in production.
// options.enableTracing = YES;
options.tracesSampleRate = @0.2;
options.enableCaptureFailedRequests = NO;
}];
}

// React template code:
self.moduleName = @"edge";
Expand Down
2 changes: 1 addition & 1 deletion ios/sentry.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ auth.token=SENTRY_MAP_UPLOAD_AUTH_TOKEN
defaults.org=SENTRY_ORGANIZATION_SLUG
defaults.project=SENTRY_PROJECT_SLUG

defaults.url=https://sentryuploadurl.mydomain.com
defaults.url=SENTRY_MAP_UPLOAD_URL
Loading

0 comments on commit 42790b2

Please sign in to comment.