diff --git a/pom.xml b/pom.xml index 38a876e..ce181ee 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.github.libgraviton worker-base jar - 4.1.0-SNAPSHOT + 4.1.0 Graviton Worker Base Library https://github.com/libgraviton/graviton-worker-base-java 2015 @@ -41,8 +41,8 @@ UTF-8 false false - 2.16.1 - 2.22.1 + 2.16.2 + 2.23.1 @@ -124,7 +124,7 @@ org.slf4j slf4j-api - 2.0.11 + 2.0.12 com.google.guava @@ -213,7 +213,7 @@ io.sentry sentry-log4j2 - 7.2.0 + 7.6.0 com.fasterxml.jackson.core @@ -253,14 +253,14 @@ io.github.classgraph classgraph - 4.8.165 + 4.8.168 io.micrometer micrometer-registry-prometheus - 1.12.2 + 1.12.3 io.github.mweirauch @@ -298,7 +298,7 @@ com.github.libgraviton graviton-worker-test-base - 4.0.0 + 4.1.0 test @@ -310,7 +310,7 @@ org.wiremock wiremock - 3.3.1 + 3.4.2 test @@ -438,13 +438,13 @@ org.junit.jupiter junit-jupiter - 5.10.1 + 5.10.2 test org.mockito mockito-core - 5.9.0 + 5.11.0 test diff --git a/src/main/java/com/github/libgraviton/workerbase/Application.java b/src/main/java/com/github/libgraviton/workerbase/Application.java index 53dde91..a148669 100644 --- a/src/main/java/com/github/libgraviton/workerbase/Application.java +++ b/src/main/java/com/github/libgraviton/workerbase/Application.java @@ -3,20 +3,16 @@ import com.github.libgraviton.workerbase.exception.WorkerException; import com.github.libgraviton.workerbase.helper.DependencyInjection; import com.github.libgraviton.workerbase.helper.WorkerProperties; +import io.sentry.Sentry; import java.io.IOException; -import java.lang.reflect.InvocationTargetException; import java.util.Properties; import java.util.Set; import java.util.stream.Collectors; public class Application { - public static void main(String[] args) throws IOException, WorkerException, ClassNotFoundException, InvocationTargetException, NoSuchMethodException, IllegalAccessException { - WorkerProperties.load(); - DependencyInjection.init(); - - // try to persist them - WorkerProperties.persist(); + public static void main(String[] args) throws IOException, WorkerException { + Properties workerProperties = initPropertiesAndSentry(); Set> workerClasses = DependencyInjection.getWorkerClasses(); @@ -61,9 +57,44 @@ public static void main(String[] args) throws IOException, WorkerException, Clas final WorkerLauncher workerLauncher = new WorkerLauncher( worker, - DependencyInjection.getInstance(Properties.class) + workerProperties, + getApplicationName(workerProperties) ); workerLauncher.run(); } + + private static Properties initPropertiesAndSentry() throws IOException { + WorkerProperties.load(); + DependencyInjection.init(); + + // try to persist them + WorkerProperties.persist(); + + Properties workerProperties = DependencyInjection.getInstance(Properties.class); + + Sentry.init(options -> { + String dsn = System.getenv("SENTRY_DSN"); + + if (null != dsn && !dsn.isBlank()) { + options.setDsn(dsn); + options.setEnabled(true); + } + + options.setRelease( + String.format( + "%s@%s", + getApplicationName(workerProperties), + workerProperties.getProperty("application.version") + ) + ); + }); + + return workerProperties; + } + + private static String getApplicationName(Properties properties) + { + return properties.getProperty("graviton.workerName") != null ? properties.getProperty("graviton.workerName") : properties.getProperty("application.name"); + } } \ No newline at end of file diff --git a/src/main/java/com/github/libgraviton/workerbase/WorkerLauncher.java b/src/main/java/com/github/libgraviton/workerbase/WorkerLauncher.java index c124be9..fcf22f0 100644 --- a/src/main/java/com/github/libgraviton/workerbase/WorkerLauncher.java +++ b/src/main/java/com/github/libgraviton/workerbase/WorkerLauncher.java @@ -6,7 +6,6 @@ import com.github.libgraviton.workerbase.exception.WorkerException; import com.github.libgraviton.workerbase.util.PrometheusServer; import com.sun.net.httpserver.HttpServer; -import io.activej.inject.annotation.Inject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,19 +33,14 @@ public final class WorkerLauncher { private final PrometheusServer prometheusServer; private final QueueWorkerRunner queueWorkerRunner; - @Inject public WorkerLauncher( WorkerInterface worker, - Properties properties + Properties properties, + String applicationName ) { this.worker = worker; - String applicationName = properties.getProperty("application.name"); - if (properties.getProperty("graviton.workerName") != null) { - applicationName = properties.getProperty("graviton.workerName"); - } - LOG.info( "Starting '{} {}' (class '{}', worker-base '{}'). Runtime '{}' version '{}', TZ '{}'", applicationName, diff --git a/src/test/java/com/github/libgraviton/workerbase/gdk/api/RequestTest.java b/src/test/java/com/github/libgraviton/workerbase/gdk/api/RequestTest.java index 650ba0d..9626a0c 100644 --- a/src/test/java/com/github/libgraviton/workerbase/gdk/api/RequestTest.java +++ b/src/test/java/com/github/libgraviton/workerbase/gdk/api/RequestTest.java @@ -8,6 +8,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import java.net.URI; import java.net.URL; import java.util.HashMap; import java.util.List; @@ -30,7 +31,7 @@ public void setup() throws Exception { RequestExecutor executor = mock(RequestExecutor.class); when(executor.execute(any(Request.class))).thenReturn(response); - URL url = new URL("http://aRandomUrl"); + URL url = new URI("http://aRandomUrl").toURL(); builder = new Request.Builder().setUrl(url); } @@ -117,7 +118,7 @@ public void testMultipartPut() throws Exception { Assertions.assertEquals(HttpMethod.PUT, request.getMethod()); List parts = request.getParts(); Assertions.assertEquals(1, parts.size()); - Assertions.assertEquals(part, parts.get(0)); + Assertions.assertEquals(part, parts.getFirst()); } @Test