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 LocalProvider #441

Merged
merged 2 commits into from
Feb 4, 2024
Merged

Add LocalProvider #441

merged 2 commits into from
Feb 4, 2024

Conversation

iRevive
Copy link
Contributor

@iRevive iRevive commented Jan 18, 2024

Follow-up to #420 (comment).

Motivation

Currently, there is no way to provide an arbitrary IOLocal or Local instance to certain OtelJava methods.
For example, you cannot use OtelJava.resource with an arbitrary IOLocal instance.

Why would you want to use a custom IOLocal? To have direct access to the Context and keep the benefits of the resource API. For example, #431 (comment).

Drawbacks

  1. LocalProvider is kinda a magic implicit. The derivation logic may be confusing for newcomers
  2. In some cases, the explicit type must be provided (e.g. OtelJava.autoConfigured[IO]()).

The LocalProvider has usages beyond OtelJava. It fits nicely into the SDK module too:

def loadSdk(
resource: TelemetryResource,
config: Config
): Resource[F, OpenTelemetrySdk[F]] =
Resource.eval(Random.scalaUtilRandom[F]).flatMap { implicit random =>
Resource.eval(LocalProvider[F, Context].local).flatMap {
implicit local =>
implicit val console: Console[F] = Console.make[F]
val builder =
SdkTracerProvider.builder[F].withResource(resource)
for {
.

Co-authored-by: Marissa | April <7505383+NthPortal@users.noreply.github.com>
@NthPortal
Copy link
Contributor

is this waiting on something?

@iRevive
Copy link
Contributor Author

iRevive commented Feb 4, 2024

Not really, we can merge this one.

@iRevive iRevive merged commit ddb5829 into typelevel:main Feb 4, 2024
10 checks passed
@iRevive iRevive deleted the local-provider branch February 4, 2024 10:06
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.

2 participants