Skip to content

Commit

Permalink
Merge pull request #89 from NthPortal/small-tweaks
Browse files Browse the repository at this point in the history
A small fix and improvement
  • Loading branch information
NthPortal committed May 8, 2024
2 parents 82edd7d + a5dba72 commit 3d00753
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import com.typesafe.tools.mima.core._

ThisBuild / tlBaseVersion := "0.6" // your current series x.y
ThisBuild / tlBaseVersion := "0.7" // your current series x.y

ThisBuild / licenses := Seq(License.Apache2)
ThisBuild / developers += tlGitHubDev("rossabaker", "Ross A. Baker")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,15 @@ object ServerMiddleware {
* server span.
*/
def withAdditionalRequestAttributes(
additionalRequestAttributes: Request[F] => Seq[Attribute[_]]
additionalRequestAttributes: Request[F] => immutable.Iterable[Attribute[_]]
): ServerMiddlewareBuilder[F] =
copy(additionalRequestAttributes = additionalRequestAttributes)

/** Sets how to derive additional `Attribute`s from a response to add to the
* server span.
*/
def withAdditionalResponseAttributes(
additionalResponseAttributes: Response[F] => Seq[Attribute[_]]
additionalResponseAttributes: Response[F] => immutable.Iterable[Attribute[_]]
): ServerMiddlewareBuilder[F] =
copy(additionalResponseAttributes = additionalResponseAttributes)

Expand All @@ -164,7 +164,7 @@ object ServerMiddleware {
)(implicit kt: KindTransformer[F, G]): Http[G, F] =
Kleisli { (req: Request[F]) =>
if (
shouldTrace(req.requestPrelude) == ShouldTrace.DoNotTrace ||
!shouldTrace(req.requestPrelude).shouldTrace ||
!Tracer[F].meta.isEnabled
) {
f(req)
Expand Down
14 changes: 11 additions & 3 deletions core/src/main/scala/org/http4s/otel4s/middleware/ShouldTrace.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,21 @@
package org.http4s.otel4s.middleware

/** Whether or not to trace something. */
sealed trait ShouldTrace
sealed trait ShouldTrace {

/** Whether or not to trace something. */
def shouldTrace: Boolean
}

object ShouldTrace {

/** Trace the thing. */
case object Trace extends ShouldTrace
case object Trace extends ShouldTrace {
def shouldTrace: Boolean = true
}

/** Do not trace the thing. */
case object DoNotTrace extends ShouldTrace
case object DoNotTrace extends ShouldTrace {
def shouldTrace: Boolean = false
}
}

0 comments on commit 3d00753

Please sign in to comment.