Skip to content

Commit

Permalink
Merge pull request #319 from iRevive/tracer-provider-noop
Browse files Browse the repository at this point in the history
Add `TracerProvider.noop`
  • Loading branch information
iRevive authored Sep 22, 2023
2 parents c9f3ddc + 553f9da commit a4cd226
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ trait ContextPropagators[F[_]] {
}

object ContextPropagators {

/** Creates a no-op implementation of the [[ContextPropagators]].
*
* A [[TextMapPropagator]] has no-op implementation too.
*
* @tparam F
* the higher-kinded type of a polymorphic effect
*/
def noop[F[_]: Applicative]: ContextPropagators[F] =
new ContextPropagators[F] {
def textMapPropagator: TextMapPropagator[F] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ object TextMapPropagator {

def apply[F[_]](implicit ev: TextMapPropagator[F]): TextMapPropagator[F] = ev

/** Creates a no-op implementation of the [[TextMapPropagator]].
*
* All propagation operations are no-op.
*
* @tparam F
* the higher-kinded type of a polymorphic effect
*/
def noop[F[_]: Applicative]: TextMapPropagator[F] =
new TextMapPropagator[F] {
def extract[A: TextMapGetter](ctx: Vault, carrier: A): Vault =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ object Meter {

def apply[F[_]](implicit ev: Meter[F]): Meter[F] = ev

/** Creates a no-op implementation of the [[Meter]].
*
* All meter instruments ([[Counter]], [[Histogram]], etc) have no-op
* implementation too.
*
* @tparam F
* the higher-kinded type of a polymorphic effect
*/
def noop[F[_]](implicit F: Applicative[F]): Meter[F] =
new Meter[F] {
def counter(name: String): SyncInstrumentBuilder[F, Counter[F, Long]] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ trait MeterBuilder[F[_]] {
}

object MeterBuilder {

/** Creates a no-op implementation of the [[MeterBuilder]].
*
* A [[Meter]] has no-op implementation too.
*
* @tparam F
* the higher-kinded type of a polymorphic effect
*/
def noop[F[_]](implicit F: Applicative[F]): MeterBuilder[F] =
new MeterBuilder[F] {
def withVersion(version: String): MeterBuilder[F] = this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ trait MeterProvider[F[_]] {
}

object MeterProvider {

/** Creates a no-op implementation of the [[MeterProvider]].
*
* A [[MeterBuilder]] has no-op implementation too.
*
* @tparam F
* the higher-kinded type of a polymorphic effect
*/
def noop[F[_]: Applicative]: MeterProvider[F] =
new MeterProvider[F] {
def meter(name: String): MeterBuilder[F] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,13 @@ object Tracer {
}
}

/** Creates a no-op implementation of the [[Tracer]].
*
* All tracing operations are no-op.
*
* @tparam F
* the higher-kinded type of a polymorphic effect
*/
def noop[F[_]: Applicative]: Tracer[F] =
new Tracer[F] {
private val noopBackend = Span.Backend.noop
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package org.typelevel.otel4s
package trace

import cats.Applicative

trait TracerBuilder[F[_]] {

/** Assigns a version to the resulting Meter.
Expand All @@ -38,3 +40,20 @@ trait TracerBuilder[F[_]] {
def get: F[Tracer[F]]

}

object TracerBuilder {

/** Creates a no-op implementation of the [[TracerBuilder]].
*
* A [[Tracer]] has no-op implementation too.
*
* @tparam F
* the higher-kinded type of a polymorphic effect
*/
def noop[F[_]](implicit F: Applicative[F]): TracerBuilder[F] =
new TracerBuilder[F] {
def withVersion(version: String): TracerBuilder[F] = this
def withSchemaUrl(schemaUrl: String): TracerBuilder[F] = this
def get: F[Tracer[F]] = F.pure(Tracer.noop)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package org.typelevel.otel4s
package trace

import cats.Applicative

/** The entry point of the tracing API. Provides access to [[Tracer]].
*/
trait TracerProvider[F[_]] {
Expand Down Expand Up @@ -54,3 +56,19 @@ trait TracerProvider[F[_]] {
*/
def tracer(name: String): TracerBuilder[F]
}

object TracerProvider {

/** Creates a no-op implementation of the [[TracerProvider]].
*
* A [[TracerBuilder]] has no-op implementation too.
*
* @tparam F
* the higher-kinded type of a polymorphic effect
*/
def noop[F[_]: Applicative]: TracerProvider[F] =
new TracerProvider[F] {
def tracer(name: String): TracerBuilder[F] =
TracerBuilder.noop
}
}

0 comments on commit a4cd226

Please sign in to comment.