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

Unable to use native boot with Loki4jAppender #44016

Closed
fkjaekel opened this issue Jan 29, 2025 · 6 comments
Closed

Unable to use native boot with Loki4jAppender #44016

fkjaekel opened this issue Jan 29, 2025 · 6 comments
Labels
status: superseded An issue that has been superseded by another type: bug A general bug

Comments

@fkjaekel
Copy link

fkjaekel commented Jan 29, 2025

I found this issue, but in my case the loki endpoint has authentication.

Error:

ERROR in ch.qos.logback.core.model.processor.ImplicitModelHandler - Could not find an appropriate class for property [auth]

Stacktrace:

13:11:52.116 [main] INFO org.springframework.boot.devtools.restart.RestartApplicationListener -- Restart disabled due to context in which it is running
13:11:52,146 |-WARN in ch.qos.logback.core.model.processor.AppenderModelHandler - Appender named [LOKI_PRODUCTION] not referenced. Skipping further processing.
Logging system failed to initialize using configuration from 'null'
java.lang.IllegalStateException: Logback configuration error detected: 
ERROR in ch.qos.logback.core.model.processor.ImplicitModelHandler - Could not find an appropriate class for property [auth]
        at org.springframework.boot.logging.logback.LogbackLoggingSystem.reportConfigurationErrorsIfNecessary(LogbackLoggingSystem.java:291)
        at org.springframework.boot.logging.logback.LogbackLoggingSystem.initializeFromAotGeneratedArtifactsIfPossible(LogbackLoggingSystem.java:222)
        at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:196)
        at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:332)
        at org.springframework.boot.context.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:298)
        at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:246)
        at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:223)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:185)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:178)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:156)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:138)
        at org.springframework.boot.context.event.EventPublishingRunListener.multicastInitialEvent(EventPublishingRunListener.java:136)
        at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:81)
        at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:64)
        at [email protected]/java.lang.Iterable.forEach(Iterable.java:75)
        at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:118)
        at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:112)
        at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:63)
        at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:353)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:313)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1361)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1350)
        at br.com.digital.core.CoreApplication.main(CoreApplication.java:14)
        at [email protected]/java.lang.invoke.LambdaForm$DMH/sa346b79c.invokeStaticInit(LambdaForm$DMH)
Application run failed
java.lang.IllegalStateException: java.lang.IllegalStateException: Logback configuration error detected: 
ERROR in ch.qos.logback.core.model.processor.ImplicitModelHandler - Could not find an appropriate class for property [auth]
        at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:347)
        at org.springframework.boot.context.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:298)
        at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:246)
        at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:223)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:185)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:178)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:156)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:138)
        at org.springframework.boot.context.event.EventPublishingRunListener.multicastInitialEvent(EventPublishingRunListener.java:136)
        at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:81)
        at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:64)
        at [email protected]/java.lang.Iterable.forEach(Iterable.java:75)
        at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:118)
        at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:112)
        at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:63)
        at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:353)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:313)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1361)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1350)
        at br.com.digital.core.CoreApplication.main(CoreApplication.java:14)
        at [email protected]/java.lang.invoke.LambdaForm$DMH/sa346b79c.invokeStaticInit(LambdaForm$DMH)
Caused by: java.lang.IllegalStateException: Logback configuration error detected: 
ERROR in ch.qos.logback.core.model.processor.ImplicitModelHandler - Could not find an appropriate class for property [auth]
        at org.springframework.boot.logging.logback.LogbackLoggingSystem.reportConfigurationErrorsIfNecessary(LogbackLoggingSystem.java:291)
        at org.springframework.boot.logging.logback.LogbackLoggingSystem.initializeFromAotGeneratedArtifactsIfPossible(LogbackLoggingSystem.java:222)
        at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:196)
        at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:332)
        ... 20 more
Exception in thread "main" java.lang.IllegalStateException: java.lang.IllegalStateException: Logback configuration error detected: 
ERROR in ch.qos.logback.core.model.processor.ImplicitModelHandler - Could not find an appropriate class for property [auth]
        at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:347)
        at org.springframework.boot.context.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:298)
        at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:246)
        at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:223)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:185)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:178)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:156)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:138)
        at org.springframework.boot.context.event.EventPublishingRunListener.multicastInitialEvent(EventPublishingRunListener.java:136)
        at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:81)
        at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:64)
        at [email protected]/java.lang.Iterable.forEach(Iterable.java:75)
        at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:118)
        at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:112)
        at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:63)
        at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:353)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:313)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1361)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1350)
        at br.com.digital.core.CoreApplication.main(CoreApplication.java:14)
        at [email protected]/java.lang.invoke.LambdaForm$DMH/sa346b79c.invokeStaticInit(LambdaForm$DMH)
Caused by: java.lang.IllegalStateException: Logback configuration error detected: 
ERROR in ch.qos.logback.core.model.processor.ImplicitModelHandler - Could not find an appropriate class for property [auth]
        at org.springframework.boot.logging.logback.LogbackLoggingSystem.reportConfigurationErrorsIfNecessary(LogbackLoggingSystem.java:291)
        at org.springframework.boot.logging.logback.LogbackLoggingSystem.initializeFromAotGeneratedArtifactsIfPossible(LogbackLoggingSystem.java:222)
        at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:196)
        at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:332)
        ... 20 more

logback-spring.xml:

<?xml version="1.0" encoding="UTF-8"?>

<!-- https://loki4j.github.io/loki-logback-appender/docs/configuration -->

<configuration>        
	<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
	<include resource="org/springframework/boot/logging/logback/console-appender.xml" />

    <springProperty scope="context" name="appName" source="spring.application.name"/>

    <appender name="LOKI_STAGING" class="com.github.loki4j.logback.Loki4jAppender">
        <http>
            <url>https://logs-prod-024.grafana.net/loki/api/v1/push</url>
            <auth>
                <username>${GRAFANA_USERNAME_STAGING}</username>
                <password>${GRAFANA_PASSWORD_STAGING}</password>
            </auth>
            <tenantId>${TENANT_ID}</tenantId>
            <requestTimeoutMs>30000</requestTimeoutMs>
        </http>
        <format>
            <label>
                <pattern>app=${appName},host=${HOSTNAME},tenant=${TENANT_ID},subtenant=${SUB_TENANT_ID},level=%level</pattern>
                <readMarkers>true</readMarkers>
            </label>
            <message>
                <pattern>
                    "%message"
                </pattern>
            </message>
         </format>
     </appender>

   	<appender name="LOKI_PRODUCTION" class="com.github.loki4j.logback.Loki4jAppender">
        <http>
            <url>https://logs-prod-024.grafana.net/loki/api/v1/push</url>
            <auth>
                <username>${GRAFANA_USERNAME_PRODUCTION}</username>
                <password>${GRAFANA_PASSWORD_PRODUCTION}</password>
            </auth>
            <tenantId>${TENANT_ID}</tenantId>
            <requestTimeoutMs>30000</requestTimeoutMs>
        </http>
        <format>
            <label>
                <pattern>app=${appName},host=${HOSTNAME},tenant=${TENANT_ID},subtenant=${SUB_TENANT_ID},level=%level</pattern>
                <readMarkers>true</readMarkers>
            </label>
            <message>
                <pattern>
                    "%message"
                </pattern>
            </message>
         </format>
     </appender>

    <springProfile name="staging">
        <root level="INFO">
            <appender-ref ref="LOKI_STAGING" />
            <appender-ref ref="CONSOLE"/>
        </root>
    </springProfile>

    <springProfile name="production">
        <root level="INFO">
            <appender-ref ref="LOKI_PRODUCTION" />
            <appender-ref ref="CONSOLE"/>
        </root>
    </springProfile>

    <springProfile name="!production &amp; !staging">
        <root level="INFO">
            <appender-ref ref="CONSOLE"/>
        </root>
    </springProfile>
</configuration>

I tried to add @RegisterReflection(classes = {Loki4jAppender.class, JavaHttpSender.class, ApacheHttpSender.class}) in a @Configuration but it didn't work

Spring boot version is 3.4.2

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 29, 2025
@fkjaekel
Copy link
Author

loki-logback-appender version is 1.6.0

nosan added a commit to nosan/spring-boot that referenced this issue Jan 29, 2025
Signed-off-by: Dmytro Nosan <[email protected]>
@nosan
Copy link
Contributor

nosan commented Jan 29, 2025

reflect-config.json file contains incorrect data for AbstractHttpSender.BasicAuth nested class.

Generated value:

  {
    "name": "com.github.loki4j.logback.AbstractHttpSender.BasicAuth",
    "allPublicConstructors": true,
    "queryAllPublicMethods": true,
    "allPublicMethods": true
  }

the name property should be com.github.loki4j.logback.AbstractHttpSender$BasicAuth instead of com.github.loki4j.logback.AbstractHttpSender.BasicAuth

I've fixed it in main...nosan:spring-boot:44016

This should probably be fixed in version 3.4.x.

Meanwhile, you can create your own META-INF/native-image/com/test1/reflect-config.json with the following content to fix this issue:

[
  {
    "name": "com.github.loki4j.logback.AbstractHttpSender$BasicAuth",
    "allPublicConstructors": true,
    "queryAllPublicMethods": true,
    "allPublicMethods": true
  }
]

@wilkinsona
Copy link
Member

Thanks very much, @nosan. Would you like to turn main...nosan:spring-boot:44016 into a PR?

nosan added a commit to nosan/spring-boot that referenced this issue Jan 30, 2025
…nner class

Prior to this commit, the generated name for inner class had a wrong
format <package>.<parent>.<child> (canonical name). GraalVM expects $
to  separate the parent from the inner class.

This commit updates SpringBootJoranConfigurator to generate an
appropriate format for a class name. Specifically, an
inner class should be separated by a dollar sign, not a dot.

See spring-projectsgh-44016

Signed-off-by: Dmytro Nosan <[email protected]>
nosan added a commit to nosan/spring-boot that referenced this issue Jan 30, 2025
Prior to this commit, the generated name for inner class had a wrong
format <package>.<parent>.<child> (canonical name). GraalVM expects $
to  separate the parent from the inner class.

This commit updates SpringBootJoranConfigurator to generate an
appropriate format for a class name. Specifically, an
inner class should be separated by a dollar sign, not a dot.

See spring-projectsgh-44016

Signed-off-by: Dmytro Nosan <[email protected]>
nosan added a commit to nosan/spring-boot that referenced this issue Jan 30, 2025
Before this commit, the generated name for the inner class had
a wrong format <package>.<parent>.<child> (canonical name).
GraalVM expects $ to separate the parent from the inner class.

This commit updates SpringBootJoranConfigurator to generate
an appropriate format for a class name. Specifically, an inner class
should be separated by a dollar sign, not a dot.

See spring-projectsgh-44016

Signed-off-by: Dmytro Nosan <[email protected]>
nosan added a commit to nosan/spring-boot that referenced this issue Jan 30, 2025
Before this commit, the generated name for the inner class had
a wrong format <package>.<parent>.<child> (canonical name).
GraalVM expects $ to separate the parent from the inner class.

This commit updates SpringBootJoranConfigurator to generate
an appropriate format for a class name. Specifically, an inner class
should be separated by a dollar sign, not a dot.

See spring-projectsgh-44016

Signed-off-by: Dmytro Nosan <[email protected]>
nosan added a commit to nosan/spring-boot that referenced this issue Jan 30, 2025
Before this commit, the generated name for the inner class had
a wrong format <package>.<parent>.<child> (canonical name).
GraalVM expects $ to separate the parent from the inner class.

This commit updates SpringBootJoranConfigurator to generate
an appropriate format for a class name. Specifically, an inner class
should be separated by a dollar sign, not a dot.

See spring-projectsgh-44016

Signed-off-by: Dmytro Nosan <[email protected]>
@nosan
Copy link
Contributor

nosan commented Jan 30, 2025

Sure, @wilkinsona

#44021

nosan added a commit to nosan/spring-boot that referenced this issue Jan 30, 2025
Before this commit, the generated name for the inner class had the
wrong format <package>.<parent>.<child> (canonical name).
GraalVM expects $ to separate the parent from the inner class.

This commit updates SpringBootJoranConfigurator to generate
an appropriate format for a class name. Specifically, an inner class
should be separated by a dollar sign, not a dot.

See spring-projectsgh-44016

Signed-off-by: Dmytro Nosan <[email protected]>
@wilkinsona
Copy link
Member

Thanks again! Closing in favor of #44021.

@wilkinsona wilkinsona closed this as not planned Won't fix, can't repro, duplicate, stale Jan 30, 2025
@wilkinsona wilkinsona added type: bug A general bug status: superseded An issue that has been superseded by another and removed status: waiting-for-triage An issue we've not yet triaged labels Jan 30, 2025
@fkjaekel
Copy link
Author

Thanks a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: superseded An issue that has been superseded by another type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants