1

In a spring boot app, with Open Telemetry, when you have no logback.xml or logback-spring.xml there are console logs that include the traceId and spanId values.

I need to add an OpenTelemetryAppender, and thus I have to add a configuration file. This means I have to specify both OpenTelemetryAppender and ConsoleAppender, but ConsoleAppender needs an encoder and a pattern.

I don't want to change the pattern, I want to keep the existing pattern.

How could I do this?

Every attempt to specify no pattern fails with errors. Every example pattern I have found searching leaves out traceId and spanId.

2 Answers 2

0

You can add the appender programatically, like here.

You can also just use a starter that adds the appender for you:

Sign up to request clarification or add additional context in comments.

5 Comments

I'll give this method a try. Looks useful, thanks.
Nope, that won't work. At least not as is. I am not using grafana-opentelemetry-starter, so there is no LogAppenderConfigurer. Spring Boot 3.2.1 with actuator. Perhaps I can convert it to some sort of postConstruct...
I think it should work when you copy the LogAppenderConfigurer to your application.
Using Boot 3.2.1, and Actuator, there is no LogAppenderConfigurer anywhere. I think that is part of the older otlp starter library.
That's right - I'd suggest you manually copy this file to your application.
0

I found that this works just fine:

<?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="OpenTelemetry"
              class="io.opentelemetry.instrumentation.logback.appender.v1_0.OpenTelemetryAppender">
        <captureExperimentalAttributes>true</captureExperimentalAttributes>
        <captureKeyValuePairAttributes>true</captureKeyValuePairAttributes>
    </appender>
    <root level="INFO">
        <appender-ref ref="CONSOLE"/>
        <appender-ref ref="OpenTelemetry"/>
    </root>
</configuration>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.