getsentry / sentry-java

A Sentry SDK for Java, Android and other JVM languages.
https://docs.sentry.io/
MIT License
1.14k stars 432 forks source link

Non-blocking UUID generation for Spans #3325

Open Andrevmatias opened 5 months ago

Andrevmatias commented 5 months ago

Problem Statement

The UUID generation for Spans is made using UUID.randomUUID() deep within the library and can't be replaced easily.

UUID.randomUUID() can be a blocking method depending on the Java distribution and OS configurations and it's resulting in a lot of our threads being blocked, impairing the system performance. We don't have control over the servers were our system is installed.

Also, the Spans and Transactions are created for every request regardless of whether it will be sent to Sentry. It occurs before the sampling process and is created even if sentry.traces-sample-rate is 0 or null. This creates a lot of UUIDs that I think are not even necessary.

Solution Brainstorm

┆Issue is synchronized with this Jira Improvement by Unito

adinauer commented 5 months ago

Hello @Andrevmatias thanks for opening this issue. We'll add this to the backlog but can't say when we'll get to it.

kozaxinan commented 3 months ago

Hi we also see lots of CPU usage for Span creation. UUID generation and then string manipulation takes some time. There are lots of spans during Android app creation and navigating that accumulate easily.

I support creating UUID in the background thread before sending idea. or any expensive operation about that part should be in the background thread.

Screenshot 2024-05-27 at 22 53 34
markushi commented 3 months ago

In theory this should be straightforward:

To consider:

Angelodaniel commented 1 month ago

Hey Team, it would really help to have reduced impact on performance from the sentry library. Is there any update on this? cc @markushi

kahest commented 1 month ago

@Angelodaniel thx for the ping, we'll revisit prio for this

stefanosiano commented 1 month ago

@lbloder Can you have a look at this?