Skip to content
Merged
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
- Add support for setting in-app-includes/in-app-excludes via AndroidManifest.xml ([#4240](https://github.com/getsentry/sentry-java/pull/4240))
- Modifications to OkHttp requests are now properly propagated to the affected span / breadcrumbs ([#4238](https://github.com/getsentry/sentry-java/pull/4238))
- Please ensure the SentryOkHttpInterceptor is added last to your OkHttpClient, as otherwise changes to the `Request` by subsequent interceptors won't be considered
- Fix "class ch.qos.logback.classic.spi.ThrowableProxyVO cannot be cast to class ch.qos.logback.classic.spi.ThrowableProxy" ([#4206](https://github.com/getsentry/sentry-java/pull/4206))
- In this case we cannot report the `Throwable` to Sentry as it's not available
- If you are using OpenTelemetry v1 `OpenTelemetryAppender`, please consider upgrading to v2

### Features

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,16 @@ protected void append(@NotNull ILoggingEvent eventObject) {
event.setLogger(loggingEvent.getLoggerName());
event.setLevel(formatLevel(loggingEvent.getLevel()));

final ThrowableProxy throwableInformation = (ThrowableProxy) loggingEvent.getThrowableProxy();
if (throwableInformation != null) {
final Mechanism mechanism = new Mechanism();
mechanism.setType(MECHANISM_TYPE);
final Throwable mechanismException =
new ExceptionMechanismException(
mechanism, throwableInformation.getThrowable(), Thread.currentThread());
event.setThrowable(mechanismException);
if (loggingEvent.getThrowableProxy() instanceof ThrowableProxy) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's nothing else we can do here. In case we can't cast to ThrowableProxy, we cannot access the Throwable meaning we can't report the exception to Sentry.

final ThrowableProxy throwableInformation = (ThrowableProxy) loggingEvent.getThrowableProxy();
if (throwableInformation != null) {
final Mechanism mechanism = new Mechanism();
mechanism.setType(MECHANISM_TYPE);
final Throwable mechanismException =
new ExceptionMechanismException(
mechanism, throwableInformation.getThrowable(), Thread.currentThread());
event.setThrowable(mechanismException);
}
}

if (loggingEvent.getThreadName() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import ch.qos.logback.classic.Level
import ch.qos.logback.classic.LoggerContext
import ch.qos.logback.classic.encoder.PatternLayoutEncoder
import ch.qos.logback.classic.spi.ILoggingEvent
import ch.qos.logback.classic.spi.LoggingEvent
import ch.qos.logback.classic.spi.LoggingEventVO
import ch.qos.logback.classic.spi.ThrowableProxy
import ch.qos.logback.core.encoder.Encoder
import ch.qos.logback.core.encoder.EncoderBase
import ch.qos.logback.core.status.Status
Expand Down Expand Up @@ -536,4 +539,24 @@ class SentryAppenderTest {
assertTrue(Sentry.isEnabled())
System.clearProperty("sentry.dsn")
}

@Test
fun `does not crash on ThrowableProxyVO`() {
fixture = Fixture()
val throwableProxy = ThrowableProxy(RuntimeException("hello proxy throwable"))
val loggingEvent = LoggingEvent()
loggingEvent.level = Level.ERROR
loggingEvent.setThrowableProxy(throwableProxy)
val loggingEventVO = LoggingEventVO.build(loggingEvent)

fixture.appender.append(loggingEventVO)

verify(fixture.transport).send(
checkEvent { event ->
assertEquals(SentryLevel.ERROR, event.level)
assertNull(event.exceptions)
},
anyOrNull()
)
}
}
Loading