Skip to content

Commit

Permalink
docs: Add an example of manual configuretion
Browse files Browse the repository at this point in the history
  • Loading branch information
NomadBlacky committed Sep 25, 2023
1 parent be5b385 commit 044ab17
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 16 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand All @@ -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",
),
)
6 changes: 6 additions & 0 deletions examples/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
services:
jeager:
image: jaegertracing/all-in-one:latest
ports:
- "4317:4317"
- "16686:16686"
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
@@ -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)
}
}
}

0 comments on commit 044ab17

Please sign in to comment.