Skip to content
Closed
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
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Version 7.0.1

- Use RavenFactory's class loader when creating the service loader, fixing some issues in containers. (thanks exell-christopher)
- Add ``release`` property to ``raven-log4j``. (thanks molaschi)
- Add ``release`` property to JUL integration and ``raven-log4j2``.
- Add setters for ``dsn`` and ``tags`` in JUL integration, fixes integration with WildFly. (thanks giilby)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,18 @@ public class SentryAppender extends AppenderSkeleton {
* Might be null in which case the DSN should be detected automatically.
*/
protected String dsn;
/**
* Release to be sent to sentry.
* <p>
* Might be null in which case no release is sent.
*/
protected String release;
/**
* Name of the {@link RavenFactory} being used.
* <p>
* Might be null in which case the factory should be defined automatically.
*/
protected String ravenFactory;
/**
* Release to be sent to sentry.
* <p>
* Might be null in which case no release is sent.
*/
protected String release;
/**
* Additional tags to be sent to sentry.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.getsentry.raven.event.interfaces.ExceptionInterface;
import com.getsentry.raven.event.interfaces.MessageInterface;
import com.getsentry.raven.event.interfaces.StackTraceInterface;
import com.google.common.base.Strings;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.Filter;
import org.apache.logging.log4j.core.LogEvent;
Expand Down Expand Up @@ -62,14 +63,20 @@ public class SentryAppender extends AbstractAppender {
* Might be null in which case the factory should be defined automatically.
*/
protected String ravenFactory;
/**
* Release to be sent to Sentry.
* <p>
* Might be null in which case no release is sent.
*/
protected String release;
/**
* Additional tags to be sent to sentry.
* <p>
* Might be empty in which case no tags are sent.
*/
protected Map<String, String> tags = Collections.emptyMap();
/**
* Set of tags to look for in the MDC. These will be added as tags to be sent to sentry.
* Set of tags to look for in the MDC. These will be added as tags to be sent to Sentry.
* <p>
* Might be empty in which case no mapped tags are set.
* </p>
Expand Down Expand Up @@ -103,6 +110,7 @@ private SentryAppender(String name, Filter filter) {
* @param name The name of the Appender.
* @param dsn Data Source Name to access the Sentry server.
* @param ravenFactory Name of the factory to use to build the {@link Raven} instance.
* @param release Release to be sent to Sentry.
* @param tags Tags to add to each event.
* @param extraTags Tags to search through the MDC.
* @param filter The filter, if any, to use.
Expand All @@ -112,6 +120,7 @@ private SentryAppender(String name, Filter filter) {
public static SentryAppender createAppender(@PluginAttribute("name") final String name,
@PluginAttribute("dsn") final String dsn,
@PluginAttribute("ravenFactory") final String ravenFactory,
@PluginAttribute("release") final String release,
@PluginAttribute("tags") final String tags,
@PluginAttribute("extraTags") final String extraTags,
@PluginElement("filters") final Filter filter) {
Expand All @@ -120,9 +129,10 @@ public static SentryAppender createAppender(@PluginAttribute("name") final Strin
LOGGER.error("No name provided for SentryAppender");
return null;
}

SentryAppender sentryAppender = new SentryAppender(name, filter);
sentryAppender.setDsn(dsn);
if (release != null)
sentryAppender.setRelease(release);
if (tags != null)
sentryAppender.setTags(tags);
if (extraTags != null)
Expand Down Expand Up @@ -224,6 +234,10 @@ protected Event buildEvent(LogEvent event) {
.withLevel(formatLevel(event.getLevel()))
.withExtra(THREAD_NAME, event.getThreadName());

if (!Strings.isNullOrEmpty(release)) {
eventBuilder.withRelease(release.trim());
}

if (!eventMessage.getFormattedMessage().equals(eventMessage.getFormat())) {
eventBuilder.withSentryInterface(new MessageInterface(eventMessage.getFormat(),
formatMessageParameters(eventMessage.getParameters())));
Expand Down Expand Up @@ -274,6 +288,10 @@ public void setRavenFactory(String ravenFactory) {
this.ravenFactory = ravenFactory;
}

public void setRelease(String release) {
this.release = release;
}

/**
* Set the tags that should be sent along with the events.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,19 @@ public void testExtraTagObtainedFromMdc() throws Exception {
}};
assertNoErrorsInErrorHandler();
}

@Test
public void testReleaseAddedToEvent() throws Exception {
final String release = "d7b4a6a0-1a0a-4381-a519-e2ccab609003";
sentryAppender.setRelease(release);

sentryAppender.append(new Log4jLogEvent(null, null, null, Level.ERROR, new SimpleMessage(""), null));

new Verifications() {{
Event event;
mockRaven.sendEvent(event = withCapture());
assertThat(event.getRelease(), is(release));
}};
assertNoErrorsInErrorHandler();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -289,4 +289,19 @@ public void testExtraTagObtainedFromMdc() throws Exception {
}};
assertNoErrorsInStatusManager();
}

@Test
public void testReleaseAddedToEvent() throws Exception {
final String release = "d7b4a6a0-1a0a-4381-a519-e2ccab609003";
sentryAppender.setRelease(release);

sentryAppender.append(new MockUpLoggingEvent(null, null, Level.INFO, null, null, null).getMockInstance());

new Verifications() {{
Event event;
mockRaven.sendEvent(event = withCapture());
assertThat(event.getRelease(), is(release));
}};
assertNoErrorsInStatusManager();
}
}
16 changes: 16 additions & 0 deletions raven/src/main/java/com/getsentry/raven/jul/SentryHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.getsentry.raven.event.EventBuilder;
import com.getsentry.raven.event.interfaces.ExceptionInterface;
import com.getsentry.raven.event.interfaces.MessageInterface;
import com.google.common.base.Strings;
import org.slf4j.MDC;

import java.text.MessageFormat;
Expand Down Expand Up @@ -42,6 +43,12 @@ public class SentryHandler extends Handler {
* Might be null in which case the factory should be defined automatically.
*/
protected String ravenFactory;
/**
* Release to be sent to sentry.
* <p>
* Might be null in which case no release is sent.
*/
protected String release;
/**
* Tags to add to every event.
*/
Expand Down Expand Up @@ -129,6 +136,7 @@ protected void retrieveProperties() {
String className = SentryHandler.class.getName();
dsn = manager.getProperty(className + ".dsn");
ravenFactory = manager.getProperty(className + ".ravenFactory");
release = manager.getProperty(className + ".release");
String tagsProperty = manager.getProperty(className + ".tags");
tags = parseTags(tagsProperty);
String extraTagsProperty = manager.getProperty(className + ".extraTags");
Expand Down Expand Up @@ -224,6 +232,10 @@ protected Event buildEvent(LogRecord record) {

eventBuilder.withExtra(THREAD_ID, record.getThreadID());

if (!Strings.isNullOrEmpty(release)) {
eventBuilder.withRelease(release.trim());
}

raven.runBuilderHelpers(eventBuilder);
return eventBuilder.build();
}
Expand All @@ -244,4 +256,8 @@ public void close() throws SecurityException {
RavenEnvironment.stopManagingThread();
}
}

public void setRelease(String release) {
this.release = release;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;
import java.util.UUID;
import java.util.logging.ErrorManager;
import java.util.logging.Level;
import java.util.logging.LogRecord;
Expand Down Expand Up @@ -159,4 +157,19 @@ private LogRecord newLogRecord(String loggerName, Level level, String message, O
}
return logRecord;
}

@Test
public void testReleaseAddedToEvent() throws Exception {
final String release = "d7b4a6a0-1a0a-4381-a519-e2ccab609003";
sentryHandler.setRelease(release);

sentryHandler.publish(newLogRecord(null, Level.INFO, null, null, null));

new Verifications() {{
Event event;
mockRaven.sendEvent(event = withCapture());
assertThat(event.getRelease(), is(release));
}};
assertNoErrorsInErrorManager();
}
}
6 changes: 3 additions & 3 deletions raven/src/test/java/com/getsentry/raven/stub/SentryStub.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public SentryStub(URL url) {
public int getEventCount() {
RavenEnvironment.startManagingThread();
try {
HttpURLConnection connection = connnectTo("count");
HttpURLConnection connection = connectTo("count");
connection.setRequestMethod("GET");
return (Integer) getContent(connection).get("count");
} catch (Exception e) {
Expand All @@ -52,7 +52,7 @@ public int getEventCount() {
public void removeEvents() {
RavenEnvironment.startManagingThread();
try {
HttpURLConnection connection = connnectTo("cleanup");
HttpURLConnection connection = connectTo("cleanup");
connection.setRequestMethod("DELETE");
connection.setDoOutput(false);
connection.connect();
Expand All @@ -78,7 +78,7 @@ private Map<String, Object> getContent(HttpURLConnection connection) {
}
}

private HttpURLConnection connnectTo(String path) {
private HttpURLConnection connectTo(String path) {
try {
URL test = new URL(url, path);
return (HttpURLConnection) test.openConnection();
Expand Down