inspectIT / inspectit-ocelot

inspectIT Ocelot - Java agent for collecting application performance, tracing and behavior data
http://www.inspectit.rocks/
Apache License 2.0
204 stars 69 forks source link

[Bug] - Agent throws exception if logback config contains net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder #1546

Closed heiko-holz closed 1 year ago

heiko-holz commented 1 year ago

Describe the bug When the Java application or the inspectIT Ocelot agent is configured to use a custom configuration file (e.g., -Dlogback.configurationFIle=path/to/logback-config.xml or -Dinspectit.logging.config-file:path/to/logback-config.xml), the agent throws the following exception. This is because the dependency to net.logstash.logback:logstash-logback-encoder is missing in inspectIT Ocelot, which is needed by the logback configuration.

Exception:

07:43:58,896 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [./log/logback-config.xml] at [file:/C:/Users/HHO/dev/inspectit/inspectic-ocelot-playground/./log/logback-config.xml]
07:43:58,950 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set
07:43:58,953 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - Will scan for changes in [file:/C:/Users/HHO/dev/inspectit/inspectic-ocelot-playground/./log/logback-config.xml] 
07:43:58,953 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - Setting ReconfigureOnChangeTask scanning period to 30 minutes
07:43:58,954 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
07:43:58,956 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [STDOUT]
07:43:58,960 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
07:43:58,976 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
07:43:58,976 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [StdoutJsonAppender]
07:43:58,977 |-ERROR in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Could not create component [encoder] of type [net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder] java.lang.ClassNotFoundException: net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder
    at java.lang.ClassNotFoundException: net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder
    at  at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    at  at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
    at  at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
    at  at ch.qos.logback.core.util.Loader.loadClass(Loader.java:120)
    at  at ch.qos.logback.core.joran.action.NestedComplexPropertyIA.begin(NestedComplexPropertyIA.java:102)
    at  at ch.qos.logback.core.joran.spi.Interpreter.callBeginAction(Interpreter.java:269)
    at  at ch.qos.logback.core.joran.spi.Interpreter.startElement(Interpreter.java:145)
    at  at ch.qos.logback.core.joran.spi.Interpreter.startElement(Interpreter.java:128)
    at  at ch.qos.logback.core.joran.spi.EventPlayer.play(EventPlayer.java:50)
    at  at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:165)
    at  at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:152)
    at  at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:110)
    at  at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:53)
    at  at ch.qos.logback.classic.util.ContextInitializer.configureByResource(ContextInitializer.java:64)
    at  at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:134)
    at  at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:84)
    at  at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:55)
    at  at org.slf4j.LoggerFactory.bind(LoggerFactory.java:150)
    at  at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:124)
    at  at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:417)
    at  at rocks.inspectit.ocelot.core.logging.logback.LogbackInitializer.initLogging(LogbackInitializer.java:84)
    at  at rocks.inspectit.ocelot.core.logging.logback.LogbackInitializer.initDefaultLogging(LogbackInitializer.java:70)
    at  at rocks.inspectit.ocelot.core.AgentImpl.<clinit>(AgentImpl.java:53)
    at  at java.lang.Class.forName0(Native Method)
    at  at java.lang.Class.forName(Class.java:348)
    at  at rocks.inspectit.ocelot.bootstrap.AgentManager.startOrReplaceInspectitCore(AgentManager.java:40)
    at  at rocks.inspectit.ocelot.agent.AgentMain.startAgent(AgentMain.java:110)
    at  at rocks.inspectit.ocelot.agent.AgentMain.lambda$premain$0(AgentMain.java:93)
    at  at java.lang.Thread.run(Thread.java:748)

Logback configuration:

<configuration scan="true" scanPeriod="30 minutes" packagingData="true">
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <!-- encoders are  by default assigned the type
             ch.qos.logback.classic.encoder.PatternLayoutEncoder -->
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>

    <appender name="StdoutJsonAppender" class="ch.qos.logback.core.ConsoleAppender">
        <encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
            <providers>
                <mdc>
                    <mdcKeyFieldName>CUSTOM_CORRELATION_ID=correlationId</mdcKeyFieldName>
                    <mdcKeyFieldName>CUSTOM_USERINFO=userId</mdcKeyFieldName>
                </mdc>
                <pattern>
                    <pattern>
                        { "loglevel": "%level", "ibm_datetime": "%d{yyyy-MM-dd'T'HH:mm:ss.SSSZ}", "type": "iact_message", "loggerName": "%logger","thread": "%thread","message": "%message", "exception": "%exception" }
                    </pattern>
                </pattern>
            </providers>
        </encoder>
    </appender>

    <root level="info">
        <appender-ref ref="StdoutJsonAppender" />
    </root>

</configuration>

To Reproduce Steps to reproduce the behavior:

  1. Use the above logback configuration
  2. Run the Java application with -Dlogback.configurationFile=/path/to/logback-configuration.xml
  3. See error

Expected behavior I'd like to be able to use the logback configuration file.

The easiest solution is to add the required dependency to the inspectIT Ocelot agent.