Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<!-- Plugins -->
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
<quarkus.platform.version>3.5.3</quarkus.platform.version>
<quarkus.platform.version>3.8.2</quarkus.platform.version>
<resources-plugin.version>3.3.1</resources-plugin.version>
<build-helper-maven-plugin.version>3.4.0</build-helper-maven-plugin.version>
<compiler-plugin.version>3.11.0</compiler-plugin.version>
Expand All @@ -49,7 +49,7 @@

<!-- Dependencies -->
<exhort-api.version>1.0.5</exhort-api.version>
<sentry.version>1.7.27</sentry.version>
<sentry.version>7.6.0</sentry.version>
<cyclonedx.version>8.0.3</cyclonedx.version>
<spdx.version>1.1.7</spdx.version>
<htmlunit.version>2.70.0</htmlunit.version>
Expand Down Expand Up @@ -210,7 +210,7 @@
</dependency>
<dependency>
<groupId>org.wiremock</groupId>
<artifactId>wiremock</artifactId>
<artifactId>wiremock-standalone</artifactId>
<version>${wiremock.version}</version>
<scope>test</scope>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public void configure() {
.when(header(Exchange.CONTENT_ENCODING).isEqualToIgnoreCase(GZIP_ENCODING)).unmarshal().gzipDeflater()
.setProperty(Constants.GZIP_RESPONSE_PROPERTY, constant(Boolean.TRUE))
.end()
.to(seda("analyticsIdentify"))
.to(direct("analyticsIdentify"))
.setProperty(PROVIDERS_PARAM, method(vulnerabilityProvider, "getProvidersFromQueryParam"))
.setProperty(REQUEST_CONTENT_PROPERTY, method(BackendUtils.class, "getResponseMediaType"))
.setProperty(VERBOSE_MODE_HEADER, header(VERBOSE_MODE_HEADER));
Expand All @@ -221,7 +221,7 @@ public void configure() {
from(direct("validateToken"))
.routeId("validateToken")
.setProperty(Constants.EXHORT_REQUEST_ID_HEADER, method(BackendUtils.class,"generateRequestId"))
.to(seda("analyticsIdentify"))
.to(direct("analyticsIdentify"))
.choice()
.when(header(Constants.SNYK_TOKEN_HEADER).isNotNull())
.setProperty(PROVIDERS_PARAM, constant(Arrays.asList(Constants.SNYK_PROVIDER)))
Expand All @@ -239,7 +239,7 @@ public void configure() {
.setHeader(Constants.EXHORT_REQUEST_ID_HEADER, exchangeProperty(Constants.EXHORT_REQUEST_ID_HEADER))
.process(this::cleanUpHeaders);

from(seda("analyticsIdentify"))
from(direct("analyticsIdentify"))
.routeId("analyticsIdentify")
.process(monitoringProcessor::processOriginalRequest)
.to(seda("analyticsAsyncIdentify").waitForTaskToComplete(WaitForTaskToComplete.Never));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import com.redhat.exhort.monitoring.impl.SentryMonitoringClient;

import io.quarkus.runtime.annotations.RegisterForReflection;
import io.sentry.SentryClientFactory;
import io.sentry.SentryOptions;

import jakarta.enterprise.context.ApplicationScoped;

Expand All @@ -43,9 +43,10 @@ public class SentryMonitoringClientFactory {
String environment;

public MonitoringClient newInstance() {
var client = SentryClientFactory.sentryClient(dsn.get());
client.addTag("server_name", serverName.get());
client.addTag("environment", environment);
return new SentryMonitoringClient(client);
SentryOptions opt = new SentryOptions();
opt.setDsn(dsn.get());
opt.setEnvironment(environment);
opt.setTag("server_name", serverName.get());
return new SentryMonitoringClient(opt);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,58 +18,50 @@

package com.redhat.exhort.monitoring.impl;

import java.util.Base64;
import java.util.Map;

import com.redhat.exhort.monitoring.MonitoringClient;
import com.redhat.exhort.monitoring.MonitoringContext;

import io.quarkus.runtime.annotations.RegisterForReflection;
import io.sentry.SentryClient;
import io.sentry.event.BreadcrumbBuilder;
import io.sentry.event.UserBuilder;
import io.sentry.Hub;
import io.sentry.SentryOptions;
import io.sentry.protocol.User;

@RegisterForReflection
public class SentryMonitoringClient implements MonitoringClient {

private final SentryClient client;
private final SentryOptions options;

public SentryMonitoringClient(SentryClient client) {
this.client = client;
public SentryMonitoringClient(SentryOptions options) {
this.options = options;
}

@Override
public void reportException(Throwable exception, MonitoringContext context) {
var hub = new Hub(options);
if (!context.breadcrumbs().isEmpty()) {
context
.breadcrumbs()
.forEach(
b ->
this.client
.getContext()
.recordBreadcrumb(
new BreadcrumbBuilder()
.setMessage(new String(Base64.getEncoder().encode(b.getBytes())))
.setType(null)
.build()));
context.breadcrumbs().forEach(b -> hub.addBreadcrumb(b));
}
if (context.userId() != null) {
this.client.getContext().setUser(new UserBuilder().setId(context.userId()).build());
var user = new User();
user.setId(context.userId());
hub.setUser(user);
}
addAdditionalData(context.metadata(), context.tags());
this.client.sendException(exception);
addAdditionalData(hub, context.metadata(), context.tags());
hub.captureException(exception);
}

private void addAdditionalData(Map<String, String> metadata, Map<String, String> tags) {
private void addAdditionalData(Hub hub, Map<String, String> metadata, Map<String, String> tags) {
if (metadata != null) {
metadata.entrySet().stream()
.filter(e -> e.getValue() != null)
.forEach(e -> this.client.getContext().addExtra(e.getKey(), e.getValue()));
.forEach(e -> hub.setExtra(e.getKey(), e.getValue()));
}
if (tags != null) {
tags.entrySet().stream()
.filter(e -> e.getValue() != null)
.forEach(t -> this.client.getContext().addTag(t.getKey(), t.getValue()));
.forEach(t -> hub.setTag(t.getKey(), t.getValue()));
}
}
}
1 change: 1 addition & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ quarkus.rest-client.segment-api.url=https://api.segment.io/
# monitoring.sentry.dsn=https://<some-uuid>@app.glitchtip.com/<some-id>
# monitoring.sentry.servername=local
# monitoring.sentry.environment=development
sentry.stacktrace.app.packages=

quarkus.management.enabled=true
quarkus.http.limits.max-body-size=4G
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@

import io.quarkus.test.common.QuarkusTestResource;

@QuarkusTestResource(WiremockV3Extension.class)
@QuarkusTestResource(WiremockExtension.class)
@Retention(RetentionPolicy.RUNTIME)
public @interface InjectWireMock {}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

import io.quarkus.test.common.QuarkusTestResourceLifecycleManager;

public class WiremockV3Extension implements QuarkusTestResourceLifecycleManager {
public class WiremockExtension implements QuarkusTestResourceLifecycleManager {

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
import static com.redhat.exhort.extensions.WiremockV3Extension.SNYK_TOKEN;
import static com.redhat.exhort.extensions.WiremockExtension.SNYK_TOKEN;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand All @@ -51,7 +51,7 @@
import com.github.tomakehurst.wiremock.client.BasicCredentials;
import com.google.common.base.Charsets;
import com.redhat.exhort.extensions.InjectWireMock;
import com.redhat.exhort.extensions.WiremockV3Extension;
import com.redhat.exhort.extensions.WiremockExtension;
import com.redhat.exhort.integration.providers.snyk.SnykRequestBuilder;

import io.quarkus.test.common.QuarkusTestResource;
Expand All @@ -63,7 +63,7 @@
import jakarta.ws.rs.core.MediaType;

@QuarkusTest
@QuarkusTestResource(WiremockV3Extension.class)
@QuarkusTestResource(WiremockExtension.class)
public abstract class AbstractAnalysisTest {

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