Skip to content

Commit

Permalink
Fix Attributes.apply methods resolution (#913)
Browse files Browse the repository at this point in the history
* rename Attributes.apply for sequence to Attributes.fromList

* Add test

* scalafix
  • Loading branch information
grouzen authored Nov 25, 2024
1 parent 9362c50 commit 3be3ba0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ object Attributes {
def empty: api.common.Attributes =
api.common.Attributes.empty()

def apply[T](attributes: Attribute[T]*): api.common.Attributes = {
def fromList[T](attributes: List[Attribute[T]]): api.common.Attributes = {
val builder = api.common.Attributes.builder()

attributes.foreach(attr => builder.put(attr.key, attr.value))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import zio.telemetry.opentelemetry.common.{Attribute, Attributes}
package object internal {

private[metrics] def attributes(tags: Set[MetricLabel]): api.common.Attributes =
Attributes(tags.map(t => Attribute.string(t.key, t.value)).toSeq: _*)
Attributes.fromList(tags.map(t => Attribute.string(t.key, t.value)).toList)

private[metrics] def logAnnotatedAttributes(attributes: api.common.Attributes, logAnnotated: Boolean)(implicit
trace: Trace
): UIO[api.common.Attributes] =
if (logAnnotated)
for {
annotations <- ZIO.logAnnotations
annotated = Attributes(annotations.map { case (k, v) => Attribute.string(k, v) }.toSeq: _*)
annotated = Attributes.fromList(annotations.map { case (k, v) => Attribute.string(k, v) }.toList)
builder = api.common.Attributes.builder()
_ = builder.putAll(annotated)
_ = builder.putAll(attributes)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package zio.telemetry.opentelemetry.common

import zio.test.{ZIOSpecDefault, _}

object AttributesSpec extends ZIOSpecDefault {

override def spec: Spec[Any, Throwable] =
suite("zio opentelemetry")(
suite("Attributes")(
// Addresses the bug: https://github.com/zio/zio-telemetry/issues/911
test("Check methods resolution in compile time") {
val _ = Attributes(Attribute.string("foo", "bar"), Attribute.string("dog", "fox"))

assertTrue(true);
}
)
)

}

0 comments on commit 3be3ba0

Please sign in to comment.