Spring Observability questions

174 views Asked by At

I implemented code from this article: https://programmingtechie.com/2023/09/09/spring-boot3-observability-grafana-stack/

  1. Can I enable tracing only for specific endpoints ?
  2. Trace id between services pass by http header? And how Can I check it?
  3. Can I use Graylog instead of Loki ? Maybe such example available.
1

There are 1 answers

2
Jonatan Ivanov On BEST ANSWER
  1. Can I enable tracing only for specific endpoints ?

Yes you can write an ObservationPredicate and disable everything, except what you want:

@Bean
ObservationPredicate excludeServerObservations() {
    return (name, context) -> {
        if (name.equals("http.server.requests") && context instanceof ServerRequestObservationContext serverContext) {
            return serverContext.getCarrier().getRequestURI().startsWith("/endpoint");
        }
        else {
            return true;
        }
    };
}

(example)

  1. Trace id between services pass by http header? And how Can I check it?

Yes, the same way you would check anything else that is in the request: using a debugger, using rq/rs logs (e.g.: logbook), using netcat/ncat/etc., using wiremock or an httpbin-like service like httpbin.org.

  1. Can I use Graylog instead of Loki ? Maybe such example available.

Yes, that has nothing to do with Micrometer, if your loging library can send logs to Graylog, you should be ok.

Fyi: There is some likelihood that the article was made after one of the talks that one of us from the Micrometer team gave and after the demo apps of those talks. You can find the full demo app here: https://github.com/jonatan-ivanov/teahouse/ and a talk demoing the app and its capabilities: https://www.youtube.com/watch?v=HQHuFnKvk_U