diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 61602b2..4310887 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -55,7 +55,7 @@ jobs: run: sbt '++ ${{ matrix.scala }}' test - name: Compress target directories - run: tar cf targets.tar target scalatest-otel-reporter/target project/target + run: tar cf targets.tar target scalatest-otel-reporter/target examples/manual-configuration/target project/target - name: Upload target directories uses: actions/upload-artifact@v3 diff --git a/build.sbt b/build.sbt index 6afd578..78c7c4b 100644 --- a/build.sbt +++ b/build.sbt @@ -35,7 +35,7 @@ ThisBuild / githubWorkflowPublish := Seq( ) lazy val root = (project in file(".")) - .aggregate(`scalatest-otel-reporter`) + .aggregate(`scalatest-otel-reporter`, `example-manual-configuration`) .settings( publish / skip := true, ) @@ -47,5 +47,20 @@ lazy val `scalatest-otel-reporter` = (project in file("scalatest-otel-reporter") otelSdk % Provided, ), ) + +lazy val `example-manual-configuration` = (project in file("examples/manual-configuration")) + .dependsOn(`scalatest-otel-reporter`) + .settings( + publish / skip := true, + libraryDependencies ++= Seq( + scalatest % Test, + otelSdk % Test, + otelExporterOTLP % Test, + otelSemConv % Test, + ), + Test / testOptions += Tests.Argument( + TestFrameworks.ScalaTest, + "-C", + "dev.nomadblacky.scalatest_otel_reporter.examples.JaegerTestReporter", ), ) diff --git a/examples/docker-compose.yml b/examples/docker-compose.yml new file mode 100644 index 0000000..414e56f --- /dev/null +++ b/examples/docker-compose.yml @@ -0,0 +1,6 @@ +services: + jeager: + image: jaegertracing/all-in-one:latest + ports: + - "4317:4317" + - "16686:16686" diff --git a/examples/manual-configuration/src/test/scala/dev/nomadblacky/scalatest_otel_reporter/examples/JaegerTestReporter.scala b/examples/manual-configuration/src/test/scala/dev/nomadblacky/scalatest_otel_reporter/examples/JaegerTestReporter.scala new file mode 100644 index 0000000..55f90e2 --- /dev/null +++ b/examples/manual-configuration/src/test/scala/dev/nomadblacky/scalatest_otel_reporter/examples/JaegerTestReporter.scala @@ -0,0 +1,32 @@ +package dev.nomadblacky.scalatest_otel_reporter.examples + +import dev.nomadblacky.scalatest_otel_reporter.BaseOpenTelemetryTestReporter +import io.opentelemetry.api.OpenTelemetry +import io.opentelemetry.api.common.Attributes +import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter +import io.opentelemetry.sdk.OpenTelemetrySdk +import io.opentelemetry.sdk.resources.Resource +import io.opentelemetry.sdk.trace.SdkTracerProvider +import io.opentelemetry.sdk.trace.`export`.BatchSpanProcessor +import io.opentelemetry.semconv.ResourceAttributes + +import java.util.concurrent.TimeUnit + +class JaegerTestReporter extends BaseOpenTelemetryTestReporter { + def otel: OpenTelemetry = { + // Export traces to Jaeger over OTLP + val jaegerOtlpExporter = + OtlpGrpcSpanExporter.builder.setEndpoint("http://localhost:4317").setTimeout(30, TimeUnit.SECONDS).build + + val serviceNameResource = + Resource.create(Attributes.of(ResourceAttributes.SERVICE_NAME, "scalatest-otel-demo")) + + // Set to process the spans by the Jaeger Exporter + val tracerProvider = SdkTracerProvider.builder + .addSpanProcessor(BatchSpanProcessor.builder(jaegerOtlpExporter).build) + .setResource(Resource.getDefault.merge(serviceNameResource)) + .build + + OpenTelemetrySdk.builder.setTracerProvider(tracerProvider).build + } +} diff --git a/examples/manual-configuration/src/test/scala/dev/nomadblacky/scalatest_otel_reporter/examples/ManualConfigurationExample.scala b/examples/manual-configuration/src/test/scala/dev/nomadblacky/scalatest_otel_reporter/examples/ManualConfigurationExample.scala new file mode 100644 index 0000000..5ba2acd --- /dev/null +++ b/examples/manual-configuration/src/test/scala/dev/nomadblacky/scalatest_otel_reporter/examples/ManualConfigurationExample.scala @@ -0,0 +1,13 @@ +package dev.nomadblacky.scalatest_otel_reporter.examples + +import org.scalatest.funspec.AnyFunSpecLike + +class ManualConfigurationExample extends AnyFunSpecLike { + + describe("Describe") { + it("It") { + Thread.sleep(1000) + assert(1 == 1) + } + } +}