Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use .to(Attributes) instead of .fromSpecific #516

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class AttributesProps extends ScalaCheckSuite {
property("Attributes#size is equal to the number of unique keys") {
forAll(listOfAttributes) { attributes =>
val keysSet = attributes.map(_.key).toSet
val attrs = Attributes.fromSpecific(attributes)
val attrs = attributes.to(Attributes)

keysSet.size == attrs.size
}
Expand All @@ -38,7 +38,7 @@ class AttributesProps extends ScalaCheckSuite {
property("Attributes#isEmpty is true when there are no attributes") {
forAll(listOfAttributes) { attributes =>
val keysSet = attributes.map(_.key).toSet
val attrs = Attributes.fromSpecific(attributes)
val attrs = attributes.to(Attributes)

keysSet.isEmpty == attrs.isEmpty
}
Expand All @@ -47,15 +47,15 @@ class AttributesProps extends ScalaCheckSuite {
property("Attributes#contains is true when the key is present") {
forAll(listOfAttributes) { attributes =>
val keysSet = attributes.map(_.key).toSet
val attrs = Attributes.fromSpecific(attributes)
val attrs = attributes.to(Attributes)

keysSet.forall(attrs.contains)
}
}

property("Attributes#foreach iterates over all attributes") {
forAll(listOfAttributes) { attributes =>
val attrs = Attributes.fromSpecific(attributes)
val attrs = attributes.to(Attributes)

var count = 0
attrs.foreach(_ => count += 1)
Expand All @@ -66,7 +66,7 @@ class AttributesProps extends ScalaCheckSuite {

property("Attributes#toList returns a list of all attributes") {
forAll(listOfAttributes) { attributes =>
val attrs = Attributes.fromSpecific(attributes)
val attrs = attributes.to(Attributes)
val list = attrs.toList

list.size == attrs.size && list.forall(a => attrs.contains(a.key))
Expand All @@ -75,7 +75,7 @@ class AttributesProps extends ScalaCheckSuite {

property("Attributes#foldLeft folds over all attributes") {
forAll(listOfAttributes) { attributes =>
val attrs = Attributes.fromSpecific(attributes)
val attrs = attributes.to(Attributes)
val list = attrs.toList

val folded = attrs.foldLeft[Int](0) { (acc, _) => acc + 1 }
Expand All @@ -88,15 +88,15 @@ class AttributesProps extends ScalaCheckSuite {
"Attributes#forall returns true when all attributes match the predicate"
) {
forAll(listOfAttributes) { attributes =>
val attrs = Attributes.fromSpecific(attributes)
val attrs = attributes.to(Attributes)

attrs.forall(_ => true)
}
}

property("Attributes#toMap returns a map of all attributes") {
forAll(listOfAttributes) { attributes =>
val attrs = Attributes.fromSpecific(attributes)
val attrs = attributes.to(Attributes)
val map = attrs.toMap

map.size == attrs.size && map.forall { case (k, v) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ trait Gens {
val attributes: Gen[Attributes] =
for {
attributes <- Gen.listOf(attribute)
} yield Attributes.fromSpecific(attributes)
} yield attributes.to(Attributes)

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ object Measurement {
* the attributes to associate with the value
*/
def apply[A](value: A, attributes: Attribute[_]*): Measurement[A] =
Impl(value, Attributes.fromSpecific(attributes))
Impl(value, attributes.to(Attributes))

/** Creates a [[Measurement]] with the given `value` and `attributes`.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ trait ObservableMeasurement[F[_], A] {
* the set of attributes to associate with the value
*/
final def record(value: A, attributes: Attribute[_]*): F[Unit] =
record(value, Attributes.fromSpecific(attributes))
record(value, attributes.to(Attributes))

/** Records a value with a set of attributes.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private[oteljava] object Conversions {
Attribute(attribute.getKey, value.asScala.toList.map(_.doubleValue()))
}

Attributes.fromSpecific(converted)
converted.to(Attributes)
}

def asyncFromCompletableResultCode[F[_]](
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class OtlpHttpSpanExporterSuite
}
}

Attributes.fromSpecific(adapted)
adapted.to(Attributes)
}

private def toJaegerTag(a: Attribute[_]): JaegerTag = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private final class SdkSpanBackend[F[_]: Monad: Clock: Console] private (
attributes: immutable.Iterable[Attribute[_]]
): F[Unit] =
addTimedEvent(
EventData(name, timestamp, Attributes.fromSpecific(attributes))
EventData(name, timestamp, attributes.to(Attributes))
)

def recordException(
Expand All @@ -116,7 +116,7 @@ private final class SdkSpanBackend[F[_]: Monad: Clock: Console] private (
EventData.fromException(
now,
exception,
Attributes.fromSpecific(attributes),
attributes.to(Attributes),
escaped = false
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ private final case class SdkSpanBuilder[F[_]: Temporal: Console](
spanContext: SpanContext,
attributes: immutable.Iterable[Attribute[_]]
): SpanBuilder[F] =
copy(links =
links :+ LinkData(spanContext, Attributes.fromSpecific(attributes))
)
copy(links = links :+ LinkData(spanContext, attributes.to(Attributes)))

def root: SpanBuilder[F] =
copy(parent = Parent.Root)
Expand Down Expand Up @@ -141,7 +139,7 @@ private final case class SdkSpanBuilder[F[_]: Temporal: Console](
private def start: F[Span.Backend[F]] = {
val idGenerator = tracerSharedState.idGenerator
val spanKind = kind.getOrElse(SpanKind.Internal)
val attrs = Attributes.fromSpecific(attributes)
val attrs = attributes.to(Attributes)

def genTraceId(parent: Option[SpanContext]): F[ByteVector] =
parent
Expand Down