-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TextMapPropagator draft #124
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's going to be pretty ugly to wrap the Java propagators, but it's also going to be ugly to recreate our own from an otherwise autoconfigured SDK. This is going to require some thought.
@@ -67,6 +68,7 @@ lazy val `core-common` = crossProject(JVMPlatform, JSPlatform, NativePlatform) | |||
name := "otel4s-core-common", | |||
libraryDependencies ++= Seq( | |||
"org.typelevel" %%% "cats-core" % CatsVersion, | |||
"org.typelevel" %%% "vault" % VaultVersion, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been stable for a long time, but it's not strictly necessary. It turns out to be a very good match for the Otel spec.
import cats.effect.kernel.Unique | ||
import org.typelevel.vault | ||
|
||
sealed trait Context { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is easy enough, but we need an isomorphism with the Java one to wrap their propagators, and that's where it turns to mush.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can maybe do a type parameter and some Aux magic and drop the Vault dependency? (Vault would still be ideal for a pure Scala implementation, but I'm not going there anytime soon...) But then I'm not sure how we'd create and reference keys in the core.
|
||
trait TextMapPropagator[F[_]] extends TextMapInjector[F] with TextMapExtractor | ||
|
||
trait TextMapInjector[F[_]] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the extractor side, we are to return a new immutable Context, so it's pure. No such constraint is given for injection, and the Java one returns Unit.
|
||
trait TextMapGetter[A] { | ||
def keys(carrier: A): List[String] | ||
def get(carrier: A, key: String): Option[A] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zmccoy and I had a workplace accident this week relating to this being case sensitive, but it's not clear that the spec supports case insensitivity for all transports.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I expect performance to be terrible, and I did two horrible things, but it compiles.
dispatcher.unsafeRunSync( | ||
Functor[F].void(setter.set(carrier, key, value)) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💩
def get[A](key: JContextKey[A]): A = | ||
context.get(key) match { | ||
case Some(a) => a | ||
case None => null.asInstanceOf[A] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💩
Useful thought exercise, but a dead end. |
Fixes #123