open-telemetry / opentelemetry-java-instrumentation

OpenTelemetry auto-instrumentation and instrumentation libraries for Java
https://opentelemetry.io
Apache License 2.0
1.96k stars 857 forks source link

Logback instrumentation not working #9819

Closed trajano closed 12 months ago

trajano commented 1 year ago

Is your feature request related to a problem? Please describe.

I'd like to avoid having to write anything OTEL specific in the application. Is it possible for the agent to autoconfigure logback adding the appender in dynamically rather than adding the dependencies specified in

https://github.com/open-telemetry/opentelemetry-java-instrumentation/tree/main/instrumentation/logback/logback-appender-1.0/library

Describe the solution you'd like

Allow us to specify the logger system that would be instrumented also allow for multiple if possible

OTEL_JAVAAGENT_LOGGER=logback
OTEL_JAVAAGENT_LOGGER=logback,log4j2

Describe alternatives you've considered

Manual instrumentation of logger using instructions in https://github.com/open-telemetry/opentelemetry-java-instrumentation/tree/main/instrumentation/logback/logback-appender-1.0/library

Additional context

No response

trajano commented 1 year ago

I may be doing it wrong, but I am using Spring Boot with logback-spring.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <include resource="org/springframework/boot/logging/logback/defaults.xml"/>
    <include resource="org/springframework/boot/logging/logback/console-appender.xml"/>
    <appender name="JSON" class="ch.qos.logback.core.ConsoleAppender">
        <encoder class="net.logstash.logback.encoder.LogstashEncoder" />
    </appender>
    <!--ADDED THIS-->
    <appender name="OTEL"
              class="io.opentelemetry.instrumentation.logback.appender.v1_0.OpenTelemetryAppender">
    </appender>
    <root level="${LOGGING_LEVEL_ROOT:-INFO}">
        <appender-ref ref="${LOGGING_APPENDER:-JSON}"/>
        <appender-ref ref="OTEL"/> <!--ADDED -->
    </root>
    <logger name="nil">
        <appender-ref ref="CONSOLE"/>
        <appender-ref ref="JSON"/>
    </logger>
</configuration>

I did notice it in the end that according to the documentation it may be done by automatically already. But when I do a open telemetry collector with

    logs:
      receivers: [otlp]
      exporters: [debug]

Nothing appears in the logs indicating it had received any data

trajano commented 1 year ago

I am guessing the code that hooks it together is this one https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/23a6a3e2c017d531623ee22dbbe426e8bf160dd9/instrumentation/logback/logback-appender-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/logback/appender/v1_0/LogbackInstrumentation.java#L33-L41

I tried to remove the logback-spring.xml still no luck my log line https://github.com/trajano/simple-auth/blob/c35c48196c15780bed6abc90a771247990ed5576/src/main/kotlin/net/trajano/simpleauth/RootController.kt#L48 just doesn't appear

trajano commented 1 year ago

dropping this, looking at the code it appears to have an implementation but it's not working from what I can tell so it's not a feature request.

laurit commented 1 year ago

@trajano logs exporter is not enabled by default in the java agent (will change in 2.0) you'll have to manually enable it with OTEL_LOGS_EXPORTER=otlp. You should remove all the manual steps you made, library instrumentations are meant to be used without the java agent. With java agent you should not need to add additional dependencies and logger configuration changes.

trajano commented 1 year ago

exporter is not enabled by default Where would that have been written I missed that.

trask commented 1 year ago

exporter is not enabled by default Where would that have been written I missed that.

it's a confusing situation currently because we didn't want to suddenly start emitting logs in a minor version update of the agent, but the agent docs point to the underlying SDK docs where otlp is the default logs exporter

this should all get resolved in December when we release 2.0, sorry about the confusion

trajano commented 12 months ago

TL;DR you need OTEL_LOGS_EXPORTER=otlp in envs.

swaroopar commented 11 months ago

@trajano Sorry to write on this closed issue. I have exactly the same issue. I cannot get the logs from logback exported to otel collector even after adding the env variable. I opened a discussion as well. Could you please check if even you used the same single dependency as I did? Thanks in advance.