0

I am using Spring Cloud Sleuth to create traces.

I am exposing a REST endpoint using Spring Boot like this:

  @SpanName("calculate-reviews") 
  @GetMapping(path = "/reviews/{productId}")
  public Reviews bookReviewsById(@PathVariable String productId) {
    
    ...
  }

My expectation would be that the span that is created by Spring Cloud Sleuth is named calculate-reviews, however, that's not the case. Instead the default span name is generated which looks like this: get /reviews/{productId}

Is there a chance to change the span name for a REST endpoint at all? How would I achieve this?

FloW
  • 139
  • 10

1 Answers1

0

I'm not sure it is a good idea to modify it. It gives you additional information that could be valuable if you don't know the service that you are calling by heart (most of the cases).

You can modify the Span using a SpanHandler: see the docs or inject the tracer, get the current span and change the name.

Jonatan Ivanov
  • 4,895
  • 2
  • 15
  • 30
  • Just out of curiosity, what happens if you put `@NewSpan("calculate-reviews")` there? – Jonatan Ivanov Apr 27 '21 at 21:56
  • Thanks Jonatan, you are right. Most likely one should just not touch the span name and stick with the meaningful default provided by Spring Sleuth. I will try the programmatic way you suggested. What do you mean by "put @NewSpan there"? Where exactly should I put it? – FloW Apr 29 '21 at 07:25
  • Replace `SpanName` with it (most probably it won't help you and it will create a new span that is not useful). – Jonatan Ivanov Apr 29 '21 at 14:08
  • Ah, sorry, I misread your comment. Yeah, @NewSpan will just add yet another span. That does not help. – FloW May 03 '21 at 07:09