Skip to content

Commit

Permalink
Set sentry options per-project
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelbraginskiy committed Feb 17, 2025
1 parent e30eec0 commit 4f03daf
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 13 deletions.
12 changes: 12 additions & 0 deletions megamek/src/megamek/MMConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,16 @@ private MMConstants() {
// endregion Magic Numbers That Should Be Enums

public static final String CL_KEY_FILEEXTENTION_BOARD = ".board";

public static final SentryAttributes SENTRY_ATTRIBUTES = new SentryAttributes() {
@Override
public String serverName() {
return "MegaMekClient";
}

@Override
public String dsn() {
return "https://b1720cb789ec56df7df9610dfa463c09@sentry.tapenvy.us/8";
}
};
}
2 changes: 1 addition & 1 deletion megamek/src/megamek/MegaMek.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class MegaMek {
private static final MMLogger logger = MMLogger.create(MegaMek.class);

public static void main(String... args) {
StartupUtil.setupEnvironment(logger);
StartupUtil.setupEnvironment(logger, MMConstants.SENTRY_ATTRIBUTES);


// Second, let's handle logging
Expand Down
5 changes: 5 additions & 0 deletions megamek/src/megamek/SuiteConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,9 @@ protected SuiteConstants() {
public static final String MM_PREFERENCES_FILE = "mmconf/mm.preferences";
public static final String MML_PREFERENCES_FILE = "mmconf/mml.preferences";
// endregion File Paths

public interface SentryAttributes {
String serverName();
String dsn();
}
}
23 changes: 11 additions & 12 deletions megamek/src/megamek/utilities/StartupUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

import javax.swing.*;
import java.io.*;
import java.nio.file.Files;

/**
* Common tasks to be performed when any of the suite programs first start.
Expand All @@ -34,10 +33,11 @@ public final class StartupUtil {
* Enable ObjectInputFilter, logging and Sentry, set global exception handler,
* and other startup tasks to prepare the execution environment.
* @param topLevelLogger The logger for uncaught exceptions
* @param sentryAttributes The parameters for sentry for the specific project being started
*/
public static void setupEnvironment(MMLogger topLevelLogger) {
public static void setupEnvironment(MMLogger topLevelLogger, SuiteConstants.SentryAttributes sentryAttributes) {
setOif();
setSentry();
setSentry(sentryAttributes);
setTooltips();
setExceptionHandler(topLevelLogger);
}
Expand All @@ -61,25 +61,24 @@ private static void setOif() {
ObjectInputFilter.Config.setSerialFilter(sanityInputFilter);
}

private static void setSentry() {
private static void setSentry(SuiteConstants.SentryAttributes sentryAttributes) {
querySentry();
initSentry();
initSentry(sentryAttributes);
}

/**
* // Configure Sentry with defaults. Although the client defaults to enabled, the
* // properties file is used to disable it and additional configuration can be
* // done inside the sentry.properties file. The defaults for everything else
* // is set here.
* Configure Sentry with defaults.
* The properties file is used to disable it and additional configuration can be
* done inside the sentry.properties file. The defaults for everything else is set here.
*/
private static void initSentry() {
private static void initSentry(SuiteConstants.SentryAttributes sentryAttributes) {
Sentry.init(options -> {
options.setEnableExternalConfiguration(true);
options.setDsn("https://b1720cb789ec56df7df9610dfa463c09@sentry.tapenvy.us/8");
options.setDsn(sentryAttributes.dsn());
options.setEnvironment("production");
options.setTracesSampleRate(0.2);
options.setDebug(true);
options.setServerName("MegaMekClient");
options.setServerName(sentryAttributes.serverName());
options.setRelease(SuiteConstants.VERSION.toString());
});

Expand Down

0 comments on commit 4f03daf

Please sign in to comment.