Skip to content

Commit

Permalink
Replace otel4s-testkit with otel4s-oteljava-testkit
Browse files Browse the repository at this point in the history
  • Loading branch information
iRevive committed Feb 4, 2024
1 parent ddb5829 commit 03546bb
Show file tree
Hide file tree
Showing 25 changed files with 1,027 additions and 826 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ jobs:

- name: Make target directories
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
run: mkdir -p testkit/metrics/jvm/target oteljava/metrics/target testkit/common/jvm/target core/trace/.js/target semconv/.jvm/target core/common/.jvm/target unidocs/target core/metrics/.native/target core/all/.native/target core/metrics/.jvm/target core/all/.js/target core/metrics/.js/target core/all/.jvm/target core/trace/.native/target semconv/.js/target oteljava/common/target scalafix/rules/target core/trace/.jvm/target core/common/.native/target core/common/.js/target oteljava/trace/target semconv/.native/target testkit/all/jvm/target oteljava/all/target project/target
run: mkdir -p oteljava/metrics/target core/trace/.js/target semconv/.jvm/target core/metrics-testkit/.jvm/target core/common/.jvm/target oteljava/common-testkit/target unidocs/target core/metrics/.native/target core/all/.native/target core/metrics-testkit/.native/target core/metrics/.jvm/target core/all/.js/target core/metrics/.js/target core/all/.jvm/target core/trace/.native/target oteljava/metrics-testkit/target core/metrics-testkit/.js/target semconv/.js/target oteljava/common/target scalafix/rules/target core/trace/.jvm/target core/common/.native/target core/common/.js/target oteljava/trace/target oteljava/testkit/target semconv/.native/target oteljava/all/target project/target

- name: Compress target directories
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
run: tar cf targets.tar testkit/metrics/jvm/target oteljava/metrics/target testkit/common/jvm/target core/trace/.js/target semconv/.jvm/target core/common/.jvm/target unidocs/target core/metrics/.native/target core/all/.native/target core/metrics/.jvm/target core/all/.js/target core/metrics/.js/target core/all/.jvm/target core/trace/.native/target semconv/.js/target oteljava/common/target scalafix/rules/target core/trace/.jvm/target core/common/.native/target core/common/.js/target oteljava/trace/target semconv/.native/target testkit/all/jvm/target oteljava/all/target project/target
run: tar cf targets.tar oteljava/metrics/target core/trace/.js/target semconv/.jvm/target core/metrics-testkit/.jvm/target core/common/.jvm/target oteljava/common-testkit/target unidocs/target core/metrics/.native/target core/all/.native/target core/metrics-testkit/.native/target core/metrics/.jvm/target core/all/.js/target core/metrics/.js/target core/all/.jvm/target core/trace/.native/target oteljava/metrics-testkit/target core/metrics-testkit/.js/target semconv/.js/target oteljava/common/target scalafix/rules/target core/trace/.jvm/target core/common/.native/target core/common/.js/target oteljava/trace/target oteljava/testkit/target semconv/.native/target oteljava/all/target project/target

- name: Upload target directories
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
Expand Down
107 changes: 61 additions & 46 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ lazy val root = tlCrossRootProject
.aggregate(
`core-common`,
`core-metrics`,
`core-metrics-testkit`,
`core-trace`,
core,
`sdk-common`,
Expand All @@ -86,12 +87,12 @@ lazy val root = tlCrossRootProject
`sdk-exporter-proto`,
`sdk-exporter-trace`,
`sdk-exporter`,
`testkit-common`,
`testkit-metrics`,
testkit,
`oteljava-common`,
`oteljava-common-testkit`,
`oteljava-metrics`,
`oteljava-metrics-testkit`,
`oteljava-trace`,
`oteljava-testkit`,
oteljava,
semconv,
benchmarks,
Expand Down Expand Up @@ -138,6 +139,17 @@ lazy val `core-metrics` = crossProject(JVMPlatform, JSPlatform, NativePlatform)
)
.settings(scalafixSettings)

lazy val `core-metrics-testkit` =
crossProject(JVMPlatform, JSPlatform, NativePlatform)
.crossType(CrossType.Pure)
.in(file("core/metrics-testkit"))
.dependsOn(`core-trace`)
.settings(
name := "otel4s-core-metrics-testkit",
startYear := Some(2024)
)
.settings(scalafixSettings)

lazy val `core-trace` = crossProject(JVMPlatform, JSPlatform, NativePlatform)
.crossType(CrossType.Pure)
.in(file("core/trace"))
Expand Down Expand Up @@ -311,47 +323,13 @@ lazy val `sdk-exporter` = crossProject(JVMPlatform, JSPlatform, NativePlatform)
.settings(scalafixSettings)

//
// Testkit
// OpenTelemetry Java
//

lazy val `testkit-common` = crossProject(JVMPlatform)
.crossType(CrossType.Full)
.in(file("testkit/common"))
.dependsOn(`core-common`)
.settings(
name := "otel4s-testkit-common"
)
.settings(scalafixSettings)

lazy val `testkit-metrics` = crossProject(JVMPlatform)
.crossType(CrossType.Full)
.in(file("testkit/metrics"))
.dependsOn(`testkit-common`, `core-metrics`)
.settings(
name := "otel4s-testkit-metrics"
)
.jvmSettings(
libraryDependencies ++= Seq(
"io.opentelemetry" % "opentelemetry-api" % OpenTelemetryVersion,
"io.opentelemetry" % "opentelemetry-sdk" % OpenTelemetryVersion,
"io.opentelemetry" % "opentelemetry-sdk-testing" % OpenTelemetryVersion
)
)
.settings(scalafixSettings)

lazy val testkit = crossProject(JVMPlatform)
.crossType(CrossType.Full)
.in(file("testkit/all"))
.dependsOn(`testkit-common`, `testkit-metrics`)
.settings(
name := "otel4s-testkit"
)
.settings(scalafixSettings)

lazy val `oteljava-common` = project
.in(file("oteljava/common"))
.enablePlugins(BuildInfoPlugin)
.dependsOn(`core-common`.jvm, `testkit-common`.jvm % Test)
.dependsOn(`core-common`.jvm)
.settings(munitDependencies)
.settings(
name := "otel4s-oteljava-common",
Expand All @@ -370,12 +348,24 @@ lazy val `oteljava-common` = project
)
.settings(scalafixSettings)

lazy val `oteljava-common-testkit` = project
.in(file("oteljava/common-testkit"))
.dependsOn(`oteljava-common`)
.settings(
name := "otel4s-oteljava-common-testkit",
libraryDependencies ++= Seq(
"io.opentelemetry" % "opentelemetry-sdk-testing" % OpenTelemetryVersion
),
startYear := Some(2024)
)
.settings(scalafixSettings)

lazy val `oteljava-metrics` = project
.in(file("oteljava/metrics"))
.dependsOn(
`oteljava-common`,
`core-metrics`.jvm,
`testkit-metrics`.jvm % Test
`core-metrics-testkit`.jvm % Test
)
.settings(munitDependencies)
.settings(
Expand All @@ -386,6 +376,15 @@ lazy val `oteljava-metrics` = project
)
.settings(scalafixSettings)

lazy val `oteljava-metrics-testkit` = project
.in(file("oteljava/metrics-testkit"))
.dependsOn(`oteljava-metrics`, `oteljava-common-testkit`)
.settings(
name := "otel4s-oteljava-metrics-testkit",
startYear := Some(2024)
)
.settings(scalafixSettings)

lazy val `oteljava-trace` = project
.in(file("oteljava/trace"))
.dependsOn(`oteljava-common`, `core-trace`.jvm)
Expand All @@ -401,9 +400,21 @@ lazy val `oteljava-trace` = project
)
.settings(scalafixSettings)

lazy val `oteljava-testkit` = project
.in(file("oteljava/testkit"))
.dependsOn(`oteljava-metrics-testkit`)
.settings(
name := "otel4s-oteljava-testkit"
)

lazy val oteljava = project
.in(file("oteljava/all"))
.dependsOn(core.jvm, `oteljava-metrics`, `oteljava-trace`)
.dependsOn(
core.jvm,
`oteljava-metrics`,
`oteljava-trace`,
`oteljava-metrics-testkit` % Test
)
.settings(
name := "otel4s-oteljava",
libraryDependencies ++= Seq(
Expand Down Expand Up @@ -460,9 +471,12 @@ lazy val benchmarks = project
.enablePlugins(NoPublishPlugin)
.enablePlugins(JmhPlugin)
.in(file("benchmarks"))
.dependsOn(core.jvm, sdk.jvm, oteljava, testkit.jvm)
.dependsOn(core.jvm, sdk.jvm, oteljava)
.settings(
name := "otel4s-benchmarks"
name := "otel4s-benchmarks",
libraryDependencies ++= Seq(
"io.opentelemetry" % "opentelemetry-sdk-testing" % OpenTelemetryVersion
)
)
.settings(scalafixSettings)

Expand Down Expand Up @@ -527,6 +541,7 @@ lazy val unidocs = project
ScalaUnidoc / unidoc / unidocProjectFilter := inProjects(
`core-common`.jvm,
`core-metrics`.jvm,
`core-metrics-testkit`.jvm,
`core-trace`.jvm,
core.jvm,
`sdk-common`.jvm,
Expand All @@ -535,12 +550,12 @@ lazy val unidocs = project
`sdk-exporter-common`.jvm,
`sdk-exporter-trace`.jvm,
`sdk-exporter`.jvm,
`testkit-common`.jvm,
`testkit-metrics`.jvm,
testkit.jvm,
`oteljava-common`,
`oteljava-common-testkit`,
`oteljava-metrics`,
`oteljava-metrics-testkit`,
`oteljava-trace`,
`oteljava-testkit`,
oteljava,
semconv.jvm
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* Copyright 2022 Typelevel
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.typelevel.otel4s
package oteljava
package metrics

import cats.effect.IO
import cats.effect.Resource
import io.opentelemetry.sdk.metrics._
import munit.CatsEffectSuite
import org.typelevel.otel4s.oteljava.testkit.InstrumentationScope
import org.typelevel.otel4s.oteljava.testkit.TelemetryResource
import org.typelevel.otel4s.oteljava.testkit.metrics.TestkitMetrics

import scala.jdk.CollectionConverters._

class CounterSuite extends CatsEffectSuite {

test("Counter record a proper data") {
makeSdk.use { sdk =>
for {
meter <- sdk.meterProvider
.meter("java.otel.suite")
.withVersion("1.0")
.withSchemaUrl("https://localhost:8080")
.get

counter <- meter
.counter[Long]("counter")
.withUnit("unit")
.withDescription("description")
.create

_ <- counter.add(1L, Attribute("string-attribute", "value"))

metrics <- sdk.metrics
} yield {
val resourceAttributes = Attributes(
Attribute("service.name", "unknown_service:java"),
Attribute("telemetry.sdk.language", "java"),
Attribute("telemetry.sdk.name", "opentelemetry"),
Attribute("telemetry.sdk.version", BuildInfo.openTelemetrySdkVersion)
)

val scope = InstrumentationScope(
name = "java.otel.suite",
version = Some("1.0"),
schemaUrl = Some("https://localhost:8080"),
attributes = Attributes.empty
)

assertEquals(metrics.map(_.name), List("counter"))
assertEquals(metrics.map(_.description), List(Some("description")))
assertEquals(metrics.map(_.unit), List(Some("unit")))
assertEquals(
metrics.map(_.resource),
List(TelemetryResource(resourceAttributes, None))
)
assertEquals(metrics.map(_.scope), List(scope))
assertEquals[List[Any], List[Any]](
metrics.map(_.data.points.map(_.value)),
List(List(1L))
)
}
}
}

private def makeSdk: Resource[IO, TestkitMetrics[IO]] = {
def customize(builder: SdkMeterProviderBuilder): SdkMeterProviderBuilder =
builder.registerView(
InstrumentSelector.builder().setType(InstrumentType.HISTOGRAM).build(),
View
.builder()
.setAggregation(
Aggregation.explicitBucketHistogram(
HistogramBuckets.map(Double.box).asJava
)
)
.build()
)

TestkitMetrics.inMemory[IO](customize)
}

private val HistogramBuckets: List[Double] =
List(0.01, 1, 100)

}
Loading

0 comments on commit 03546bb

Please sign in to comment.