Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@dkarlinsky
Copy link
Contributor

@dkarlinsky dkarlinsky commented Nov 2, 2021

Back-porting ThreadLocalBridge from ZIO 2
ZIO 2 PR: #5907

* runtime.mapPlatform(_.withSuperviseOperations(true).withSupervisor(supervisor)).
* }}}
*/
def trackFiberRef[A](initialValue: A)(link: A => Unit): UIO[(Supervisor[Unit], TrackingFiberRef[A])] =
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this is not really related to this PR, but I just wanted to get some opinions regarding the following:

I'm wondering if it would be possible to enable users to track all events from Fiber's lifecycle: start, resume, suspend, end? Ideally, providing Fiber identifier to callbacks.

This would allow users to add interoperability with libraries that utilize ThreadLocals. One prominent example is automatic instrumentation by OpenTelemetry agent. It provides a lot of value out of the box, but there is no way to pick up current context when Fibers are started by HTTP server, for example.

I made a proof of concept supervisor that enables such interoperability: https://github.com/dmytr/zio-otel-instrumentation/blob/main/src/main/scala/zio/OpenTelemetrySupervisor.scala. It tracks OpenTelemetry context on per-fiber base, so it needs to have a hold on some kind of Fiber identifier. Unfortunately, it relies on ZIO's package-private APIs making it usable by very brave people only 😂

Maybe, if initialValue's type is changed to => A and it gets evaluated in Supervisor.unsafeOnStart we could achieve this context capturing capability? And A could be a user-defined unique identifier for that particular Fiber.

I guess, ideally, API would look like this:

def trackFiberLifecycle(
  onStart: => A, 
  onEnd: A => Unit,
  onSuspend: A => Unit,
  onResume: A => Unit
): Supervisor[Unit]

Copy link
Contributor

Choose a reason for hiding this comment

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

@dmytr I would take a look at the functionality for this in ZIO 2.0. I think it provides basically what you are describing, though I do think we need to implement a constructor to use it from third party code.

@dkarlinsky dkarlinsky changed the title issue #5878 - Backport RuntimeConfigAspect.trackFiberRef issue #5878 - Backport ThreadLocalBridge May 29, 2022
@adamgfraser adamgfraser merged commit 22921ee into zio:master May 30, 2022
adamgfraser pushed a commit that referenced this pull request Jun 24, 2022
* Add Prezi to adopters list (#6864)

* Fix ZIO 1.x sidebars (#6863)

* remove extra sidebar
rename how-to to guides

* rename howto to guides.

* issue #5878 - Backport ThreadLocalBridge (#5980)

* Rewritten based on the merged version of PR #5907

* call Supervisor.unsafeOnResume() even if `superviseOperations` is false (same as ZIO 2)

* chore(deps): update zio.version to v1.0.15 (#6899)

Co-authored-by: Renovate Bot <[email protected]>

* add 7 and 8 arg for check, checkM, checkAll and checkAllM (#6916)

* Fix frontmatters (#6949)

* remove extra usecases sidebar.

Co-authored-by: Mate Borcsok <[email protected]>
Co-authored-by: Dmitry Karlinsky <[email protected]>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Renovate Bot <[email protected]>
Co-authored-by: LUC DUZAN <[email protected]>
Co-authored-by: Daniel Vigovszky <[email protected]>
adamgfraser pushed a commit that referenced this pull request Jun 24, 2022
* remove handle error page.

* expected errors vs. unexpected errors.

* don't type unexpected errors.

* add a general note for when importing effects.

* modeling domain errors using algebraic data types.

* typed errors using union types.

* using union type to be more specific about error types.

* don't reflexively log errors.

* exceptional and unexceptional effects.

* imperative vs. functional error handling.

* lossless error model.

* either and absolve.

* some note about orDie.

* sandbox and unsandbox.

* zio defects and fatal errors.

* default

* converting defects to failures and vice versa.

* refining and unrefining the type of the error channel.

* absorbing or resurrecting vs. dying.

* converting defects to failures.

* write an introduction to sandboxing errors.

* a better title for sandbox section.

* three type of errors in zio.

* add examples.

* add tslib.

* create a new page for error management.

* some and unsome zio values.

* use compile-only modifier for mdoc blocks.

* creating a ZIO of optional values.

* ZIO.getOrFail constructor.

* explain more on getOrFail constructors.

* flattening optional error types.

* ZIO#getOrElse

* document the ZIO#someOrElseZIO operator.

* someOrFail operation.

* add a note on some or fail exception.

* fix the example of ZIO#sandboxWith.

* introduction for error management.

* add example for sandboxWith operator.

* fallback on optional error types.

* ZIO#orElseFail.

* more note on ZIO#orElseFail and also add documentation for ZIO#orElseSucceed.

* document ZIO#orElse operator.

* clean up code blocks and their imports.

* document ZIO#orElseEither.

* document fold operators.

* document ZIO#foldTraceZIO

* remove extra table.

* write a note on fiber interruption and the fold operator.

* retry and retryOrElse operators.

* retryOrElseEither.

* ZIO#retryN

* retryUntil and retryUntilZIO

* retryUntilEqual

* retryWhile, retryWhileZIO and retryWhileEquals

* timeout operator

* cleanup

* using ZIO#disconnect with ZIO#timeout.

* ZIO#timeoutTo

* producing error message in case of timeout.

* cleanup absolve and either section.

* cleanup sandbox examples.

* catchAll convert exceptional effects to unexceptional effects.

* catchSome section

* note on catching defects and fiber interruptions.

* catching defects.

* catching all errors.

* catching traces.

* typed errors don't guarantee the absence of defects and interruptions.

* fix mdoc's error.

* cause is a semiring and show how the cause designed.

* cause internals.

* failure cause.

* wip on cause page.

* wip on cause.

* then cause for sequential errors.

* cleanup the cause page.

* clean-up.

* definition of the exit data type.

* cause internals.

* add result type.

* fix mdoc failure.

* fix `mdoc -watch` breakage.

* update mdoc version.

* complete failure section.

* clean up fatal errors section.

* reorder topics.

* fix title.

* sequential and parallel errors.

* change header levels.

* exposing parallel failure errors.

* error accumulation.

* introduce ZIO#validate and ZIO#validatePar operators.

* cleanup.

* add function definitions.

* write a note about ZIO#validateWith.

* merging the error channel into success channel.

* flipping the error and success channels.

* firstSuccessOf

* add more explanation.

* nonOrFail

* getOrFail and nonOrFail.

* rejecting some values.

* fix method name.

* map and flatMap on error channels.

* introduce all error refinement methods.

* introduce left/unleft, right/unright operations.

* cleanup.

* converting optional values to optional errors and vice versa.

* rename left and right section.

* uncovering the underlying cause of an effect.

* cleanup

* catching non-fatal.

* filtering the success channel values.

* complete ZIO#someOrElse section.

* tapping.

* tapping errors.

* add definition of ZIO#resurrect and ZIO#absorb.

* add definition of ZIO#either and ZIO#absolve.

* add tapSome.

* write a note about why we need to catch defects.

* remove extra note.

* add definition of all catch methods.

* cleanup.

* proofreading.

* cleanup zio.md page.

* fix mdoc errors.

* fix validate output.

* examples

* cleanup.

* remove default services from the zio environment.

* fix imports.

* fix typo.

* use ZIO instead of IO.

* fix mdoc errors.

# Conflicts:
#	docs/datatypes/core/zio/zio.md

* regarding removal of RuntimeConfig.

* fix warning.

* Switch ZIO version for 1.0 docs to 1.0.14

* Upgrade to docusaurus beta-20

* Add appId to docusaurus config

* Make Overview link version aware

* testing versioned links

* another try on versioned links

* Trying a version relative link

* yet another relative link try

* Playing with config vars

* trying docsVersion without statis override

* Try version specific navbar

* Swizzling Navbar component for version resolution

* Switch navbar links to doc links

* Correct docid in sidebar

* Break site build on broken links

* Add Prezi to adopters list (#6864)

* Fix ZIO 1.x sidebars (#6863)

* remove extra sidebar
rename how-to to guides

* rename howto to guides.

* issue #5878 - Backport ThreadLocalBridge (#5980)

* Rewritten based on the merged version of PR #5907

* call Supervisor.unsafeOnResume() even if `superviseOperations` is false (same as ZIO 2)

* chore(deps): update zio.version to v1.0.15 (#6899)

Co-authored-by: Renovate Bot <[email protected]>

* workaround.

* remove empty article.

* prepare for publish.

* fix mdoc errors.

* minor change.

* update zio-kafka ecosystem page.

* add 7 and 8 arg for check, checkM, checkAll and checkAllM (#6916)

* initial work.

* conclusion section.

* fix sidebar.

* fix site build problem.

* initial work.

* Fix frontmatters (#6949)

* Use master for version 1 build for now

* remove extra usecases sidebar.

* orrect navbar

* Switch back version 1 docs ref

* Remove docusaurus site build from sbt message

* Fix some broken links

* Fix checkSite build step

* Remove obsolete link

* Replace occurrences of ZTrace with Trace

Co-authored-by: Milad Khajavi <[email protected]>
Co-authored-by: Mate Borcsok <[email protected]>
Co-authored-by: Dmitry Karlinsky <[email protected]>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Renovate Bot <[email protected]>
Co-authored-by: LUC DUZAN <[email protected]>
Co-authored-by: Daniel Vigovszky <[email protected]>
vigoo added a commit that referenced this pull request Jun 25, 2022
* remove handle error page.

* expected errors vs. unexpected errors.

* don't type unexpected errors.

* add a general note for when importing effects.

* modeling domain errors using algebraic data types.

* typed errors using union types.

* using union type to be more specific about error types.

* don't reflexively log errors.

* exceptional and unexceptional effects.

* imperative vs. functional error handling.

* lossless error model.

* either and absolve.

* some note about orDie.

* sandbox and unsandbox.

* zio defects and fatal errors.

* default

* converting defects to failures and vice versa.

* refining and unrefining the type of the error channel.

* absorbing or resurrecting vs. dying.

* converting defects to failures.

* write an introduction to sandboxing errors.

* a better title for sandbox section.

* three type of errors in zio.

* add examples.

* add tslib.

* create a new page for error management.

* some and unsome zio values.

* use compile-only modifier for mdoc blocks.

* creating a ZIO of optional values.

* ZIO.getOrFail constructor.

* explain more on getOrFail constructors.

* flattening optional error types.

* ZIO#getOrElse

* document the ZIO#someOrElseZIO operator.

* someOrFail operation.

* add a note on some or fail exception.

* fix the example of ZIO#sandboxWith.

* introduction for error management.

* add example for sandboxWith operator.

* fallback on optional error types.

* ZIO#orElseFail.

* more note on ZIO#orElseFail and also add documentation for ZIO#orElseSucceed.

* document ZIO#orElse operator.

* clean up code blocks and their imports.

* document ZIO#orElseEither.

* document fold operators.

* document ZIO#foldTraceZIO

* remove extra table.

* write a note on fiber interruption and the fold operator.

* retry and retryOrElse operators.

* retryOrElseEither.

* ZIO#retryN

* retryUntil and retryUntilZIO

* retryUntilEqual

* retryWhile, retryWhileZIO and retryWhileEquals

* timeout operator

* cleanup

* using ZIO#disconnect with ZIO#timeout.

* ZIO#timeoutTo

* producing error message in case of timeout.

* cleanup absolve and either section.

* cleanup sandbox examples.

* catchAll convert exceptional effects to unexceptional effects.

* catchSome section

* note on catching defects and fiber interruptions.

* catching defects.

* catching all errors.

* catching traces.

* typed errors don't guarantee the absence of defects and interruptions.

* fix mdoc's error.

* cause is a semiring and show how the cause designed.

* cause internals.

* failure cause.

* wip on cause page.

* wip on cause.

* then cause for sequential errors.

* cleanup the cause page.

* clean-up.

* definition of the exit data type.

* cause internals.

* add result type.

* fix mdoc failure.

* fix `mdoc -watch` breakage.

* update mdoc version.

* complete failure section.

* clean up fatal errors section.

* reorder topics.

* fix title.

* sequential and parallel errors.

* change header levels.

* exposing parallel failure errors.

* error accumulation.

* introduce ZIO#validate and ZIO#validatePar operators.

* cleanup.

* add function definitions.

* write a note about ZIO#validateWith.

* merging the error channel into success channel.

* flipping the error and success channels.

* firstSuccessOf

* add more explanation.

* nonOrFail

* getOrFail and nonOrFail.

* rejecting some values.

* fix method name.

* map and flatMap on error channels.

* introduce all error refinement methods.

* introduce left/unleft, right/unright operations.

* cleanup.

* converting optional values to optional errors and vice versa.

* rename left and right section.

* uncovering the underlying cause of an effect.

* cleanup

* catching non-fatal.

* filtering the success channel values.

* complete ZIO#someOrElse section.

* tapping.

* tapping errors.

* add definition of ZIO#resurrect and ZIO#absorb.

* add definition of ZIO#either and ZIO#absolve.

* add tapSome.

* write a note about why we need to catch defects.

* remove extra note.

* add definition of all catch methods.

* cleanup.

* proofreading.

* cleanup zio.md page.

* fix mdoc errors.

* fix validate output.

* examples

* cleanup.

* remove default services from the zio environment.

* fix imports.

* fix typo.

* use ZIO instead of IO.

* fix mdoc errors.

# Conflicts:
#	docs/datatypes/core/zio/zio.md

* regarding removal of RuntimeConfig.

* fix warning.

* Switch ZIO version for 1.0 docs to 1.0.14

* Upgrade to docusaurus beta-20

* Add appId to docusaurus config

* Make Overview link version aware

* testing versioned links

* another try on versioned links

* Trying a version relative link

* yet another relative link try

* Playing with config vars

* trying docsVersion without statis override

* Try version specific navbar

* Swizzling Navbar component for version resolution

* Switch navbar links to doc links

* Correct docid in sidebar

* Break site build on broken links

* Add Prezi to adopters list (#6864)

* Fix ZIO 1.x sidebars (#6863)

* remove extra sidebar
rename how-to to guides

* rename howto to guides.

* issue #5878 - Backport ThreadLocalBridge (#5980)

* Rewritten based on the merged version of PR #5907

* call Supervisor.unsafeOnResume() even if `superviseOperations` is false (same as ZIO 2)

* chore(deps): update zio.version to v1.0.15 (#6899)

Co-authored-by: Renovate Bot <[email protected]>

* workaround.

* remove empty article.

* prepare for publish.

* fix mdoc errors.

* minor change.

* update zio-kafka ecosystem page.

* add 7 and 8 arg for check, checkM, checkAll and checkAllM (#6916)

* initial work.

* conclusion section.

* fix sidebar.

* fix site build problem.

* initial work.

* Fix frontmatters (#6949)

* Use master for version 1 build for now

* remove extra usecases sidebar.

* orrect navbar

* Switch back version 1 docs ref

* Remove docusaurus site build from sbt message

* Fix some broken links

* Fix checkSite build step

* Remove obsolete link

* Replace occurrences of ZTrace with Trace

* Make version 2 the default docs version
Rewire the getting started button

* Update package.json to compatible packages

* Fix time call

* Fix sidebar tirles

Co-authored-by: Milad Khajavi <[email protected]>
Co-authored-by: Mate Borcsok <[email protected]>
Co-authored-by: Dmitry Karlinsky <[email protected]>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Renovate Bot <[email protected]>
Co-authored-by: LUC DUZAN <[email protected]>
Co-authored-by: Daniel Vigovszky <[email protected]>
@kubukoz kubukoz mentioned this pull request Jun 27, 2022
adamgfraser pushed a commit that referenced this pull request Jul 1, 2022
* Add Prezi to adopters list (#6864)

* Fix ZIO 1.x sidebars (#6863)

* remove extra sidebar
rename how-to to guides

* rename howto to guides.

* issue #5878 - Backport ThreadLocalBridge (#5980)

* Rewritten based on the merged version of PR #5907

* call Supervisor.unsafeOnResume() even if `superviseOperations` is false (same as ZIO 2)

* chore(deps): update zio.version to v1.0.15 (#6899)

Co-authored-by: Renovate Bot <[email protected]>

* add 7 and 8 arg for check, checkM, checkAll and checkAllM (#6916)

* Fix frontmatters (#6949)

* Update cause.md (#6988)

Fixed wrong indentation level for examples

* Scala Native on Scala 3 (#6310)

* Scala Native on Scala 3

* Update BuildHelper.scala

* Use scala-java-time for both JS and Native, compatible with Scala 3

* drop dottySettings, use the same settings for all versions

* Scala JS 1.10.0

* izumi-reflect 2.1.1-SNAPSHOT

* Add scalajs-java-securerandom

* don't change ci.yml

* Update scalacheck to support Scala 3 Native

* Update libraries

* Work around issues in Scala 3 Native when overriding members without ()

* Work around issues in Scala 3 Native when overriding members without ()

* izumi-reflect 2.1.1

* Update plugins.sbt (#6996)

* Compile tests on Scala Native (#6283)

* Scala Native 0.4.3

* Minimize changes

* Use scala-java-time instead of sjavatime for Scala Native

* Run tests on Scala Native, not just compile

* Update plugins.sbt

* native-loop-core 0.2.1

* Update ci.yml

* format

* fix Scala 2.11

* fix Scala 2.11

* fix Scala 2.11

* More memory for non-JVM processes

* Just build tests, don't run them

* Add nativeSettings to streamsTests and testTests

* fix 2.11 Native

* fix 2.11 Native

* -Xmx4G

* izumi-reflect 2.1.3

* fix Scala 3

Co-authored-by: Mate Borcsok <[email protected]>
Co-authored-by: Milad Khajavi <[email protected]>
Co-authored-by: Dmitry Karlinsky <[email protected]>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Renovate Bot <[email protected]>
Co-authored-by: LUC DUZAN <[email protected]>
Co-authored-by: Daniel Vigovszky <[email protected]>
Co-authored-by: felix-hedenstrom <[email protected]>
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.

3 participants