Skip to content

Commit

Permalink
Merge pull request #748 from iRevive/sdk-common/detector-tests
Browse files Browse the repository at this point in the history
sdk-common: use `semconv-experimental` in tests
  • Loading branch information
iRevive authored Sep 5, 2024
2 parents ac92be5 + 6688e40 commit e9c26a8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 25 deletions.
6 changes: 5 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,11 @@ lazy val `sdk-common` = crossProject(JVMPlatform, JSPlatform, NativePlatform)
.crossType(CrossType.Full)
.enablePlugins(BuildInfoPlugin)
.in(file("sdk/common"))
.dependsOn(`core-common` % "compile->compile;test->test", `semconv-stable`)
.dependsOn(
`core-common` % "compile->compile;test->test",
`semconv-stable`,
`semconv-experimental` % Test
)
.settings(
name := "otel4s-sdk-common",
startYear := Some(2023),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,73 +19,78 @@ package org.typelevel.otel4s.sdk.resource
import cats.effect.IO
import munit.CatsEffectSuite
import munit.internal.PlatformCompat
import org.typelevel.otel4s.AttributeKey
import org.typelevel.otel4s.semconv.SchemaUrls
import org.typelevel.otel4s.semconv.experimental.attributes.HostExperimentalAttributes._
import org.typelevel.otel4s.semconv.experimental.attributes.OsExperimentalAttributes._
import org.typelevel.otel4s.semconv.experimental.attributes.ProcessExperimentalAttributes._

class TelemetryResourceDetectorSuite extends CatsEffectSuite {

test("HostDetector - detect name and arch") {
val keys = Set("host.name", "host.arch")
val keys: Set[AttributeKey[_]] = Set(HostName, HostArch)

for {
resource <- HostDetector[IO].detect
} yield {
assertEquals(resource.map(_.attributes.map(_.key.name).toSet), Some(keys))
assertEquals(resource.map(_.attributes.map(_.key).toSet), Some(keys))
assertEquals(resource.flatMap(_.schemaUrl), Some(SchemaUrls.Current))
}
}

test("OSDetector - detect OS type and description") {
val keys = Set("os.type", "os.description")
val keys: Set[AttributeKey[_]] = Set(OsType, OsDescription)

for {
resource <- OSDetector[IO].detect
} yield {
assertEquals(resource.map(_.attributes.map(_.key.name).toSet), Some(keys))
assertEquals(resource.map(_.attributes.map(_.key).toSet), Some(keys))
assertEquals(resource.flatMap(_.schemaUrl), Some(SchemaUrls.Current))
}
}

test("ProcessDetector - detect pid, exe path, exe name") {
val keys =
val keys: Set[AttributeKey[_]] =
if (PlatformCompat.isJS)
Set(
"process.executable.path",
"process.pid",
"process.executable.name",
"process.owner",
"process.command_args"
ProcessExecutablePath,
ProcessExecutableName,
ProcessPid,
ProcessOwner,
ProcessCommandArgs
)
else if (PlatformCompat.isNative)
Set("process.pid")
Set(ProcessPid)
else
Set(
"process.executable.path",
"process.pid",
"process.command_line"
ProcessExecutablePath,
ProcessPid,
ProcessCommandLine
)

for {
resource <- ProcessDetector[IO].detect
} yield {
assertEquals(resource.map(_.attributes.map(_.key.name).toSet), Some(keys))
assertEquals(resource.map(_.attributes.map(_.key).toSet), Some(keys))
assertEquals(resource.flatMap(_.schemaUrl), Some(SchemaUrls.Current))
}
}

test("ProcessRuntimeDetector - detect name, version, and description") {
val keys = {
val name = "process.runtime.name"
val version = "process.runtime.version"
val description = "process.runtime.description"

if (PlatformCompat.isNative) Set(name, description)
else Set(name, version, description)
}
val keys: Set[AttributeKey[_]] =
if (PlatformCompat.isNative)
Set(ProcessRuntimeName, ProcessRuntimeDescription)
else
Set(
ProcessRuntimeName,
ProcessRuntimeVersion,
ProcessRuntimeDescription
)

for {
resource <- ProcessRuntimeDetector[IO].detect
} yield {
assertEquals(resource.map(_.attributes.map(_.key.name).toSet), Some(keys))
assertEquals(resource.map(_.attributes.map(_.key).toSet), Some(keys))
assertEquals(resource.flatMap(_.schemaUrl), Some(SchemaUrls.Current))
}
}
Expand Down

0 comments on commit e9c26a8

Please sign in to comment.