-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
V0.3.0 - Add possibility to report unexpected exceptions to bugsnag (#6)
* Add feature to provide a bugsnag api key to report unexpected exceptions to bugsnag
- Loading branch information
Showing
14 changed files
with
168 additions
and
30 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
27 changes: 27 additions & 0 deletions
27
src/main/java/io/github/easybill/Contracts/IApplicationConfig.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package io.github.easybill.Contracts; | ||
|
||
import static io.smallrye.config.ConfigMapping.NamingStrategy.VERBATIM; | ||
|
||
import io.quarkus.runtime.annotations.StaticInitSafe; | ||
import io.smallrye.config.ConfigMapping; | ||
import io.smallrye.config.WithName; | ||
import java.util.Optional; | ||
|
||
@StaticInitSafe | ||
@ConfigMapping(prefix = "app", namingStrategy = VERBATIM) | ||
public interface IApplicationConfig { | ||
String version(); | ||
|
||
Artefacts artefacts(); | ||
|
||
interface Artefacts { | ||
String version(); | ||
} | ||
|
||
Exceptions exceptions(); | ||
|
||
interface Exceptions { | ||
@WithName("bugsnag-api-key") | ||
Optional<String> bugsnagApiKey(); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/io/github/easybill/Contracts/IExceptionNotifier.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package io.github.easybill.Contracts; | ||
|
||
public interface IExceptionNotifier { | ||
void notify(Throwable throwable); | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/io/github/easybill/Contracts/IStageService.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package io.github.easybill.Contracts; | ||
|
||
public interface IStageService { | ||
boolean isProd(); | ||
boolean isDev(); | ||
boolean isTest(); | ||
} |
This file contains 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
This file contains 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
21 changes: 21 additions & 0 deletions
21
src/main/java/io/github/easybill/Services/BugNotifier/BugsnagNotifier.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package io.github.easybill.Services.BugNotifier; | ||
|
||
import com.bugsnag.Bugsnag; | ||
import io.github.easybill.Contracts.IExceptionNotifier; | ||
import org.checkerframework.checker.nullness.qual.NonNull; | ||
|
||
public final class BugsnagNotifier implements IExceptionNotifier { | ||
|
||
@NonNull | ||
private final String bugsnagApiKey; | ||
|
||
public BugsnagNotifier(@NonNull String bugsnagApiKey) { | ||
this.bugsnagApiKey = bugsnagApiKey; | ||
} | ||
|
||
public void notify(Throwable throwable) { | ||
try (Bugsnag bugsnag = new Bugsnag(bugsnagApiKey)) { | ||
bugsnag.notify(throwable); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/io/github/easybill/Services/BugNotifier/NoopNotifier.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package io.github.easybill.Services.BugNotifier; | ||
|
||
import io.github.easybill.Contracts.IExceptionNotifier; | ||
|
||
public final class NoopNotifier implements IExceptionNotifier { | ||
|
||
@Override | ||
public void notify(Throwable throwable) { | ||
return; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/main/java/io/github/easybill/Services/BugNotifier/NotifierProducer.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package io.github.easybill.Services.BugNotifier; | ||
|
||
import io.github.easybill.Contracts.IApplicationConfig; | ||
import io.github.easybill.Contracts.IExceptionNotifier; | ||
import io.github.easybill.Interceptors.GlobalExceptionInterceptor; | ||
import io.quarkus.arc.DefaultBean; | ||
import io.quarkus.arc.profile.IfBuildProfile; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.enterprise.context.Dependent; | ||
import jakarta.ws.rs.Produces; | ||
import org.jboss.logging.Logger; | ||
|
||
@Dependent | ||
public final class NotifierProducer { | ||
|
||
private static final Logger logger = Logger.getLogger( | ||
GlobalExceptionInterceptor.class | ||
); | ||
|
||
@Produces | ||
@ApplicationScoped | ||
@IfBuildProfile("prod") | ||
public IExceptionNotifier realNotifier(IApplicationConfig config) { | ||
var bugsnagApiKey = config.exceptions().bugsnagApiKey(); | ||
|
||
if (bugsnagApiKey.isEmpty()) { | ||
logger.info( | ||
"Notifier: NOOP notifier loaded as no API-Key was provided" | ||
); | ||
|
||
return new NoopNotifier(); | ||
} | ||
|
||
logger.info("Notifier: BUGSNAG notifier loaded"); | ||
|
||
return new BugsnagNotifier(bugsnagApiKey.get()); | ||
} | ||
|
||
@Produces | ||
@DefaultBean | ||
@ApplicationScoped | ||
public IExceptionNotifier noopNotifier() { | ||
logger.info( | ||
"Notifier: NOOP notifier loaded as the build profile does not permit loading a real notifier" | ||
); | ||
|
||
return new NoopNotifier(); | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
application.version=0.2.0 | ||
|
||
en16931.artefacts.version=1.3.13 | ||
app.version=0.3.0 | ||
app.artefacts.version=1.3.13 | ||
app.exceptions.bugsnag-api-key=${BUGSNAG_API_KEY} | ||
|
||
quarkus.smallrye-openapi.info-title=EN16931 Validator API | ||
quarkus.smallrye-openapi.info-version=${application.version} | ||
quarkus.smallrye-openapi.info-version=${app.version} | ||
quarkus.smallrye-openapi.info-description=A small service to validate XML against EN16931 rules | ||
quarkus.smallrye-openapi.info-contact-email[email protected] | ||
quarkus.smallrye-openapi.info-contact-name=easybill GmbH | ||
|