Skip to content

Commit 787d2f5

Browse files
authored
feat: upgrade to latest sentry and quarkus dependencies (#314)
* feat: upgrade sentry library * feat: upgrade to quarkus 3.8.2 Signed-off-by: Ruben Romero Montes <[email protected]>
1 parent 4e840d6 commit 787d2f5

File tree

8 files changed

+34
-40
lines changed

8 files changed

+34
-40
lines changed

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
<!-- Plugins -->
3535
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
3636
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
37-
<quarkus.platform.version>3.5.3</quarkus.platform.version>
37+
<quarkus.platform.version>3.8.2</quarkus.platform.version>
3838
<resources-plugin.version>3.3.1</resources-plugin.version>
3939
<build-helper-maven-plugin.version>3.4.0</build-helper-maven-plugin.version>
4040
<compiler-plugin.version>3.11.0</compiler-plugin.version>
@@ -49,7 +49,7 @@
4949

5050
<!-- Dependencies -->
5151
<exhort-api.version>1.0.5</exhort-api.version>
52-
<sentry.version>1.7.27</sentry.version>
52+
<sentry.version>7.6.0</sentry.version>
5353
<cyclonedx.version>8.0.3</cyclonedx.version>
5454
<spdx.version>1.1.7</spdx.version>
5555
<htmlunit.version>2.70.0</htmlunit.version>
@@ -210,7 +210,7 @@
210210
</dependency>
211211
<dependency>
212212
<groupId>org.wiremock</groupId>
213-
<artifactId>wiremock</artifactId>
213+
<artifactId>wiremock-standalone</artifactId>
214214
<version>${wiremock.version}</version>
215215
<scope>test</scope>
216216
</dependency>

src/main/java/com/redhat/exhort/integration/backend/ExhortIntegration.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ public void configure() {
197197
.when(header(Exchange.CONTENT_ENCODING).isEqualToIgnoreCase(GZIP_ENCODING)).unmarshal().gzipDeflater()
198198
.setProperty(Constants.GZIP_RESPONSE_PROPERTY, constant(Boolean.TRUE))
199199
.end()
200-
.to(seda("analyticsIdentify"))
200+
.to(direct("analyticsIdentify"))
201201
.setProperty(PROVIDERS_PARAM, method(vulnerabilityProvider, "getProvidersFromQueryParam"))
202202
.setProperty(REQUEST_CONTENT_PROPERTY, method(BackendUtils.class, "getResponseMediaType"))
203203
.setProperty(VERBOSE_MODE_HEADER, header(VERBOSE_MODE_HEADER));
@@ -221,7 +221,7 @@ public void configure() {
221221
from(direct("validateToken"))
222222
.routeId("validateToken")
223223
.setProperty(Constants.EXHORT_REQUEST_ID_HEADER, method(BackendUtils.class,"generateRequestId"))
224-
.to(seda("analyticsIdentify"))
224+
.to(direct("analyticsIdentify"))
225225
.choice()
226226
.when(header(Constants.SNYK_TOKEN_HEADER).isNotNull())
227227
.setProperty(PROVIDERS_PARAM, constant(Arrays.asList(Constants.SNYK_PROVIDER)))
@@ -239,7 +239,7 @@ public void configure() {
239239
.setHeader(Constants.EXHORT_REQUEST_ID_HEADER, exchangeProperty(Constants.EXHORT_REQUEST_ID_HEADER))
240240
.process(this::cleanUpHeaders);
241241

242-
from(seda("analyticsIdentify"))
242+
from(direct("analyticsIdentify"))
243243
.routeId("analyticsIdentify")
244244
.process(monitoringProcessor::processOriginalRequest)
245245
.to(seda("analyticsAsyncIdentify").waitForTaskToComplete(WaitForTaskToComplete.Never));

src/main/java/com/redhat/exhort/monitoring/SentryMonitoringClientFactory.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import com.redhat.exhort.monitoring.impl.SentryMonitoringClient;
2626

2727
import io.quarkus.runtime.annotations.RegisterForReflection;
28-
import io.sentry.SentryClientFactory;
28+
import io.sentry.SentryOptions;
2929

3030
import jakarta.enterprise.context.ApplicationScoped;
3131

@@ -43,9 +43,10 @@ public class SentryMonitoringClientFactory {
4343
String environment;
4444

4545
public MonitoringClient newInstance() {
46-
var client = SentryClientFactory.sentryClient(dsn.get());
47-
client.addTag("server_name", serverName.get());
48-
client.addTag("environment", environment);
49-
return new SentryMonitoringClient(client);
46+
SentryOptions opt = new SentryOptions();
47+
opt.setDsn(dsn.get());
48+
opt.setEnvironment(environment);
49+
opt.setTag("server_name", serverName.get());
50+
return new SentryMonitoringClient(opt);
5051
}
5152
}

src/main/java/com/redhat/exhort/monitoring/impl/SentryMonitoringClient.java

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,58 +18,50 @@
1818

1919
package com.redhat.exhort.monitoring.impl;
2020

21-
import java.util.Base64;
2221
import java.util.Map;
2322

2423
import com.redhat.exhort.monitoring.MonitoringClient;
2524
import com.redhat.exhort.monitoring.MonitoringContext;
2625

2726
import io.quarkus.runtime.annotations.RegisterForReflection;
28-
import io.sentry.SentryClient;
29-
import io.sentry.event.BreadcrumbBuilder;
30-
import io.sentry.event.UserBuilder;
27+
import io.sentry.Hub;
28+
import io.sentry.SentryOptions;
29+
import io.sentry.protocol.User;
3130

3231
@RegisterForReflection
3332
public class SentryMonitoringClient implements MonitoringClient {
3433

35-
private final SentryClient client;
34+
private final SentryOptions options;
3635

37-
public SentryMonitoringClient(SentryClient client) {
38-
this.client = client;
36+
public SentryMonitoringClient(SentryOptions options) {
37+
this.options = options;
3938
}
4039

4140
@Override
4241
public void reportException(Throwable exception, MonitoringContext context) {
42+
var hub = new Hub(options);
4343
if (!context.breadcrumbs().isEmpty()) {
44-
context
45-
.breadcrumbs()
46-
.forEach(
47-
b ->
48-
this.client
49-
.getContext()
50-
.recordBreadcrumb(
51-
new BreadcrumbBuilder()
52-
.setMessage(new String(Base64.getEncoder().encode(b.getBytes())))
53-
.setType(null)
54-
.build()));
44+
context.breadcrumbs().forEach(b -> hub.addBreadcrumb(b));
5545
}
5646
if (context.userId() != null) {
57-
this.client.getContext().setUser(new UserBuilder().setId(context.userId()).build());
47+
var user = new User();
48+
user.setId(context.userId());
49+
hub.setUser(user);
5850
}
59-
addAdditionalData(context.metadata(), context.tags());
60-
this.client.sendException(exception);
51+
addAdditionalData(hub, context.metadata(), context.tags());
52+
hub.captureException(exception);
6153
}
6254

63-
private void addAdditionalData(Map<String, String> metadata, Map<String, String> tags) {
55+
private void addAdditionalData(Hub hub, Map<String, String> metadata, Map<String, String> tags) {
6456
if (metadata != null) {
6557
metadata.entrySet().stream()
6658
.filter(e -> e.getValue() != null)
67-
.forEach(e -> this.client.getContext().addExtra(e.getKey(), e.getValue()));
59+
.forEach(e -> hub.setExtra(e.getKey(), e.getValue()));
6860
}
6961
if (tags != null) {
7062
tags.entrySet().stream()
7163
.filter(e -> e.getValue() != null)
72-
.forEach(t -> this.client.getContext().addTag(t.getKey(), t.getValue()));
64+
.forEach(t -> hub.setTag(t.getKey(), t.getValue()));
7365
}
7466
}
7567
}

src/main/resources/application.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ quarkus.rest-client.segment-api.url=https://api.segment.io/
3131
# monitoring.sentry.dsn=https://<some-uuid>@app.glitchtip.com/<some-id>
3232
# monitoring.sentry.servername=local
3333
# monitoring.sentry.environment=development
34+
sentry.stacktrace.app.packages=
3435

3536
quarkus.management.enabled=true
3637
quarkus.http.limits.max-body-size=4G

src/test/java/com/redhat/exhort/extensions/InjectWireMock.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@
2323

2424
import io.quarkus.test.common.QuarkusTestResource;
2525

26-
@QuarkusTestResource(WiremockV3Extension.class)
26+
@QuarkusTestResource(WiremockExtension.class)
2727
@Retention(RetentionPolicy.RUNTIME)
2828
public @interface InjectWireMock {}

src/test/java/com/redhat/exhort/extensions/WiremockV3Extension.java renamed to src/test/java/com/redhat/exhort/extensions/WiremockExtension.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
import io.quarkus.test.common.QuarkusTestResourceLifecycleManager;
2828

29-
public class WiremockV3Extension implements QuarkusTestResourceLifecycleManager {
29+
public class WiremockExtension implements QuarkusTestResourceLifecycleManager {
3030

3131
public static final String SNYK_TOKEN = "snyk-token-xyz";
3232

src/test/java/com/redhat/exhort/integration/AbstractAnalysisTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor;
2929
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
3030
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
31-
import static com.redhat.exhort.extensions.WiremockV3Extension.SNYK_TOKEN;
31+
import static com.redhat.exhort.extensions.WiremockExtension.SNYK_TOKEN;
3232
import static org.junit.jupiter.api.Assertions.assertEquals;
3333
import static org.junit.jupiter.api.Assertions.assertFalse;
3434
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -51,7 +51,7 @@
5151
import com.github.tomakehurst.wiremock.client.BasicCredentials;
5252
import com.google.common.base.Charsets;
5353
import com.redhat.exhort.extensions.InjectWireMock;
54-
import com.redhat.exhort.extensions.WiremockV3Extension;
54+
import com.redhat.exhort.extensions.WiremockExtension;
5555
import com.redhat.exhort.integration.providers.snyk.SnykRequestBuilder;
5656

5757
import io.quarkus.test.common.QuarkusTestResource;
@@ -63,7 +63,7 @@
6363
import jakarta.ws.rs.core.MediaType;
6464

6565
@QuarkusTest
66-
@QuarkusTestResource(WiremockV3Extension.class)
66+
@QuarkusTestResource(WiremockExtension.class)
6767
public abstract class AbstractAnalysisTest {
6868

6969
private static final String SNYK_UA_PATTERN = "redhat-snyk-exhort-.*";

0 commit comments

Comments
 (0)