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
\ No newline at end of file
# SentryPlugin
This `SentryPlugin` installs a[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
class: SentryPlugin
dsn: 'https://<key>@<host>/<project>?'
loggers: de.gwdg,org.eclipse.jetty
.Config Parameters
| 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="" xmlns:xsi="" xsi:schemaLocation="">
\ 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.");
config.setDefault("loggers", LogManager.ROOT_LOGGER_NAME);
loggers = new ArrayList<>(config.getList("loggers"));
public void onInit(RuntimeContext ctx) throws Exception {
final SentryClient client = Sentry.getStoredClient();
if (GitInfo.isAvailable()) {
client.setRelease("cdstar-" + GitInfo.getInstance().getVersion());
client.addTag("git.commit", GitInfo.getInstance().getCommit());
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();
lc.addAppender(app, Level.WARN, null);
log.debug("Sentry log appender installed to logger: {}", lc.getName());
} catch (final Exception e) {
log.error("Failed to install sentry log appender (assuming log4j2 logging implementation)", e);
throw new ConfigException("Plugin initialisation failed", e);
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)) {
log.debug("Sentry log appender removed from logger: {}", lc.getName());
......@@ -23,7 +23,6 @@
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