0

In past Python/Flask projects, we used Sentry tracing to track latency times in PostgreSQL tasks. Because it was a flask app, if I recall correctly, Sentry tracing would automatically track latency times of Postgres queries. I'd like to do something similar in Java, but the docs on distributed tracing support for Java are eluding me. Here are my questions:

  1. Does Sentry support Distributed Tracing for Java out of the box?
    • If so, is there documentation on how to configure?
  2. Does this support different between Spring/Vanilla Java?
  3. Is there any Framework support to automatically capture Postgres query latencies, or would we need to manually instrument our calls to DB (ie. an interceptor on the JDBC layer)?
Adam Hughes
  • 14,601
  • 12
  • 83
  • 122
  • I implemented once such tracing with Sentry, need to say that having just SQL is not enough, must be queries parameters too and they are much harder to trace. I collected both SQL and parameters from Hibernate, stored them in thread context and pushed to Sentry only on exceptions raised. – Alex Chernyshev Nov 24 '20 at 15:17
  • So did you have to manually make calls to Sentry like `Sentry.capture()`? – Adam Hughes Nov 24 '20 at 15:33
  • Bit different call but same idea yes, Sentry does not support automatic tracking for such cases. Also wouldn't be easier to use something like Micrometer? https://stackoverflow.com/questions/48704789/how-to-measure-service-methods-using-spring-boot-2-and-micrometer in your case? – Alex Chernyshev Nov 24 '20 at 15:37
  • @AlexChernyshev - honestly the value add for sentry is I can easily configure alerts/share with teammates through their web dashboard. I'd like to be able to send links of latencies to DBAs and stuff and not rely on console logs. But yes, micrometer may be a good tech to use, thanks – Adam Hughes Nov 24 '20 at 15:43
  • 1
    Actually PostgreSQL has tools to find performance bottlenecks and detect slow running queries. Also there could be issues with connection pool itself, like incorrect timeout settings. – Alex Chernyshev Nov 24 '20 at 15:50
  • We don't know exactly what queries are perofrmant or not. Are you aware of a tool in postgres that would just trace all queries over a period of a week for example? – Adam Hughes Nov 24 '20 at 15:54
  • 1
    Check Pg_stat_statements for example. – Alex Chernyshev Nov 24 '20 at 15:56
  • 1
    @AdamHughes we have just added distributed tracing for Java and Spring Boot: https://mvnrepository.com/artifact/io.sentry/sentry-spring-boot-starter/4.0.0-alpha.1 Docs are under development but you can take a look at the sample in the Github repository. It works out of the box with Spring MVC, RestTemplate and there are two custom AOP annotations SentrySpan and SentryTransaction you can use. Docs will be there soon. – Maciej Walkowiak Nov 25 '20 at 00:46
  • @MaciejWalkowiak awesome thanks - is this compatible with older springs (1.x) or only 2.x? – Adam Hughes Nov 25 '20 at 14:26
  • If Spring alone is used - Spring 4.2+, Spring Boot 2.x. Performance is made mainly with Spring Boot users in mind (at least for now). If you would like to use it without Spring Boot there are few AOP related beans to create + you would have to instrument RestTemplate by yourself. That being said, you asked about instrumenting calls to DB - this is not implemented yet. Aside from Sentry, you can use this project to send JDBC traces with Spring Cloud Sleuth: https://github.com/gavlyukovskiy/spring-boot-data-source-decorator – Maciej Walkowiak Nov 25 '20 at 21:27

0 Answers0