-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
65a0c28
commit be5b385
Showing
6 changed files
with
123 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import sbt._ | ||
|
||
object Dependencies { | ||
private val v = new { | ||
val otel = "1.30.0" | ||
} | ||
|
||
// scalatest | ||
val scalatest = "org.scalatest" %% "scalatest" % "3.2.16" | ||
|
||
// OpenTelemetry | ||
val otelSdk = "io.opentelemetry" % "opentelemetry-sdk" % v.otel | ||
val otelExporterOTLP = "io.opentelemetry" % "opentelemetry-exporter-otlp" % v.otel | ||
val otelAutoConfigure = "io.opentelemetry" % "opentelemetry-sdk-extension-autoconfigure" % v.otel | ||
val otelSemConv = "io.opentelemetry.semconv" % "opentelemetry-semconv" % "1.21.0-alpha" | ||
|
||
// Testing utilities | ||
val wiremock = "org.wiremock" % "wiremock" % "3.1.0" | ||
val testcontainers = "org.testcontainers" % "testcontainers" % "1.19.0" | ||
} |
This file was deleted.
Oops, something went wrong.
75 changes: 75 additions & 0 deletions
75
...er/src/main/scala/dev/nomadblacky/scalatest_otel_reporter/OpenTelemetryTestReporter.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package dev.nomadblacky.scalatest_otel_reporter | ||
|
||
import io.opentelemetry.api.trace.Span | ||
import io.opentelemetry.api.{GlobalOpenTelemetry, OpenTelemetry} | ||
import io.opentelemetry.context.Context | ||
import org.scalatest.Reporter | ||
import org.scalatest.events._ | ||
|
||
import java.util.concurrent.ConcurrentHashMap | ||
|
||
trait BaseOpenTelemetryTestReporter extends Reporter { | ||
def otel: OpenTelemetry | ||
|
||
private val tracer = otel.getTracerProvider.get("scalatest") | ||
|
||
private var testRunSpan: Span = _ | ||
private val suitesMap = new ConcurrentHashMap[String, Span]() | ||
private val testsMap = new ConcurrentHashMap[String, Span]() | ||
|
||
def apply(event: Event): Unit = | ||
event match { | ||
case starting: TestStarting => | ||
val suiteSpan = Option(suitesMap.get(starting.suiteId)) | ||
val parentContext = suiteSpan.fold(Context.current())(Context.current().`with`) | ||
val testSpan = tracer.spanBuilder(starting.testName).setParent(parentContext).startSpan() | ||
testsMap.put(starting.testName, testSpan) | ||
case succeeded: TestSucceeded => | ||
Option(testsMap.remove(succeeded.testName)) | ||
.fold(throw new IllegalStateException(s"Test not found: $succeeded"))(_.end()) | ||
case _: TestFailed => | ||
// TODO | ||
case ignored: TestIgnored => | ||
// TODO | ||
case pending: TestPending => | ||
// TODO | ||
case canceled: TestCanceled => | ||
// TODO | ||
case starting: SuiteStarting => | ||
val suiteSpan = | ||
tracer.spanBuilder(starting.suiteName).setParent(Context.current().`with`(testRunSpan)).startSpan() | ||
suitesMap.put(starting.suiteId, suiteSpan) | ||
case completed: SuiteCompleted => | ||
val span = suitesMap.remove(completed.suiteId) | ||
span.end() | ||
case aborted: SuiteAborted => | ||
// TODO | ||
case starting: RunStarting => | ||
testRunSpan = tracer.spanBuilder("UNIT_TEST").startSpan() | ||
case completed: RunCompleted => | ||
testRunSpan.end() | ||
case stopped: RunStopped => | ||
// TODO | ||
case aborted: RunAborted => | ||
// TODO | ||
case opened: ScopeOpened => | ||
// TODO | ||
case closed: ScopeClosed => | ||
// TODO | ||
case pending: ScopePending => | ||
// TODO | ||
case _: DiscoveryStarting => () | ||
case _: DiscoveryCompleted => () | ||
case _: RecordableEvent => () | ||
case _: ExceptionalEvent => () | ||
case _: NotificationEvent => () | ||
case _: InfoProvided => () | ||
case _: AlertProvided => () | ||
case _: NoteProvided => () | ||
case _: MarkupProvided => () | ||
} | ||
} | ||
|
||
class OpenTelemetryTestReporter extends BaseOpenTelemetryTestReporter { | ||
def otel: OpenTelemetry = GlobalOpenTelemetry.get() | ||
} |
This file was deleted.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
...otel-reporter/src/test/scala/dev/nomadblacky/scalatest_otel_reporter/SimpleTestSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package dev.nomadblacky.scalatest_otel_reporter | ||
|
||
import org.scalatest.Args | ||
import org.scalatest.funspec.AnyFunSpecLike | ||
import org.scalatest.funsuite.AnyFunSuiteLike | ||
|
||
class SimpleTestSpec extends AnyFunSuiteLike { | ||
|
||
class SimpleTests extends AnyFunSpecLike { | ||
describe("Describe") { | ||
it("It") { | ||
Thread.sleep(1000) | ||
assert(1 == 1) | ||
} | ||
} | ||
} | ||
|
||
test("SimpleTest") { | ||
val simpleTests = new SimpleTests | ||
simpleTests.run(None, Args(new OpenTelemetryTestReporter)) | ||
} | ||
} |