Skip to content

Commit

Permalink
Update otel4s to 0.9.0
Browse files Browse the repository at this point in the history
Adapt for breaking changes due to the introduction of span limits.
See: typelevel/otel4s#719

closes: http4s#122
  • Loading branch information
mzuehlke committed Sep 3, 2024
1 parent e62b498 commit 8bf5e24
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 19 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ val http4sV = "0.23.27"
val munitV = "1.0.0"
val munitCatsEffectV = "2.0.0"
val openTelemetryV = "1.41.0"
val otel4sV = "0.8.1"
val otel4sV = "0.9.0"
val slf4jV = "1.7.36"

// Projects
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ import org.typelevel.otel4s.Attribute
import org.typelevel.otel4s.AttributeKey
import org.typelevel.otel4s.Attributes
import org.typelevel.otel4s.sdk.testkit.trace.TracesTestkit
import org.typelevel.otel4s.sdk.trace.SpanLimits
import org.typelevel.otel4s.sdk.trace.data.EventData
import org.typelevel.otel4s.sdk.trace.data.LimitedData
import org.typelevel.otel4s.sdk.trace.data.StatusData
import org.typelevel.otel4s.trace.SpanKind
import org.typelevel.otel4s.trace.StatusCode
Expand All @@ -45,6 +47,9 @@ import scala.concurrent.duration.Duration
import scala.util.control.NoStackTrace

class ClientMiddlewareTests extends CatsEffectSuite {

private val spanLimits = SpanLimits.default

test("ClientMiddleware") {
TracesTestkit
.inMemory[IO]()
Expand Down Expand Up @@ -80,7 +85,7 @@ class ClientMiddlewareTests extends CatsEffectSuite {
assertEquals(span.kind, SpanKind.Client)
assertEquals(span.status, StatusData.Unset)

val attributes = span.attributes
val attributes = span.attributes.elements
assertEquals(attributes.size, 10)
def getAttr[A: AttributeKey.KeySelect](name: String): Option[A] =
attributes.get[A](name).map(_.value)
Expand Down Expand Up @@ -181,7 +186,13 @@ class ClientMiddlewareTests extends CatsEffectSuite {
val request = Request[IO](Method.GET, uri"http://localhost/")

val events = Vector(
EventData.fromException(Duration.Zero, error, Attributes(), escaped = false)
EventData.fromException(
Duration.Zero,
error,
LimitedData
.attributes(spanLimits.maxNumberOfAttributes, spanLimits.maxAttributeValueLength),
escaped = false,
)
)

val status = StatusData(StatusCode.Error)
Expand All @@ -199,8 +210,8 @@ class ClientMiddlewareTests extends CatsEffectSuite {
_ <- tracedClient.run(request).use_.attempt
spans <- testkit.finishedSpans
} yield {
assertEquals(spans.map(_.attributes), List(attributes))
assertEquals(spans.map(_.events), List(events))
assertEquals(spans.map(_.attributes.elements), List(attributes))
assertEquals(spans.map(_.events.elements), List(events))
assertEquals(spans.map(_.status), List(status))
}
}
Expand Down Expand Up @@ -228,7 +239,7 @@ class ClientMiddlewareTests extends CatsEffectSuite {
_ <- f.joinWithUnit
spans <- testkit.finishedSpans
} yield {
assertEquals(spans.flatMap(_.events), Nil)
assertEquals(spans.flatMap(_.events.elements), Nil)
assertEquals(spans.map(_.status), List(status))
}
}
Expand All @@ -253,7 +264,13 @@ class ClientMiddlewareTests extends CatsEffectSuite {
val request = Request[IO](Method.GET, uri"http://localhost/")

val events = Vector(
EventData.fromException(Duration.Zero, error, Attributes(), escaped = false)
EventData.fromException(
Duration.Zero,
error,
LimitedData
.attributes(spanLimits.maxNumberOfAttributes, spanLimits.maxAttributeValueLength),
escaped = false,
)
)

val status = StatusData(StatusCode.Error)
Expand All @@ -271,8 +288,8 @@ class ClientMiddlewareTests extends CatsEffectSuite {
_ <- tracedClient.run(request).surround(IO.raiseError(error)).attempt
spans <- testkit.finishedSpans
} yield {
assertEquals(spans.map(_.attributes), List(attributes))
assertEquals(spans.map(_.events), List(events))
assertEquals(spans.map(_.attributes.elements), List(attributes))
assertEquals(spans.map(_.events.elements), List(events))
assertEquals(spans.map(_.status), List(status))
}
}
Expand Down Expand Up @@ -301,7 +318,7 @@ class ClientMiddlewareTests extends CatsEffectSuite {
_ <- f.joinWithUnit
spans <- testkit.finishedSpans
} yield {
assertEquals(spans.flatMap(_.events), Nil)
assertEquals(spans.flatMap(_.events.elements), Nil)
assertEquals(spans.map(_.status), List(status))
}
}
Expand Down Expand Up @@ -339,8 +356,8 @@ class ClientMiddlewareTests extends CatsEffectSuite {
_ <- tracedClient.run(request).use_
spans <- testkit.finishedSpans
} yield {
assertEquals(spans.map(_.attributes), List(attributes))
assertEquals(spans.flatMap(_.events), Nil)
assertEquals(spans.map(_.attributes.elements), List(attributes))
assertEquals(spans.flatMap(_.events.elements), Nil)
assertEquals(spans.map(_.status), List(status))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ import org.typelevel.otel4s.Attribute
import org.typelevel.otel4s.AttributeKey
import org.typelevel.otel4s.Attributes
import org.typelevel.otel4s.sdk.testkit.trace.TracesTestkit
import org.typelevel.otel4s.sdk.trace.SpanLimits
import org.typelevel.otel4s.sdk.trace.data.EventData
import org.typelevel.otel4s.sdk.trace.data.LimitedData
import org.typelevel.otel4s.sdk.trace.data.StatusData
import org.typelevel.otel4s.trace.SpanKind
import org.typelevel.otel4s.trace.StatusCode
Expand All @@ -42,6 +44,9 @@ import scala.concurrent.duration.Duration
import scala.util.control.NoStackTrace

class ServerMiddlewareTests extends CatsEffectSuite {

private val spanLimits = SpanLimits.default

test("ServerMiddleware") {
TracesTestkit
.inMemory[IO]()
Expand Down Expand Up @@ -73,7 +78,7 @@ class ServerMiddlewareTests extends CatsEffectSuite {
assertEquals(span.kind, SpanKind.Server)
assertEquals(span.status, StatusData.Unset)

val attributes = span.attributes
val attributes = span.attributes.elements
assertEquals(attributes.size, 10)
def getAttr[A: AttributeKey.KeySelect](name: String): Option[A] =
attributes.get[A](name).map(_.value)
Expand Down Expand Up @@ -109,7 +114,13 @@ class ServerMiddlewareTests extends CatsEffectSuite {
val request = Request[IO](Method.GET, uri"http://localhost/")

val events = Vector(
EventData.fromException(Duration.Zero, error, Attributes.empty, escaped = false)
EventData.fromException(
Duration.Zero,
error,
LimitedData
.attributes(spanLimits.maxNumberOfAttributes, spanLimits.maxAttributeValueLength),
escaped = false,
)
)

val status = StatusData(StatusCode.Error)
Expand All @@ -127,8 +138,8 @@ class ServerMiddlewareTests extends CatsEffectSuite {
_ <- tracedServer.run(request).attempt
spans <- testkit.finishedSpans
} yield {
assertEquals(spans.map(_.attributes), List(attributes))
assertEquals(spans.map(_.events), List(events))
assertEquals(spans.map(_.attributes.elements), List(attributes))
assertEquals(spans.map(_.events.elements), List(events))
assertEquals(spans.map(_.status), List(status))
}
}
Expand Down Expand Up @@ -163,7 +174,7 @@ class ServerMiddlewareTests extends CatsEffectSuite {
_ <- tracedServer.run(request).attempt
spans <- testkit.finishedSpans
} yield {
assertEquals(spans.map(_.attributes), List(attributes))
assertEquals(spans.map(_.attributes.elements), List(attributes))
assertEquals(spans.map(_.status), List(status))
}
}
Expand Down Expand Up @@ -198,8 +209,8 @@ class ServerMiddlewareTests extends CatsEffectSuite {
_ <- f.joinWithUnit
spans <- testkit.finishedSpans
} yield {
assertEquals(spans.map(_.attributes), List(attributes))
assertEquals(spans.flatMap(_.events), Nil)
assertEquals(spans.map(_.attributes.elements), List(attributes))
assertEquals(spans.flatMap(_.events.elements), Nil)
assertEquals(spans.map(_.status), List(status))
}
}
Expand Down

0 comments on commit 8bf5e24

Please sign in to comment.