Skip to content
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

Closed
wants to merge 2 commits into from
Closed

TextMapPropagator draft #124

wants to merge 2 commits into from

Conversation

rossabaker
Copy link
Member

Fixes #123

Copy link
Member Author

@rossabaker rossabaker left a 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,
Copy link
Member Author

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 {
Copy link
Member Author

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.

Copy link
Member Author

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[_]] {
Copy link
Member Author

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]
Copy link
Member Author

@rossabaker rossabaker Feb 10, 2023

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.

Copy link
Member Author

@rossabaker rossabaker left a 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.

Comment on lines +111 to +113
dispatcher.unsafeRunSync(
Functor[F].void(setter.set(carrier, key, value))
)
Copy link
Member Author

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]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💩

@rossabaker
Copy link
Member Author

Useful thought exercise, but a dead end.

@rossabaker rossabaker closed this Feb 12, 2023
@iRevive iRevive mentioned this pull request Aug 31, 2023
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Context propagation
1 participant