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

Experimental IOLocalContextStorage #214

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from
Draft

Experimental IOLocalContextStorage #214

wants to merge 17 commits into from

Conversation

rossabaker
Copy link
Member

@rossabaker rossabaker commented May 12, 2023

I think this is doomed, but putting it out there to continue the discussion in #202.

Edit by @NthPortal: it is not necessarily doomed

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 tantalizingly close to working, but I don't think it ever can.

rootLog.setLevel(Level.FINE)
rootLog.getHandlers().head.setLevel(Level.FINE)
}
ioLocal <- IOLocal(null: 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.

We have to add the wrapper before we refer to Context, or else we get a FINE message that we're being ignored.

@iRevive
Copy link
Contributor

iRevive commented May 14, 2023

Does it seamlessly propagate the context? At least from the examples, it seems it does.

@rossabaker
Copy link
Member Author

rossabaker commented May 18, 2023

I don't think it works at all, because the dispatched fibers have their own IOLocal state. But typelevel/cats-effect#3636 may open a new path.

build.sbt Outdated Show resolved Hide resolved
examples/src/main/scala/ContextStorageExample.scala Outdated Show resolved Hide resolved
build.sbt Outdated Show resolved Hide resolved
@rossabaker
Copy link
Member Author

6b542aa probably belongs on main for general cleanliness. The motivator here is that the Java SDK loads its own testkit if it's present, in preference to any other SPI implementation, like ours.

examples/src/main/scala/ContextStorageExample.scala Outdated Show resolved Hide resolved
class IOLocalContextStorageProvider extends ContextStorageProvider {
def get(): ContextStorage =
new IOLocalContextStorage(
Eval.later(IOLocalContextStorageProvider.localContext)
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't access Context.root() before the storage is initialized. Yikes!

object IOLocalContextStorageProvider {
val localContext: IOLocal[Context] =
IOLocal[Context](Context.root())
.syncStep(100)
Copy link
Member Author

Choose a reason for hiding this comment

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

I think 1 is sufficient, but this would be a stupid reason to have a fatal error, so I was generous.

@rossabaker
Copy link
Member Author

This is going to want to live in an SPI module. Having more than one on the classpath is like multiple slf4j bindings.

Co-authored-by: Arman Bilge <[email protected]>
@NthPortal
Copy link
Contributor

I just realised there's a small problem of this not being the same type of context used in the API of the java backend, and I'm not entirely sure how to deal with that

@NthPortal
Copy link
Contributor

so, with the new context implementation, if we use our own context and just have the custom ContextStorage unbox it, that should work fine. but we also need to expose access to a Local[F, Context] so that scala API users can access the context

import io.opentelemetry.context.ContextStorageProvider

object IOLocalContextStorageProvider {
val localContext: IOLocal[Context] =
Copy link
Contributor

Choose a reason for hiding this comment

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

any reason not to make this lazy?

@NthPortal
Copy link
Contributor

just want to drop a note that I've been working on this (with Ross' blessing), and have a working implementation with tests. there's just the teeny, tiny problem that it depends not just on an unreleased cats effect version but on one that's not even merged yet. so, uh. not sure quite what to do about that

@iRevive iRevive mentioned this pull request Sep 29, 2023
2 tasks
Finish implementing `IOLocalContextStorage` and
`IOLocalContextStorageProvider` for sharing context modifications
between Java and Scala instrumentation.
@NthPortal
Copy link
Contributor

NthPortal commented Oct 4, 2023

this is ready for review. I'm reluctant to mark it as not a draft however, until typelevel/cats-effect#3636 is merged


import java.util.logging._

object ContextStorageExample extends IOApp.Simple {
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be removed now that tests exist?

@razvanz
Copy link

razvanz commented May 15, 2024

@iRevive Has this been accidentally closed?

@iRevive
Copy link
Contributor

iRevive commented May 15, 2024

@razvanz thanks for pointing out! I guess I linked the wrong task/PR, and it closed automatically.

@iRevive iRevive reopened this May 15, 2024
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.

5 participants