Java Code Examples for io.sentry.Sentry#init()

The following examples show how to use io.sentry.Sentry#init() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SentryUtils.java    From andesite-node with MIT License 6 votes vote down vote up
static void setup(Config config) {
    var client = Sentry.init(config.getString("sentry.dsn"));
    client.setRelease(Version.VERSION);
    client.setTags(parseTags(config.getStringList("sentry.tags")));
    SentryUtils.client = client;
    var loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
    var root = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME);
    
    var sentryAppender = (SentryAppender) root.getAppender(SENTRY_APPENDER_NAME);
    if(sentryAppender == null) {
        sentryAppender = new SentryAppender();
        sentryAppender.setName(SENTRY_APPENDER_NAME);
        sentryAppender.start();
        
        var warningsOrAboveFilter = new ThresholdFilter();
        warningsOrAboveFilter.setLevel(config.getString("sentry.log-level").toUpperCase());
        warningsOrAboveFilter.start();
        sentryAppender.addFilter(warningsOrAboveFilter);
        
        sentryAppender.setContext(loggerContext);
        root.addAppender(sentryAppender);
    }
}
 
Example 2
Source File: SentryHandlerValueFactory.java    From quarkus with Apache License 2.0 6 votes vote down vote up
public RuntimeValue<Optional<Handler>> create(final SentryConfig config) {
    final SentryConfigProvider provider = new SentryConfigProvider(config);
    final Lookup lookup = new Lookup(provider, provider);

    if (!config.enable) {
        // Disable Sentry
        Sentry.init(SentryOptions.from(lookup, Dsn.DEFAULT_DSN));
        return new RuntimeValue<>(Optional.empty());
    }
    if (!config.dsn.isPresent()) {
        throw new ConfigurationException(
                "Configuration key \"quarkus.log.sentry.dsn\" is required when Sentry is enabled, but its value is empty/missing");
    }
    if (!config.inAppPackages.isPresent()) {
        LOG.warn(
                "No 'quarkus.sentry.in-app-packages' was configured, this option is highly recommended as it affects stacktrace grouping and display on Sentry. See https://quarkus.io/guides/logging-sentry#in-app-packages");
    }

    // Init Sentry
    Sentry.init(SentryOptions.from(lookup, config.dsn.get()));
    SentryHandler handler = new SentryHandler();
    handler.setLevel(config.level);
    return new RuntimeValue<>(Optional.of(handler));
}
 
Example 3
Source File: ServerLogger.java    From weMessage with GNU Affero General Public License v3.0 5 votes vote down vote up
static void setServerHook(MessageServer server, ServerConfiguration serverConfiguration){
    try {
        if (USE_SENTRY && serverConfiguration.getConfigJSON().getConfig().getSendCrashReports()) {
            Sentry.init(new SentryConfig(weMessage.SENTRY_DSN, weMessage.WEMESSAGE_VERSION, "production").build());
            Sentry.getStoredClient().addBuilderHelper(new SentryEventHelper());

            isSentryInitialized = true;
        }
    } catch (Exception ex){
        isSentryInitialized = false;
    }

    messageServer = server;
}
 
Example 4
Source File: SentryConfiguration.java    From Lavalink with MIT License 5 votes vote down vote up
public void turnOn(String dsn, Map<String, String> tags) {
    log.info("Turning on sentry");
    SentryClient sentryClient = Sentry.init(dsn);

    if (tags != null) {
        tags.forEach(sentryClient::addTag);
    }

    // set the git commit hash this was build on as the release
    Properties gitProps = new Properties();
    try {
        //noinspection ConstantConditions
        gitProps.load(Launcher.class.getClassLoader().getResourceAsStream("git.properties"));
    } catch (NullPointerException | IOException e) {
        log.error("Failed to load git repo information", e);
    }

    String commitHash = gitProps.getProperty("git.commit.id");
    if (commitHash != null && !commitHash.isEmpty()) {
        log.info("Setting sentry release to commit hash {}", commitHash);
        sentryClient.setRelease(commitHash);
    } else {
        log.warn("No git commit hash found to set up sentry release");
    }

    getSentryLogbackAppender().start();
}
 
Example 5
Source File: TkApp.java    From jpeek with MIT License 5 votes vote down vote up
/**
 * Main Java entry point.
 * @param args Command line args
 * @throws IOException If fails
 */
public static void main(final String... args) throws IOException {
    Sentry.init(
        new PropertiesOf(
            new ResourceOf(
                "org/jpeek/jpeek.properties"
            )
        ).value().getProperty("org.jpeek.sentry")
    );
    new FtCli(
        new TkApp(Files.createTempDirectory("jpeek")),
        args
    ).start(Exit.NEVER);
}
 
Example 6
Source File: Entrance.java    From jare with MIT License 5 votes vote down vote up
/**
 * Main entry point.
 * @param args Arguments
 * @throws IOException If fails
 */
public static void main(final String... args) throws IOException {
    Sentry.init(Manifests.read("Jare-SentryDsn"));
    final Base base = new CdBase(new DyBase());
    new Logs(
        base,
        new Region.Simple(
            Manifests.read("Jare-S3Key"),
            Manifests.read("Jare-S3Secret")
        ).bucket("logs.jare.io")
    );
    new FtCli(new TkApp(base), args).start(Exit.NEVER);
}
 
Example 7
Source File: StdErrorReporter.java    From linstor-server with GNU General Public License v3.0 4 votes vote down vote up
public StdErrorReporter(
    String moduleName,
    Path logDirectory,
    boolean printStackTraces,
    String nodeName,
    String logLevelRef,
    String linstorLogLevelRef,
    Provider<AccessContext> peerCtxProviderRef
)
{
    super(moduleName, printStackTraces, nodeName);
    this.baseLogDirectory = logDirectory;
    peerCtxProvider = peerCtxProviderRef;
    mainLogger = org.slf4j.LoggerFactory.getLogger(LinStor.PROGRAM + "/" + moduleName);

    // check if the log directory exists, generate if not
    File logDir = baseLogDirectory.toFile();
    if (!logDir.exists())
    {
        if(!logDir.mkdirs())
        {
            logError("Unable to create log directory: " + logDir);
        }
    }

    if (logLevelRef != null)
    {
        try
        {
            String linstorLogLevel = linstorLogLevelRef;
            if (linstorLogLevel == null)
            {
                linstorLogLevel = logLevelRef;
            }
            setLogLevelImpl(
                Level.valueOf(logLevelRef.toUpperCase()),
                Level.valueOf(linstorLogLevel.toUpperCase())
            );
        }
        catch (IllegalArgumentException exc)
        {
            logError("Invalid log level '%s'", logLevelRef);
        }
    }

    h2ErrorReporter = new H2ErrorReporter(this);

    logInfo("Log directory set to: '" + logDir + "'");

    System.setProperty("sentry.release", LinStor.VERSION_INFO_PROVIDER.getVersion());
    System.setProperty("sentry.servername", nodeName);
    System.setProperty("sentry.tags", "module:" + moduleName);
    System.setProperty("sentry.stacktrace.app.packages", "com.linbit");
    Sentry.init();
}
 
Example 8
Source File: CoreApplication.java    From zhcet-web with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
    Sentry.init();
    SpringApplication.run(CoreApplication.class, args);
}
 
Example 9
Source File: Variables.java    From SkyBot with GNU Affero General Public License v3.0 4 votes vote down vote up
Variables() {
    this.mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
    this.mapper.enable(JsonParser.Feature.ALLOW_COMMENTS);
    this.mapper.enable(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES);

    DunctebotConfig tmp = null;
    try {
        tmp = this.mapper.readValue(new File("config.json"), DunctebotConfig.class);
    }
    catch (IOException e) {
        e.printStackTrace();
    }

    this.config = tmp;
    if (this.config == null) {
        System.exit(0);
    }

    this.apis = new DuncteApis("Bot " + this.config.discord.token, this.mapper);
    this.commandManager = new CommandManager(this);
    this.blargBot = new BlargBot(this.config.apis.blargbot, this.mapper);

    // Audio Utils needs the client
    final var ytcfg = this.config.apis.youtubeCache;
    this.youtubeCache = new CacheClient(ytcfg.endpoint, ytcfg.token, Executors.newCachedThreadPool((r) -> {
        final Thread thread = new Thread(r, "Cache-Thread");
        thread.setDaemon(true);

        return thread;
    }));

    this.audioUtils = new AudioUtils(this.config.apis, this);
    this.alexflipnote = new Alexflipnote(this.mapper);
    this.weebApi = new WeebApiBuilder(TokenType.WOLKETOKENS)
        .setBotInfo("DuncteBot(SkyBot)", Settings.VERSION, "Production")
        .setToken(this.config.apis.weebSh)
        .build();

    //set the devs
    Settings.DEVELOPERS = this.config.discord.constantSuperUserIds;
    this.googleBaseUrl = "https://www.googleapis.com/customsearch/v1?q=%s&cx=012048784535646064391:v-fxkttbw54" +
        "&hl=en&searchType=image&key=" + this.config.apis.googl + "&safe=off";

    if (config.sentry.enabled) {
        final String env = "&environment=" + (Settings.IS_LOCAL ? "local" : "production");
        Sentry.init(config.sentry.dsn + "?release=" + Settings.VERSION + env);
    }
}
 
Example 10
Source File: SentryLogger.java    From OpenAs2App with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void init(Session session, Map<String, String> parameters) throws OpenAS2Exception {
    super.init(session, parameters);

    Sentry.init(getParameter(SENTRY_DSN, true));
}
 
Example 11
Source File: HeroicCore.java    From heroic with Apache License 2.0 4 votes vote down vote up
/**
 * Start the Heroic core, step by step
 * <p>
 * <p>
 * It sets up the early injector which is responsible for loading all the necessary components
 * to parse a configuration file.
 * <p>
 * <p>
 * Load all the external modules, which are configured in {@link #modules}.
 * <p>
 * <p>
 * Load and build the configuration using the early injector
 * <p>
 * <p>
 * Setup the primary injector which will provide the dependencies to the entire application
 * <p>
 * <p>
 * Run all bootstraps that are configured in {@link #late}
 * <p>
 * <p>
 * Start all the external modules. {@link #startLifeCycles}
 */
public HeroicCoreInstance newInstance() throws Exception {
    final CoreLoadingComponent loading = loadingInjector();

    loadModules(loading);

    final HeroicConfig config = config(loading);

    String sentryDsn = config.sentryDsn();
    if (sentryDsn != null) {
        Sentry.init(sentryDsn);
    }

    enableTracing(config.tracing());

    final CoreEarlyComponent early = earlyInjector(loading, config);
    runBootstrappers(early, this.early);

    // Initialize the instance injector with access to early components.
    final AtomicReference<CoreComponent> injector = new AtomicReference<>();

    final HeroicCoreInstance instance =
        new Instance(loading.async(), injector, early, config, this.late);

    final CoreComponent primary = primaryInjector(early, config, instance);

    primary.loadingLifeCycle().install();

    primary.internalLifeCycleRegistry().scoped("startup future").start(() -> {
        primary.context().resolveStartedFuture();
        primary.usageTracking().reportStartup();
        return primary.async().resolved(null);
    });

    // Update the instance injector, giving dynamic components initialized after this point
    // access to the primary
    // injector.
    injector.set(primary);

    return instance;
}