diff --git a/src/main/scala/reactor/core/scala/publisher/SFlux.scala b/src/main/scala/reactor/core/scala/publisher/SFlux.scala index 8fe00524..d053e4df 100644 --- a/src/main/scala/reactor/core/scala/publisher/SFlux.scala +++ b/src/main/scala/reactor/core/scala/publisher/SFlux.scala @@ -570,6 +570,17 @@ trait SFlux[T] extends SFluxLike[T, SFlux] with MapablePublisher[T] with ScalaCo final def mergeWith(other: Publisher[_ <: T]): SFlux[T] = SFlux.fromPublisher(coreFlux.mergeWith(other)) + /** + * Activate metrics for this sequence, provided there is an instrumentation facade + * on the classpath (otherwise this method is a pure no-op). + *
+ * Metrics are gathered on [[Subscriber]] events, and it is recommended to also + * [[name]] (and optionally [[tag]]) the sequence. + * + * @return an instrumented [[SFlux]] + */ + final def metrics: SFlux[T] = SFlux.fromPublisher(coreFlux.metrics()) + final def name(name: String): SFlux[T] = SFlux.fromPublisher(coreFlux.name(name)) final def next(): SMono[T] = SMono.fromPublisher(coreFlux.next()) diff --git a/src/main/scala/reactor/core/scala/publisher/SMono.scala b/src/main/scala/reactor/core/scala/publisher/SMono.scala index 9fd69e97..3d173fd1 100644 --- a/src/main/scala/reactor/core/scala/publisher/SMono.scala +++ b/src/main/scala/reactor/core/scala/publisher/SMono.scala @@ -738,8 +738,19 @@ trait SMono[T] extends SMonoLike[T, SMono] with MapablePublisher[T] with ScalaCo final def mergeWith(other: Publisher[_ <: T]): SFlux[T] = coreMono.mergeWith(other).asScala /** - * Give a name to this sequence, which can be retrieved using [[Scannable.name()]] - * as long as this is the first reachable [[Scannable.parents()]]. + * Activate metrics for this sequence, provided there is an instrumentation facade + * on the classpath (otherwise this method is a pure no-op). + *
+ * Metrics are gathered on [[Subscriber]] events, and it is recommended to also + * [[name]] (and optionally [[tag]]) the sequence. + * + * @return an instrumented [[SMono]] + */ + final def metrics: SMono[T] = SMono.fromPublisher(coreMono.metrics()) + + /** + * Give a name to this sequence, which can be retrieved using [[Scannable.name]] + * as long as this is the first reachable [[Scannable.parents]]. * * @param name a name for the sequence * @return the same sequence, but bearing a name diff --git a/src/test/scala/reactor/core/scala/publisher/SFluxTest.scala b/src/test/scala/reactor/core/scala/publisher/SFluxTest.scala index 77e375ab..dd7678d4 100644 --- a/src/test/scala/reactor/core/scala/publisher/SFluxTest.scala +++ b/src/test/scala/reactor/core/scala/publisher/SFluxTest.scala @@ -1526,6 +1526,11 @@ class SFluxTest extends AnyFreeSpec with Matchers with TableDrivenPropertyChecks .expectNext(1, 2, 3, 4, 5, 6) .verifyComplete() } + + ".metrics should be a nop since Micrometer is not on the classpath" in { + val flux = JFlux.just("plain", "awesome") + flux.asScala.metrics.coreFlux shouldBe theSameInstanceAs(flux) + } ".min" - { "of numbers should emit the lowest value of ordering" in { diff --git a/src/test/scala/reactor/core/scala/publisher/SMonoTest.scala b/src/test/scala/reactor/core/scala/publisher/SMonoTest.scala index 63533629..b2d7d95d 100644 --- a/src/test/scala/reactor/core/scala/publisher/SMonoTest.scala +++ b/src/test/scala/reactor/core/scala/publisher/SMonoTest.scala @@ -163,6 +163,11 @@ class SMonoTest extends AnyFreeSpec with Matchers with TestSupport with Idiomati } } } + + ".metrics should be a nop since Micrometer is not on the classpath" in { + val mono = JMono.just("plain awesome") + mono.asScala.metrics.coreMono shouldBe theSameInstanceAs(mono) + } ".never will never signal any data, error or completion signal" in { StepVerifier.create(SMono.never)