zalando / opentracing-toolbox

Best-of-breed OpenTracing utilities, instrumentations and extensions
MIT License
180 stars 46 forks source link

Synchronize SPI decorator loading #796

Closed lukasniemeier-zalando closed 1 year ago

lukasniemeier-zalando commented 1 year ago

Synchronize SPI span decorator loading and have them loaded eagerly.

Motivation and Context

  1. eagerly load decorators obtained via SPI to avoid exceptions in high-concurrency setups
  2. instances of ServiceLoader are not thread-safe, iterating on the Iterable may yield exceptions if done concurrently
  3. eager loading prevents any reloading functionality of ServiceLoader to work

Example exception (sadly ServiceLoaderSpanDecorator not rendered):

java.lang.ArrayIndexOutOfBoundsException: Index 2 out of bounds for length 2
    at java.lang.CompoundEnumeration.next(ClassLoader.java:2725)
    at java.lang.CompoundEnumeration.hasMoreElements(ClassLoader.java:2734)
    ... 30 frames excluded
    at org.zalando.fauxpas.ThrowingSupplier.get(ThrowingSupplier.java:19)
    at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1768)
    at io.opentracing.contrib.concurrent.TracedRunnable.run(TracedRunnable.java:30)
    ... 6 frames excluded
    at org.zalando.fauxpas.ThrowingFunction.apply(ThrowingFunction.java:19)
    ... 5 frames excluded

See also https://github.com/zalando/riptide/pull/1462 for the same fix

Types of changes

Checklist:

lukasniemeier-zalando commented 1 year ago

:+1:

andreyors commented 1 year ago

👍🏻

e101011 commented 1 year ago

👍