Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dependency versions mismatch in v2.8.0-alpha #12299

Closed
greatvovan opened this issue Sep 19, 2024 · 4 comments
Closed

Dependency versions mismatch in v2.8.0-alpha #12299

greatvovan opened this issue Sep 19, 2024 · 4 comments
Labels
bug Something isn't working needs triage New issue that requires triage

Comments

@greatvovan
Copy link
Contributor

greatvovan commented Sep 19, 2024

Describe the bug

AppenderLoggingException on logging with Appenders by opentelemetry-log4j-appender-2.17, opentelemetry-logback-appender-1.0 of version 2.8.0-alpha.

Steps to reproduce

  1. sbt:
libraryDependencies += "org.apache.logging.log4j" % "log4j-core" % "2.24.0"
libraryDependencies += "org.apache.logging.log4j" % "log4j-api" % "2.24.0"
libraryDependencies += "io.opentelemetry.instrumentation" % "opentelemetry-log4j-appender-2.17" % "2.8.0-alpha"
libraryDependencies += "org.slf4j" % "slf4j-simple" % "2.0.16"
libraryDependencies += "com.azure" % "azure-monitor-opentelemetry-exporter" % "1.0.0-beta.28"
  1. Scala:
object Main extends App {
  var aiConnStr = "..."

  import org.apache.logging.log4j.LogManager
  import org.apache.logging.log4j.Level
  import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilderFactory
  import org.apache.logging.log4j.core.config.Configurator
  import io.opentelemetry.instrumentation.log4j.appender.v2_17.OpenTelemetryAppender
  import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk
  import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder
  import com.azure.monitor.opentelemetry.exporter.AzureMonitorExporterBuilder

  val configBuilder = ConfigurationBuilderFactory.newConfigurationBuilder()
  val configuration = configBuilder
    .add(
      configBuilder
        .newAppender("Otel", "OpenTelemetry")
    )
    .add(
      configBuilder 
        .newRootLogger(Level.INFO)
        .add(configBuilder.newAppenderRef("Otel"))
    )
    .build(false)
  Configurator.initialize(configuration)

  val logger = LogManager.getLogger()

  val sdkBuilder = AutoConfiguredOpenTelemetrySdk.builder()

  new AzureMonitorExporterBuilder()
      .connectionString(aiConnStr)
      .install(sdkBuilder)

  val openTelemetry = sdkBuilder.build().getOpenTelemetrySdk()      
  OpenTelemetryAppender.install(openTelemetry)

  logger.info("Test")
}
  1. sbt
    run

Expected behavior

Logging works emitting a message. No exceptions are thrown.

Actual behavior

Error::

ERROR An exception occurred processing Appender Otel org.apache.logging.log4j.core.appender.AppenderLoggingException: java.lang.NoClassDefFoundError: io/opentelemetry/api/incubator/logs/AnyValue

        at org.apache.logging.log4j.core.config.AppenderControl.tryCallAppender(AppenderControl.java:164)
        at org.apache.logging.log4j.core.config.AppenderControl.callAppender0(AppenderControl.java:133)
        at org.apache.logging.log4j.core.config.AppenderControl.callAppenderPreventRecursion(AppenderControl.java:124)
        at org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:88)
        at org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:714)
        at org.apache.logging.log4j.core.config.LoggerConfig.processLogEvent(LoggerConfig.java:672)
        at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:648)
        at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:584)
        at org.apache.logging.log4j.core.config.AwaitCompletionReliabilityStrategy.log(AwaitCompletionReliabilityStrategy.java:92)
        at org.apache.logging.log4j.core.Logger.log(Logger.java:240)
        at org.apache.logging.log4j.spi.AbstractLogger.tryLogMessage(AbstractLogger.java:2904)
        at org.apache.logging.log4j.spi.AbstractLogger.logMessageTrackRecursion(AbstractLogger.java:2857)
        at org.apache.logging.log4j.spi.AbstractLogger.logMessageSafely(AbstractLogger.java:2839)
        at org.apache.logging.log4j.spi.AbstractLogger.logMessage(AbstractLogger.java:2618)
        at org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:2565)
        at org.apache.logging.log4j.spi.AbstractLogger.info(AbstractLogger.java:1568)
        at Main$.delayedEndpoint$Main$1(Main.scala:39)
        at Main$delayedInit$body.apply(Main.scala:1)
        at scala.Function0.apply$mcV$sp(Function0.scala:42)
        at scala.Function0.apply$mcV$sp$(Function0.scala:42)
        at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:17)
        at scala.App.$anonfun$main$1(App.scala:98)
        at scala.App.$anonfun$main$1$adapted(App.scala:98)
        at scala.collection.IterableOnceOps.foreach(IterableOnce.scala:576)
        at scala.collection.IterableOnceOps.foreach$(IterableOnce.scala:574)
        at scala.collection.AbstractIterable.foreach(Iterable.scala:933)
        at scala.App.main(App.scala:98)
        at scala.App.main$(App.scala:96)
        at Main$.main(Main.scala:1)
        at Main.main(Main.scala)
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
        at java.base/java.lang.reflect.Method.invoke(Method.java:580)
        at sbt.Run.invokeMain(Run.scala:144)
        at sbt.Run.execute$1(Run.scala:94)
        at sbt.Run.$anonfun$runWithLoader$5(Run.scala:121)
        at sbt.Run$.executeSuccess(Run.scala:187)
        at sbt.Run.runWithLoader(Run.scala:121)
        at sbt.Defaults$.$anonfun$bgRunTask$6(Defaults.scala:2038)
        at sbt.Defaults$.$anonfun$termWrapper$2(Defaults.scala:1977)
        at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
        at scala.util.Try$.apply(Try.scala:213)
        at sbt.internal.BackgroundThreadPool$BackgroundRunnable.run(DefaultBackgroundJobService.scala:367)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
        at java.base/java.lang.Thread.run(Thread.java:1570)
Caused by: java.lang.NoClassDefFoundError: io/opentelemetry/api/incubator/logs/AnyValue
        at io.opentelemetry.sdk.logs.SdkLogRecordBuilder.setBody(SdkLogRecordBuilder.java:91)
        at io.opentelemetry.sdk.logs.SdkLogRecordBuilder.setBody(SdkLogRecordBuilder.java:24)
        at io.opentelemetry.instrumentation.log4j.appender.v2_17.internal.LogEventMapper.captureMessage(LogEventMapper.java:129)
        at io.opentelemetry.instrumentation.log4j.appender.v2_17.internal.LogEventMapper.mapLogEvent(LogEventMapper.java:94)
        at io.opentelemetry.instrumentation.log4j.appender.v2_17.OpenTelemetryAppender.emit(OpenTelemetryAppender.java:303)
        at io.opentelemetry.instrumentation.log4j.appender.v2_17.OpenTelemetryAppender.append(OpenTelemetryAppender.java:247)
        at org.apache.logging.log4j.core.config.AppenderControl.tryCallAppender(AppenderControl.java:160)
        ... 44 more
Caused by: java.lang.ClassNotFoundException: io.opentelemetry.api.incubator.logs.AnyValue
        at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:445)
        at sbt.internal.ManagedClassLoader.findClass(ManagedClassLoader.java:103)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:592)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)
        ... 51 more

Javaagent or library instrumentation version

2.8.0-alpha

Environment

Scala: 2.13
OS: 14.6.1 (23G93)

Additional context

Switching to version 2.7.0-alpha fixes the problem.

@greatvovan greatvovan added bug Something isn't working needs triage New issue that requires triage labels Sep 19, 2024
@laurit
Copy link
Contributor

laurit commented Sep 19, 2024

Firstly you should check what version of opentelemetry dependencies you have. Instrumentation 2.8.0 is compatible with otel api/sdk 1.42.1. If you see a different version (which is probably so based on the exception you get) you'll have to find a way to deal with it. In maven and gradle you'd import the BOM to enforce the versions, in sbt I have no idea what you'll need to do.

@laurit laurit added the needs author feedback Waiting for additional feedback from the author label Sep 19, 2024
@greatvovan
Copy link
Contributor Author

You might be right... After inspecting the package version in runtime, opentelemetry-api was of version 1.42.1, and opentelemetry-sdk was 1.40.0. Importing opentelemetry-bom v1.42.1 did not change a thing, but

libraryDependencies += "io.opentelemetry" % "opentelemetry-sdk" % "1.42.1"

did.
It is unfortunate that the default referenced versions are inconsistent.

@github-actions github-actions bot removed the needs author feedback Waiting for additional feedback from the author label Sep 20, 2024
@laurit
Copy link
Contributor

laurit commented Sep 20, 2024

It is unfortunate that the default referenced versions are inconsistent.

opentelemetry-log4j-appender-2.17 does not have a dependency on the sdk, it is users responsibility to bring in a compatible sdk. You probably get your sdk through azure-monitor-opentelemetry-exporter. Usually one would use a bom to align the versions, idk if sbt supports boms at all.

@laurit laurit added the needs author feedback Waiting for additional feedback from the author label Sep 20, 2024
@greatvovan
Copy link
Contributor Author

Anyway, I have a working solution for now. Thanks for your help.

@github-actions github-actions bot removed the needs author feedback Waiting for additional feedback from the author label Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage New issue that requires triage
Projects
None yet
Development

No branches or pull requests

2 participants