From 3be3ba0207925c845cb5005fe0c03ea5f91e58a1 Mon Sep 17 00:00:00 2001 From: Michael Nedokushev Date: Mon, 25 Nov 2024 22:36:22 +0000 Subject: [PATCH] Fix Attributes.apply methods resolution (#913) * rename Attributes.apply for sequence to Attributes.fromList * Add test * scalafix --- .../opentelemetry/common/Attributes.scala | 2 +- .../metrics/internal/package.scala | 4 ++-- .../opentelemetry/common/AttributesSpec.scala | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 opentelemetry/src/test/scala/zio/telemetry/opentelemetry/common/AttributesSpec.scala diff --git a/opentelemetry/src/main/scala/zio/telemetry/opentelemetry/common/Attributes.scala b/opentelemetry/src/main/scala/zio/telemetry/opentelemetry/common/Attributes.scala index e508c362..7e676fab 100644 --- a/opentelemetry/src/main/scala/zio/telemetry/opentelemetry/common/Attributes.scala +++ b/opentelemetry/src/main/scala/zio/telemetry/opentelemetry/common/Attributes.scala @@ -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)) diff --git a/opentelemetry/src/main/scala/zio/telemetry/opentelemetry/metrics/internal/package.scala b/opentelemetry/src/main/scala/zio/telemetry/opentelemetry/metrics/internal/package.scala index 32902328..19d1cffe 100644 --- a/opentelemetry/src/main/scala/zio/telemetry/opentelemetry/metrics/internal/package.scala +++ b/opentelemetry/src/main/scala/zio/telemetry/opentelemetry/metrics/internal/package.scala @@ -8,7 +8,7 @@ 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 @@ -16,7 +16,7 @@ package object internal { 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) diff --git a/opentelemetry/src/test/scala/zio/telemetry/opentelemetry/common/AttributesSpec.scala b/opentelemetry/src/test/scala/zio/telemetry/opentelemetry/common/AttributesSpec.scala new file mode 100644 index 00000000..f4592650 --- /dev/null +++ b/opentelemetry/src/test/scala/zio/telemetry/opentelemetry/common/AttributesSpec.scala @@ -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); + } + ) + ) + +}