Skip to content

Conversation

@donbeave
Copy link
Contributor

📜 Description

15:44:34,110 |-ERROR in io.sentry.logback.SentryAppender[SENTRY_ORIGINAL] - Appender [SENTRY_ORIGINAL] failed to append. java.lang.ClassCastException: class ch.qos.logback.classic.spi.ThrowableProxyVO cannot be cast to class ch.qos.logback.classic.spi.ThrowableProxy (ch.qos.logback.classic.spi.ThrowableProxyVO and ch.qos.logback.classic.spi.ThrowableProxy are in unnamed module of loader 'app')
	at java.lang.ClassCastException: class ch.qos.logback.classic.spi.ThrowableProxyVO cannot be cast to class ch.qos.logback.classic.spi.ThrowableProxy (ch.qos.logback.classic.spi.ThrowableProxyVO and ch.qos.logback.classic.spi.ThrowableProxy are in unnamed module of loader 'app')
	at 	at io.sentry.logback.SentryAppender.createEvent(SentryAppender.java:113)
	at 	at io.sentry.logback.SentryAppender.append(SentryAppender.java:80)
	at 	at io.sentry.logback.SentryAppender.append(SentryAppender.java:41)
	at 	at ch.qos.logback.core.UnsynchronizedAppenderBase.doAppend(UnsynchronizedAppenderBase.java:85)
	at 	at ch.qos.logback.core.spi.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:51)
	at 	at io.opentelemetry.instrumentation.logback.mdc.v1_0.OpenTelemetryAppender.append(OpenTelemetryAppender.java:111)
	at 	at io.opentelemetry.instrumentation.logback.mdc.v1_0.OpenTelemetryAppender.append(OpenTelemetryAppender.java:30)
	at 	at ch.qos.logback.core.UnsynchronizedAppenderBase.doAppend(UnsynchronizedAppenderBase.java:85)
	at 	at ch.qos.logback.core.spi.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:51)
	at 	at ch.qos.logback.classic.Logger.appendLoopOnAppenders(Logger.java:272)
	at 	at ch.qos.logback.classic.Logger.callAppenders(Logger.java:259)
	at 	at ch.qos.logback.classic.Logger.buildLoggingEventAndAppend(Logger.java:426)
	at 	at ch.qos.logback.classic.Logger.filterAndLog_2(Logger.java:419)
	at 	at ch.qos.logback.classic.Logger.error(Logger.java:535)
	at 	at io.micronaut.runtime.Micronaut.handleStartupException(Micronaut.java:343)
	at 	at io.micronaut.runtime.Micronaut.start(Micronaut.java:173)
	at 	at io.micronaut.runtime.Micronaut.run(Micronaut.java:328)
	at 	at io.micronaut.runtime.Micronaut.run(Micronaut.java:314)

… to class ch.qos.logback.classic.spi.ThrowableProxy"

15:44:34,110 |-ERROR in io.sentry.logback.SentryAppender[SENTRY_ORIGINAL] - Appender [SENTRY_ORIGINAL] failed to append. java.lang.ClassCastException: class ch.qos.logback.classic.spi.ThrowableProxyVO cannot be cast to class ch.qos.logback.classic.spi.ThrowableProxy (ch.qos.logback.classic.spi.ThrowableProxyVO and ch.qos.logback.classic.spi.ThrowableProxy are in unnamed module of loader 'app')
	at java.lang.ClassCastException: class ch.qos.logback.classic.spi.ThrowableProxyVO cannot be cast to class ch.qos.logback.classic.spi.ThrowableProxy (ch.qos.logback.classic.spi.ThrowableProxyVO and ch.qos.logback.classic.spi.ThrowableProxy are in unnamed module of loader 'app')
	at 	at io.sentry.logback.SentryAppender.createEvent(SentryAppender.java:113)
	at 	at io.sentry.logback.SentryAppender.append(SentryAppender.java:80)
	at 	at io.sentry.logback.SentryAppender.append(SentryAppender.java:41)
	at 	at ch.qos.logback.core.UnsynchronizedAppenderBase.doAppend(UnsynchronizedAppenderBase.java:85)
	at 	at ch.qos.logback.core.spi.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:51)
	at 	at io.opentelemetry.instrumentation.logback.mdc.v1_0.OpenTelemetryAppender.append(OpenTelemetryAppender.java:111)
	at 	at io.opentelemetry.instrumentation.logback.mdc.v1_0.OpenTelemetryAppender.append(OpenTelemetryAppender.java:30)
	at 	at ch.qos.logback.core.UnsynchronizedAppenderBase.doAppend(UnsynchronizedAppenderBase.java:85)
	at 	at ch.qos.logback.core.spi.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:51)
	at 	at ch.qos.logback.classic.Logger.appendLoopOnAppenders(Logger.java:272)
	at 	at ch.qos.logback.classic.Logger.callAppenders(Logger.java:259)
	at 	at ch.qos.logback.classic.Logger.buildLoggingEventAndAppend(Logger.java:426)
	at 	at ch.qos.logback.classic.Logger.filterAndLog_2(Logger.java:419)
	at 	at ch.qos.logback.classic.Logger.error(Logger.java:535)
	at 	at io.micronaut.runtime.Micronaut.handleStartupException(Micronaut.java:343)
	at 	at io.micronaut.runtime.Micronaut.start(Micronaut.java:173)
	at 	at io.micronaut.runtime.Micronaut.run(Micronaut.java:328)
	at 	at io.micronaut.runtime.Micronaut.run(Micronaut.java:314)
@adinauer
Copy link
Member

Thanks for the PR, will try to take a look soon.

@adinauer
Copy link
Member

@donbeave do you think it would make sense to capture the cause from IThrowableProxy.getCause() if we can't cast to ThrowableProxy?

Can you please also share how you get logback to create an event that uses ThrowableProxyVO?

@donbeave
Copy link
Contributor Author

@donbeave do you think it would make sense to capture the cause from IThrowableProxy.getCause() if we can't cast to ThrowableProxy?
Let me check, probably yes.

Can you please also share how you get logback to create an event that uses ThrowableProxyVO?
I'm using opentelemetry-java-instrumentation 1.33.6 version.

https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/a819d579de6c170199e5831adb8b1dc3c458476f/instrumentation/logback/logback-mdc-1.0/library/src/main/java/io/opentelemetry/instrumentation/logback/mdc/v1_0/OpenTelemetryAppender.java#L106

This is where it wraps the original event with LoggingEventVO, and LoggingEventVO is using ThrowableProxyVO:

https://github.com/qos-ch/logback/blob/8968d0fd43d065f2f0e63b6679e59c89e0c2a8b8/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggingEventVO.java#L87C31-L87C47

@adinauer
Copy link
Member

Do you have an example on how to set this up so it ends up sending ThrowableProxyVO into Sentry?

@donbeave
Copy link
Contributor Author

Do you have an example on how to set this up so it ends up sending ThrowableProxyVO into Sentry?

<?xml version="1.0" encoding="UTF-8"?>
<included>
  <appender name="SENTRY_ORIGINAL" class="io.sentry.logback.SentryAppender">
    <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
      <level>WARN</level>
    </filter>
  </appender>

  <appender name="SENTRY" class="io.opentelemetry.instrumentation.logback.mdc.v1_0.OpenTelemetryAppender">
    <appender-ref ref="SENTRY_ORIGINAL"/>
  </appender>
</included>

@adinauer
Copy link
Member

Thanks I'm able to reproduce now.
This seems to be implemented differently in more recent versions of OpenTelemetry (v2) so maybe upgrading allows you to work around this issue until we merge and release this PR.

Copy link
Member

@adinauer adinauer left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @donbeave . I've added a test.

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.

@adinauer adinauer merged commit 878fd7b into getsentry:main Mar 12, 2025
34 checks passed
@donbeave
Copy link
Contributor Author

Thanks for the PR @donbeave . I've added a test.

Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants