question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

spring-cloud-stream channel instrumentation with ExtraFieldPropagation

See original GitHub issue

Hi,

I want to add ExtraFieldPropagation which also should be logged via spring-cloud-stream with Rabbit binders. Now (almost) everything works fine out of the box. I defined the MDC Data in application.yml logging.pattern.level I provide my own CustomSlf4jCurrentTraceContext extends CurrentTraceContext which puts my custom Baggage into MDC in its newScope() method and it gets propagated to my downlink µservices.

Only thing left is, that my source is called by a spring scheduler and activated/called by spring-cloud-stream:

    @SendTo(SourceChannels.OUTPUT)
    public void timerMessageSource() {
        ExtraFieldPropagation.set(sleuthTracer.currentSpan().context(), CustomSlf4jCurrentTraceContext.CUSTOM_SLEUTH_BAGGAGE_BUSINESS_PROCESS_NAME, "myCustomBpName");
        ExtraFieldPropagation.set(sleuthTracer.currentSpan().context(), CustomSlf4jCurrentTraceContext.CUSTOM_SLEUTH_BAGGAGE_BUSINESS_PROCESS_SUCC, "sink1;somethingElse");

        MessageDTO messageDTO = new MessageDTO();
        messageDTO.datetime = new Date().toString();
        messageDTO.message = "fromSource";
        log.info("[{}]Produced: '{}'", instanceIndex, messageDTO);
        sourceOutputMessageChannel.send(MessageBuilder.withPayload(messageDTO).build());
    }

now at the time I insert my custom baggage, the initial Span has already been started by spring-cloud-stream message instrumentation (or sleuth scheduler support?), and at the point I add my ExtraFieldPropagation it will not get into the currentSpan’s MDC, as the span is already started and my CustomSlf4jCurrentTraceContext has already finished being called by the instrumentation.

Hence propagation is working fine, but my log.info() inside the sender does not contain/log my extra baggage.

Is there a simple way to achieve this?

How about an Annotation which I can put on my spring-cloud-stream @SendTo(SourceChannels.OUTPUT) and @StreamListener(Tier1Channels.INPUT) methods with key/value pairs that are then accessible in its currentTraceContext so that I can do with them anything I want to do, e.g. inside my CustomSlf4jCurrentTraceContext putting them into the MDC so that already spring-cloud-stream adapter log messages for my scheduled method contain the MDC log data I want to be in there.

This way I could act on my custom baggage and alter it for logging at the point in time where spring-cloud-stream does create the new span for me and not afterwards when my business code has to try to fiddle it in backward. Plus on the receiving side, it could alter the custom baggage to be logged with the altered custom values of the receiver already on receiving by spring-cloud-stream.

thanx for feedback.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:21 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
codefromthecryptcommented, Apr 6, 2018

While a best solution might not make it for 2.0, we might be able special case ExtraFieldsPropagation meanwhile and achieve the same https://github.com/openzipkin/brave/issues/682

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spring Cloud Sleuth
A normal instrumentation pattern is to create a span representing the server side of an RPC. Extractor.extract might return a complete trace context...
Read more >
ExtraFieldPropagation (Brave 5.14.1 API) - javadoc.io
Nested classes/interfaces inherited from interface brave.propagation.Propagation · Propagation.Getter<R,​K>, Propagation.KeyFactory<K>, Propagation.
Read more >
Spring Cloud Reference - 54. Propagation | Docs4dev
This utility is used in standard instrumentation (such as HttpServerHandler ) but can also be used for custom RPC or messaging code.
Read more >
What is Spring Cloud Stream? - VMware Tanzu
Discover how to use Spring Cloud Stream, a framework for building highly scalable, event-driven microservices connected with shared messaging systems.
Read more >
How to instrument Spring Boot 3.x with Spring Cloud Stream 4 ...
The underlying KafkaTemplate does not enable micrometer tracing by default, you have to set observationEnabled to true .
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found