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

Add IOLocalContextStorage #214

Merged
merged 30 commits into from
Dec 31, 2024
Merged

Add IOLocalContextStorage #214

merged 30 commits into from
Dec 31, 2024

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
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
@mergify mergify bot added module:oteljava Features and improvements to the oteljava module module:sdk Features and improvements to the sdk module metrics Improvement to metrics module tracing Improvements to tracing module labels Dec 13, 2024
@iRevive iRevive changed the title Experimental IOLocalContextStorage [CE 3.6] Experimental IOLocalContextStorage Dec 15, 2024
build.sbt Outdated Show resolved Hide resolved
@NthPortal
Copy link
Contributor

thanks for updating this @iRevive!

@iRevive iRevive marked this pull request as ready for review December 28, 2024 08:09
@iRevive iRevive changed the title [CE 3.6] Experimental IOLocalContextStorage Add IOLocalContextStorage Dec 31, 2024
@mergify mergify bot added the documentation Improvements or additions to documentation label Dec 31, 2024
@mergify mergify bot added the module:core Features and improvements to core module label Dec 31, 2024
@iRevive iRevive merged commit 6783b22 into main Dec 31, 2024
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation metrics Improvement to metrics module module:core Features and improvements to core module module:oteljava Features and improvements to the oteljava module module:sdk Features and improvements to the sdk module tracing Improvements to tracing module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants