spring-projects-experimental / spring-cloud-sleuth-otel

Spring Cloud Sleuth support for OpenTelemetry
https://spring-projects-experimental.github.io/spring-cloud-sleuth-otel/docs/current/reference/html/
Apache License 2.0
111 stars 33 forks source link

[TraceId missing using log4j2 logger with jaeger exporter in springboot 2.6.11] #164

Closed KamJohn closed 1 year ago

KamJohn commented 1 year ago

TraceId missing using log4j2 logger with jaeger exporter

My basic framework lib versions:

springboot 2.6.11 <=> springcloud 2021.0.6 <=> springcloud-alibaba 2021.0.5 <=> springcloud -feign 3.1.6 <=> \ spring-cloud-sleuth-otel-dependencies 1.1.0 <=> opentelemetry libs 1.18.0

--- sleuth related dependencies in pom like this:

......
<dependencyManagement>
    <dependencies>
        <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-sleuth-otel-dependencies</artifactId>
                <!-- Provide the version of the Spring Cloud Sleuth OpenTelemetry project (e.g. 1.1.2) -->
                <version>${springcloud.sleuth-otel.version}</version>
                <scope>import</scope>
                <type>pom</type>
            </dependency>
        </dependencies>
    </dependencyManagement>
......
<!-- Sleuth with Brave tracer implementation -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-sleuth</artifactId>
            <exclusions>
                <!-- Exclude Brave (the default) -->
                <exclusion>
                    <groupId>org.springframework.cloud</groupId>
                    <artifactId>spring-cloud-sleuth-brave</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- Add OpenTelemetry tracer -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-sleuth-otel-autoconfigure</artifactId>
        </dependency>

        <!-- Add otlp specific exporter -->
        <dependency>
            <groupId>io.opentelemetry</groupId>
            <artifactId>opentelemetry-exporter-otlp</artifactId>
            <version>1.18.0</version>
        </dependency>

        <!-- Add otlp specific exporter -->
        <dependency>
            <groupId>io.opentelemetry</groupId>
            <artifactId>opentelemetry-exporter-jaeger</artifactId>
            <version>1.18.0</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-logging</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>*</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- log4j2-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-log4j2</artifactId>
        </dependency>
...

my sleuth configs in application.yaml

...
spring:
sleuth:
otel:
exporter:
otlp:
enabled: false
endpoint: http://jaeger:4317
timeout: 6000
jaeger:
enabled: true
endpoint: http://jaeger:14250
timeout: 6000
sleuth-span-filter:
enabled: false
config:
trace-id-ratio-based: 1
log:
exporter:
enabled: true
slf4j:
enabled: true
processor:
batch:
exporter-timeout: 6000
http:
enabled: true
tracer:
mode: auto
propagation:
type: jaeger,w3c
sampler:
probability: 100
rate: 100
web:
client:
enabled: true
...


---**---

traceId and spanId logging well in config: spring.sleuth.exporter.otlp.enabled: true and spring.sleuth.exporter.jaeger.enabled: false, but didnt working with the jaeger exporter configed only. i tried to set my log4j2.xml patterns with %X{X-B3-TraceId} or %X{traceId} , still not logging traceId out, is there any config i missed to config?

KamJohn commented 1 year ago

Resolved by exclude redundant logging lib dependencies,just keep only one logging tool for working