Skip to content

Commit

Permalink
Merge pull request #410 from armanbilge/topic/java-common-no-sdk
Browse files Browse the repository at this point in the history
Remove SDK dependency from `otel4s-java-common`
  • Loading branch information
iRevive authored Dec 25, 2023
2 parents db4381d + f5d6cff commit 4f41e3e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 32 deletions.
8 changes: 5 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import com.typesafe.tools.mima.core._

ThisBuild / tlBaseVersion := "0.4"
ThisBuild / tlBaseVersion := "0.5"

ThisBuild / organization := "org.typelevel"
ThisBuild / organizationName := "Typelevel"
Expand Down Expand Up @@ -246,10 +246,11 @@ lazy val `java-common` = project
libraryDependencies ++= Seq(
"org.typelevel" %%% "cats-effect" % CatsEffectVersion,
"org.typelevel" %%% "cats-mtl" % CatsMtlVersion,
"io.opentelemetry" % "opentelemetry-sdk" % OpenTelemetryVersion,
"io.opentelemetry" % "opentelemetry-api" % OpenTelemetryVersion,
"org.typelevel" %%% "discipline-munit" % MUnitDisciplineVersion % Test,
"org.typelevel" %%% "cats-mtl-laws" % CatsMtlVersion % Test,
"org.typelevel" %%% "cats-effect-testkit" % CatsEffectVersion % Test
"org.typelevel" %%% "cats-effect-testkit" % CatsEffectVersion % Test,
"io.opentelemetry" % "opentelemetry-sdk-testing" % OpenTelemetryVersion % Test
),
buildInfoPackage := "org.typelevel.otel4s.java",
buildInfoOptions += sbtbuildinfo.BuildInfoOption.PackagePrivate,
Expand Down Expand Up @@ -312,6 +313,7 @@ lazy val java = project
.settings(
name := "otel4s-java",
libraryDependencies ++= Seq(
"io.opentelemetry" % "opentelemetry-sdk" % OpenTelemetryVersion,
"io.opentelemetry" % "opentelemetry-sdk-testing" % OpenTelemetryVersion % Test
)
)
Expand Down
28 changes: 27 additions & 1 deletion java/all/src/main/scala/org/typelevel/otel4s/java/OtelJava.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import cats.syntax.all._
import io.opentelemetry.api.{OpenTelemetry => JOpenTelemetry}
import io.opentelemetry.api.GlobalOpenTelemetry
import io.opentelemetry.sdk.{OpenTelemetrySdk => JOpenTelemetrySdk}
import io.opentelemetry.sdk.common.CompletableResultCode
import org.typelevel.otel4s.Otel4s
import org.typelevel.otel4s.context.propagation.ContextPropagators
import org.typelevel.otel4s.java.Conversions.asyncFromCompletableResultCode
import org.typelevel.otel4s.java.context.Context
import org.typelevel.otel4s.java.context.LocalContext
import org.typelevel.otel4s.java.context.propagation.PropagatorConverters._
Expand Down Expand Up @@ -102,4 +102,30 @@ object OtelJava {
*/
def global[F[_]: LiftIO: Async]: F[OtelJava[F]] =
Sync[F].delay(GlobalOpenTelemetry.get).flatMap(forAsync[F])

private[this] def asyncFromCompletableResultCode[F[_]](
codeF: F[CompletableResultCode],
msg: => Option[String] = None
)(implicit F: Async[F]): F[Unit] =
F.flatMap(codeF)(code =>
F.async[Unit](cb =>
F.delay {
code.whenComplete(() =>
if (code.isSuccess())
cb(Either.unit)
else
cb(
Left(
new RuntimeException(
msg.getOrElse(
"OpenTelemetry SDK async operation failed"
)
)
)
)
)
None
}
)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@
package org.typelevel.otel4s
package java

import cats.effect.kernel.Async
import cats.syntax.either._
import io.opentelemetry.api.common.{Attributes => JAttributes}
import io.opentelemetry.sdk.common.CompletableResultCode

private[java] object Conversions {

Expand Down Expand Up @@ -51,29 +48,4 @@ private[java] object Conversions {
builder.build()
}

def asyncFromCompletableResultCode[F[_]](
codeF: F[CompletableResultCode],
msg: => Option[String] = None
)(implicit F: Async[F]): F[Unit] =
F.flatMap(codeF)(code =>
F.async[Unit](cb =>
F.delay {
code.whenComplete(() =>
if (code.isSuccess())
cb(Either.unit)
else
cb(
Left(
new RuntimeException(
msg.getOrElse(
"OpenTelemetry SDK async operation failed"
)
)
)
)
)
None
}
)
)
}

0 comments on commit 4f41e3e

Please sign in to comment.