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

Refactor plugin to support latest Jenkins and Sentry version #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
59 changes: 34 additions & 25 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,19 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>2.2</version>
<version>4.74</version>
</parent>


<groupId>io.jenkins.plugins</groupId>
<artifactId>sentry</artifactId>
<version>1.5.0</version>
<version>6.30.4</version>
<packaging>hpi</packaging>
<description>Integrates Jenkins with the Sentry error reporting service</description>
<url>http://wiki.jenkins-ci.org/display/JENKINS/Sentry+Plugin</url>


<properties>
<jenkins.version>2.387.3</jenkins.version>
</properties>

<name>Sentry plugin</name>

Expand All @@ -64,9 +67,26 @@
<dependency>
<groupId>io.sentry</groupId>
<artifactId>sentry</artifactId>
<version>1.5.0</version>
<version>6.30.0</version>
</dependency>
<dependency>
<groupId>io.sentry</groupId>
<artifactId>sentry-jul</artifactId>
<version>6.30.0</version>
</dependency>
</dependencies>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-2.387.x</artifactId>
<version>2483.v3b_22f030990a_</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>

<repositories>
<repository>
Expand All @@ -82,31 +102,20 @@
</pluginRepository>
</pluginRepositories>

<properties>
<jenkins.version>2.60.3</jenkins.version>
<java.level>7</java.level>
</properties>

<build>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<providerSelection>1.8</providerSelection>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<goals>
<goal>generateStubs</goal>
<goal>compile</goal>
<goal>generateTestStubs</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>

This file was deleted.

This file was deleted.

68 changes: 0 additions & 68 deletions src/main/groovy/io/jenkins/plugins/sentry/SentryPlugin.groovy

This file was deleted.

81 changes: 81 additions & 0 deletions src/main/java/io/jenkins/plugins/sentry/SentryPlugin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package io.jenkins.plugins.sentry;

import hudson.Plugin;
import io.sentry.Sentry;
import io.sentry.jul.SentryHandler;

import java.util.Enumeration;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.Logger;

public class SentryPlugin extends Plugin {
private static final Logger LOG = Logger.getLogger(SentryPlugin.class.getName());

public void postInitialize() {
if (System.getenv("SENTRY_DSN") == null) {
LOG.warning("The `SENTRY_DSN` environment variable is not defined, not configuring Sentry");
return;
}

Sentry.init();
LOG.info("Sentry initialized");

if (System.getenv("SENTRY_NO_LOGWATCHER") == null) {
LOG.info("Running Sentry addLogWatcher");
addLogWatcher();
}
}

public void addLogWatcher() {
final SentryHandler sentry = new SentryHandler();
/* Default everything to the warning level, no need for INFO */
sentry.setMinimumEventLevel(Level.WARNING);

new Thread(() -> {
LOG.info("Waiting for 2 minutes for Jenkins to bootstrap before configuring Sentry");
try {
Thread.sleep(120_000); // Converted seconds to milliseconds
} catch (InterruptedException e) {
e.printStackTrace();
}

while (true) {
Enumeration<String> enum_ = LogManager.getLogManager().getLoggerNames();
LOG.fine("Iterating over loggers");
while (enum_.hasMoreElements()) {
String loggerName = enum_.nextElement();
/* Avoid excessive warnings */
/* https://issues.jenkins-ci.org/browse/JENKINS-46404 */
if (!loggerName.equals("org.jenkinsci.plugins.durabletask.ProcessLiveness")) {
LOG.fine("Checking logger: " + loggerName);
Logger manager = LogManager.getLogManager().getLogger(loggerName);
if (manager != null) {
boolean found = false;
for (Handler handler : manager.getHandlers()) {
if (handler instanceof SentryHandler) {
found = true;
break;
}
}

if (!found) {
LOG.info("Adding Sentry to " + loggerName);
manager.addHandler((Handler) sentry);
}
}
}
}

// Sleep for five minutes in this thread, to make sure we are always
// adding Sentry to new loggers should they appear
try {
Thread.sleep(300_000); // Converted 5 minutes to milliseconds
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
}
}
4 changes: 4 additions & 0 deletions src/main/resources/index.jelly
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?jelly escape-by-default='true'?>
<div>
Integrates Jenkins with the Sentry error reporting service
</div>