Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Sentry support for Issues and Performance #2152

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM openjdk:11-jre
FROM openjdk:16-bullseye

ENV OPENFIRE_USER=openfire \
OPENFIRE_DIR=/usr/local/openfire \
Expand Down
7 changes: 5 additions & 2 deletions distribution/src/resources/log4j2.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>

<Configuration monitorInterval="30">
<Configuration monitorInterval="30" status="WARN" packages="io.sentry.log4j2">
<Appenders>
<!-- Modifying this appender is likely to break the log viewer that is part of the Openfire admin console.
- If you'd like to have a differently formatted log file, it is advisable to create a new log file, by
Expand All @@ -18,6 +18,8 @@
<Console name="console" target="SYSTEM_OUT">
<PatternLayout pattern="%msg{nolookups}%n%throwable{0}"/>
</Console>

<Sentry name="sentry" minimumBreadcrumbLevel="DEBUG" minimumEventLevel="ERROR" />

</Appenders>

Expand All @@ -33,8 +35,9 @@
<!-- OF-506: Jetty INFO messages are generally not useful. Ignore them by default. -->
<Logger name="org.eclipse.jetty" level="warn"/>

<Root level="info">
<Root level="debug">
<AppenderRef ref="openfire"/>
<AppenderRef ref="sentry"/>
</Root>
</Loggers>
</Configuration>
6 changes: 6 additions & 0 deletions starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,11 @@
<scope>system</scope>
<systemPath>${project.basedir}/libs/i4jruntime.jar</systemPath>
</dependency>
<dependency>
<groupId>io.sentry</groupId>
<artifactId>sentry-log4j2</artifactId>
<version>6.4.0</version>
</dependency>

</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.io.File;

import io.sentry.Sentry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -53,6 +54,12 @@ public class ServerStarter {
private static final String DEFAULT_LIB_DIR = "../lib";

public static void main(String [] args) {
String sentryDsn = System.getProperty("sentry.dsn");
Sentry.init(options -> {
options.setDsn(sentryDsn == null ? "" : sentryDsn);
options.setTracesSampleRate(1.0);
options.setDebug(true);
});
new ServerStarter().start();
}

Expand Down
11 changes: 11 additions & 0 deletions xmppserver/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,17 @@
<version>${slf4j.version}</version>
</dependency>

<dependency>
<groupId>io.sentry</groupId>
<artifactId>sentry-log4j2</artifactId>
<version>6.4.0</version>
</dependency>
<dependency>
<groupId>io.sentry</groupId>
<artifactId>sentry-servlet</artifactId>
<version>6.4.0</version>
</dependency>

<!-- RSS feed -->
<dependency>
<groupId>com.rometools</groupId>
Expand Down
34 changes: 34 additions & 0 deletions xmppserver/src/main/java/org/jivesoftware/admin/SentryPerf.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.jivesoftware.admin;

import io.sentry.ITransaction;
import io.sentry.Sentry;
import io.sentry.SpanStatus;
import org.jivesoftware.util.SentryWrap;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

public class SentryPerf implements Filter {
@Override
public void init(FilterConfig filterConfig) throws ServletException {

}

@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
HttpServletRequest httpRequest = (HttpServletRequest) servletRequest;
try {
SentryWrap.transaction(() -> filterChain.doFilter(servletRequest, servletResponse), httpRequest.getRequestURI(), "http.server");
} catch (IOException | ServletException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}

@Override
public void destroy() {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.Map;
import java.util.MissingResourceException;

import io.sentry.Sentry;
import org.jivesoftware.util.ClassUtils;
import org.jivesoftware.util.JiveGlobals;
import org.slf4j.Logger;
Expand Down Expand Up @@ -176,6 +177,12 @@ public static Connection getConnection() throws SQLException {
// connection unless profiling is enabled. If yes, wrap the
// connection with a profiled connection.
if (!profilingEnabled) {
if (Sentry.isEnabled()) {
// Ah, but Sentry is live, so let's profile anyway.
profilingEnabled = true;
ProfiledConnection.start();
return new ProfiledConnection(con);
}
return con;
} else {
return new ProfiledConnection(con);
Expand Down
Loading