Skip to content

Commit

Permalink
core-trace: make Backend#end public
Browse files Browse the repository at this point in the history
  • Loading branch information
iRevive committed Apr 22, 2024
1 parent 858f87e commit 3a06d12
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
12 changes: 6 additions & 6 deletions core/trace/src/main/scala/org/typelevel/otel4s/trace/Span.scala
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ object Span {
def setStatus(status: StatusCode): F[Unit]
def setStatus(status: StatusCode, description: String): F[Unit]

private[otel4s] def end: F[Unit]
private[otel4s] def end(timestamp: FiniteDuration): F[Unit]
def end: F[Unit]
def end(timestamp: FiniteDuration): F[Unit]

/** Modify the context `F` using the transformation `f`. */
def mapK[G[_]](f: F ~> G): Backend[G] = new Backend.MappedK(this)(f)
Expand Down Expand Up @@ -224,8 +224,8 @@ object Span {
def setStatus(status: StatusCode): F[Unit] = unit
def setStatus(status: StatusCode, description: String): F[Unit] = unit

private[otel4s] def end: F[Unit] = unit
private[otel4s] def end(timestamp: FiniteDuration): F[Unit] = unit
def end: F[Unit] = unit
def end(timestamp: FiniteDuration): F[Unit] = unit
}

/** Implementation for [[Backend.mapK]]. */
Expand Down Expand Up @@ -263,8 +263,8 @@ object Span {
f(backend.setStatus(status))
def setStatus(status: StatusCode, description: String): G[Unit] =
f(backend.setStatus(status, description))
private[otel4s] def end: G[Unit] = f(backend.end)
private[otel4s] def end(timestamp: FiniteDuration): G[Unit] =
def end: G[Unit] = f(backend.end)
def end(timestamp: FiniteDuration): G[Unit] =
f(backend.end(timestamp))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ private[oteljava] class SpanBackendImpl[F[_]: Sync](
()
}

private[otel4s] def end: F[Unit] =
def end: F[Unit] =
Sync[F].realTime.flatMap(now => end(now))

private[otel4s] def end(timestamp: FiniteDuration): F[Unit] =
def end(timestamp: FiniteDuration): F[Unit] =
Sync[F].delay(jSpan.end(timestamp.length, timestamp.unit))

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,18 +140,17 @@ private final class SdkSpanBackend[F[_]: Monad: Clock: Console] private (
s.copy(status = StatusData(status, description))
}.void

private[otel4s] def end: F[Unit] =
def end: F[Unit] =
for {
now <- Clock[F].realTime
_ <- end(now)
} yield ()

private[otel4s] def end(timestamp: FiniteDuration): F[Unit] = {
def end(timestamp: FiniteDuration): F[Unit] =
for {
updated <- updateState("end")(s => s.copy(endTimestamp = Some(timestamp)))
_ <- toSpanData.flatMap(span => spanProcessor.onEnd(span)).whenA(updated)
} yield ()
}

private def addTimedEvent(event: EventData): F[Unit] =
updateState("addEvent")(s => s.copy(events = s.events :+ event)).void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,10 @@ class SimpleSpanProcessorSuite
def setStatus(status: StatusCode, description: String): IO[Unit] =
noopBackend.setStatus(status, description)

private[otel4s] def end: IO[Unit] =
def end: IO[Unit] =
noopBackend.end

private[otel4s] def end(timestamp: FiniteDuration): IO[Unit] =
def end(timestamp: FiniteDuration): IO[Unit] =
noopBackend.end(timestamp)
}
}
Expand Down

0 comments on commit 3a06d12

Please sign in to comment.