0

My company has got custom distributed tracing solution. I've got Java client/proxy library ready for it, its able to send traces/spans to server.

However I would like to integrate it with Spring Boot Sleuth / Brave, so to implement some kind of bridge from Brave, so brave would use my client/proxy libraries to send traces/spans.

How to customize only sender part in Brave ?

Another approach is to implement from scratch all Sleuth api interfaces (Tracer, Span, TraceContext, ... etc) which is a huge task.

I would like to use Brave implementation, only to inject some kind of bridge/adapter which will use my custom client/proxy.

Tomasz Modelski
  • 412
  • 6
  • 10

1 Answers1

1

I don't recommend implementing all the Sleuth interfaces, in that case you are writing a Tracing library (you are rewriting Brave).

You can implement the zipkin2.reporter.Sender interface and create a @Bean from it, here is an example:

public class SoutSender extends Sender {
    @Override
    public Encoding encoding() {
        return JSON;
    }

    @Override
    public int messageMaxBytes() {
        return 500 * 1024; //500 KiB
    }

    @Override
    public int messageSizeInBytes(List<byte[]> encodedSpans) {
        return encodedSpans.stream()
                .mapToInt(encodedSpan -> encodedSpan.length)
                .sum();
    }

    @Override
    public Call<Void> sendSpans(List<byte[]> encodedSpans) {
        encodedSpans.stream()
                .map(String::new)
                .forEach(System.out::println);

        return Call.create(null);
    }
}

You need to create a Reporter<zipkin2.Span> bean too but for this, you don't need to implement anything:

@Bean
Reporter<Span> soutReporter(SoutSender soutSender) {
    return AsyncReporter.create(soutSender);
}

@Bean
Sender soutSender(SoutSender sender) {
    return new SoutSender();
}

This will register an additional reporter, if you only want to keep yours and don't want to report to zipkin and to your own system, you need to name the beans accordingly, please see the docs: https://docs.spring.io/spring-cloud-sleuth/docs/current/reference/html/project-features.html#overriding-the-auto-configuration-of-zipkin

Jonatan Ivanov
  • 4,895
  • 2
  • 15
  • 30
  • Thanks for help. I see one problem with implementing custom zipkin.Sender : I need to parse byte[] trace to any kind of object model, at least Map. Any tips in this topic ? Btw. I've checked Google GCP SpringBoot starter, they're exactly implementing their own Sender - but is it not performance overhead? in such scenario there's additional serialization to byte[] and then deserialization from it. – Tomasz Modelski Dec 15 '21 at 12:45
  • 1
    Oh I see, so you don't want to use the Zipkin format at all? The Sender is the last step before sending, the bytes in the Sender API are the bytes that you send through the wire. You can implement your own Reporter to convert the Span into your own representation (`void report(Span span)`). – Jonatan Ivanov Dec 15 '21 at 18:19
  • Above comment from Jonatan Ivanov is proper answer for my question. Thanks ! – Tomasz Modelski Apr 06 '22 at 07:29