avinash kumar
avinash kumar

Reputation: 535

How to print traceId and spanId with brave tracing?

Earlier i used to write below code with spring boot 1.5.12 :-

 import org.springframework.cloud.sleuth.Span;

 import org.springframework.cloud.sleuth.Tracer;

@Autowired
Tracer tracer;



    Span span = this.tracer.getCurrentSpan();
    System.out.println(Span.idToHex(span.getSpanId()));
    System.out.println(Span.idToHex(span.getTraceId()));

But this code is not working with spring boot 2.2.6 .How should i print now ?

Upvotes: 0

Views: 2683

Answers (1)

Boris Chistov
Boris Chistov

Reputation: 950

import brave.Tracer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class BravePrinter {

    @Autowired
    private Tracer tracer;

    public void print() {
        var span = this.tracer.currentSpan();
        System.out.println(span.context().traceIdString());
        System.out.println(span.context().spanIdString());
    }
}

Upvotes: 2

Related Questions