Gitlab Community Edition Instance

Commit 23831a1b authored by mhellka's avatar mhellka
Browse files

Removing (unsupported) sentry plugin.

Upstream stopped maintaining a backwards compatible API.
parent cecb0da8
../../../cdstar-plugins-pom/cdstar-sentry/README.adoc
\ No newline at end of file
# SentryPlugin
This `SentryPlugin` installs a https://sentry.io/[Sentry] log appender (at `WARN` level) and provides a `SentryClient` for other components to use. In its default configuration, it sends all log messages of level `WARN` or higher to the configured sentry instance.
## Configuration
.Example Configuration
[source,yaml]
----
plugin.sentry:
class: SentryPlugin
dsn: 'https://<key>@<host>/<project>?stacktrace.app.packages=de.gwdg'
loggers: de.gwdg,org.eclipse.jetty
----
.Config Parameters
[cols="0v,1"]
|=========
| Name | Description
| class | Plugin class name. `SentryPlugin` or `de.gwdg.cdstar.ext.sentry.SentryPlugin`.
| dsn | Sentry DSN (data source name) to send events to. (fallback: `SENTRY_DSN` environment variable)
| loggers | Comma separated list of loggr names to attach to. (default: `ROOT`)
|=========
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>de.gwdg.cdstar.plugins</groupId>
<artifactId>cdstar-plugins-pom</artifactId>
<version>3.1.0-SNAPSHOT</version>
</parent>
<artifactId>cdstar-sentry</artifactId>
<dependencies>
<dependency>
<groupId>io.sentry</groupId>
<artifactId>sentry-log4j2</artifactId>
<version>1.7.30</version>
<exclusions>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>de.gwdg.cdstar</groupId>
<artifactId>cdstar-cli</artifactId>
<version>3.1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package de.gwdg.cdstar.ext.sentry;
import java.util.ArrayList;
import java.util.List;
import java.util.ServiceLoader;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.LoggerConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import de.gwdg.cdstar.GitInfo;
import de.gwdg.cdstar.Utils;
import de.gwdg.cdstar.cli.RunCommand;
import de.gwdg.cdstar.runtime.Config;
import de.gwdg.cdstar.runtime.ConfigException;
import de.gwdg.cdstar.runtime.Plugin;
import de.gwdg.cdstar.runtime.RuntimeContext;
import de.gwdg.cdstar.runtime.listener.RuntimeListener;
import io.sentry.Sentry;
import io.sentry.SentryClient;
import io.sentry.event.helper.HttpEventBuilderHelper;
import io.sentry.log4j2.SentryAppender;
import io.sentry.servlet.SentryServletContainerInitializer;
/**
* A plugin that installs a sentry log4j2 appender at WARN level and provides
* {@link SentryClient} as a service.
*
* Notes: The {@link SentryServletContainerInitializer} required to extract
* servlet metadata is detected and installed by {@link RunCommand} via
* {@link ServiceLoader} lookup, and the matching {@link HttpEventBuilderHelper}
* is installed by sentry if servlet APIs are found on the classpath. The
* wiering is strange, but it works.
*/
@Plugin(name = "sentry")
public class SentryPlugin implements RuntimeListener {
private static final Logger log = LoggerFactory.getLogger(SentryPlugin.class);
private String dsn;
private List<String> loggers;
public SentryPlugin(Config config) throws ConfigException {
final String configDSN = config.get("dsn", null);
final String envDSN = Utils.getProperty("sentry.dsn", null);
if (Utils.notNullOrEmpty(configDSN)) {
if (Utils.notNullOrEmpty(envDSN))
log.warn("DSN set via config, will ignore SENTRY_DSN environment variables.");
dsn = configDSN;
} else if (Utils.notNullOrEmpty(envDSN)) {
dsn = envDSN;
} else {
log.warn("Sentry plugin installed, but no DSN configured.");
return;
}
config.setDefault("loggers", LogManager.ROOT_LOGGER_NAME);
loggers = new ArrayList<>(config.getList("loggers"));
}
@Override
public void onInit(RuntimeContext ctx) throws Exception {
Sentry.init(dsn);
final SentryClient client = Sentry.getStoredClient();
ctx.register(client);
if (GitInfo.isAvailable()) {
client.setRelease("cdstar-" + GitInfo.getInstance().getVersion());
client.addTag("git.commit", GitInfo.getInstance().getCommit());
}
}
@Override
public void onStartup(RuntimeContext ctx) throws Exception {
try {
final LoggerContext logContext = (LoggerContext) LogManager.getContext(false);
final Configuration logConfig = logContext.getConfiguration();
for (final String loggerName : loggers) {
LoggerConfig lc = logConfig.getLoggers().get(loggerName);
if (lc == null) {
lc = new LoggerConfig(loggerName, Level.WARN, true);
logConfig.addLogger(loggerName, lc);
}
final SentryAppender app = new SentryAppender();
app.start();
lc.addAppender(app, Level.WARN, null);
log.debug("Sentry log appender installed to logger: {}", lc.getName());
}
logContext.updateLoggers();
} catch (final Exception e) {
log.error("Failed to install sentry log appender (assuming log4j2 logging implementation)", e);
throw new ConfigException("Plugin initialisation failed", e);
}
}
@Override
public void onShutdown(RuntimeContext ctx) {
final LoggerContext logContext = (LoggerContext) LogManager.getContext(false);
final Configuration logConfig = logContext.getConfiguration();
for (final String loggerName : loggers) {
final LoggerConfig lc = logConfig.getLoggers().get(loggerName);
if (lc != null && lc.getAppenders().containsKey(SentryAppender.APPENDER_NAME)) {
lc.removeAppender(SentryAppender.APPENDER_NAME);
log.debug("Sentry log appender removed from logger: {}", lc.getName());
}
}
logContext.updateLoggers();
}
}
......@@ -23,7 +23,6 @@
<module>cdstar-ui</module>
<module>cdstar-tus</module>
<module>cdstar-proxy-search</module>
<module>cdstar-sentry</module>
</modules>
<dependencies>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment