0

I have a spring cloud stream app chaining together some functions. I need a nice way to log time taken for each function without having to wrap the logic for each in log and timing statements. I can do it if I write the function as an anonymous inner class and annotate the apply method but its a bit ugly

spring: cloud: function: definition: f1|f2|f3

@Bean
public Function<Message<String>, Message<String>> f1(){
  return f -> {
        do stuff
         return f;
    };
 }

public Function<Message<String>, Message<String>> f1(){
  return new Function<Message<String>, Message<String>>(){
    @LogTiming(name = f1)
    public Message<String> apply(Message<String> msg){  

 }

Any tips/examples would be great

  • 1
    Hi & Welcome! [Spring-cloud-sleuth](https://docs.spring.io/spring-cloud-sleuth/docs/current/reference/html/getting-started.html#getting-started) sounds like matching your needs: "Spring Cloud Sleuth provides API for distributed tracing solution for Spring Cloud." ..."Span: The basic unit of work. ...Spans can be started and stopped, and they keep track of their timing information. Once you create a span, you must stop it at some point in the future." – xerx593 Jan 18 '22 at 09:24
  • I tested this, it will give you the time for f1|f2|f3 but not the individual functions. I managed to get it to log time taken using Aop @Around("bean(f1)") however, it involved knowing the names of the beans – greenstreetmatt Jan 25 '22 at 10:56

0 Answers0