GithubHelp home page GithubHelp logo

buzzardo / context-propagation Goto Github PK

View Code? Open in Web Editor NEW

This project forked from micrometer-metrics/context-propagation

0.0 0.0 0.0 505 KB

Context Propagation API

License: Apache License 2.0

Shell 1.14% Java 98.86%

context-propagation's Introduction

Context Propagation Library

Build Status Apache 2.0 Maven Central Javadocs Revved up by Gradle Enterprise

Overview

A library that assists with context propagation across different types of context mechanisms such as ThreadLocal, Reactor Context, and others.

Abstractions:

  • ThreadLocalAccessor - contract to assist with access to a ThreadLocal value.
  • ContextAccessor - contract to assist with access to a Map-like context.
  • ContextRegistry - registry for instances of ThreadLocalAccessor and ContextAccessor.
  • ContextSnapshot - holder of contextual values, that provides methods to capture and to propagate.

You can read the full reference documentation here.

Example Scenarios:

  • In imperative code, e.g. Spring MVC controller, capture ThreadLocal values into a ContextSnapshot. After that use the snapshot to populate a Reactor Context with the captured values, or to wrap a task (e.g. Runnable, Callable, etc) or an Executor with a decorator that restores ThreadLocal values when the task executes.
  • In reactive code, e.g. Spring WebFlux controller, create a ContextSnapshot from Reactor Context values. After that use the snapshot to restore ThreadLocal values within a specific stage (operator) of the reactive chain.

Context values can originate from any context mechanism and propagate to any other, any number of times. For example, a value in a Reactor context may originate as a ThreadLocal, and may yet become a ThreadLocal again, and so on.

Generally, imperative code should interact with ThreadLocal values as usual, and likewise Reactor code should interact with the Reactor Context as usual. The Context Propagation library is not intended to replace those, but to assist with propagation when crossing from one type of context to another, e.g. when imperative code invokes a Reactor chain, or when a Reactor chain invokes an imperative component that expects ThreadLocal values.

The library is not limited to context propagation from imperative to reactive. It can assist in asynchronous scenarios to propagate ThreadLocal values from one thread to another. It can also propagate to any other type of context for which there is a registered ContextAccesor instance.

Artifacts

Snapshots are published to repo.spring.io for every successful build on the main branch and maintenance branches.

repositories {
    maven { url 'https://repo.spring.io/snapshot' }
}

dependencies {
    implementation 'io.micrometer:context-propagation:latest.integration'
}

Milestone releases are published to https://repo.spring.io/milestone. Include that as a maven repository in your build configuration to use milestone releases. Note that milestone releases are for testing purposes and are not intended for production use.

These artifacts work with Java 8 or later.

Contributing

See our Contributing Guide for information about contributing to Micrometer Context Propagation.

Code formatting

The spring-javaformat plugin is configured to check and apply consistent formatting in the codebase through the build. The checkFormat task checks the formatting as part of the check task. Apply formatting with the format task. You should rely on the formatting the format task applies instead of your IDE's configured formatting.

Join the discussion

Join the Micrometer Slack (#context-propagation channel) to share your questions, concerns, and feature requests.


Licensed under Apache Software License 2.0

Sponsored by VMware

context-propagation's People

Contributors

bclozel avatar chemicl avatar dependabot[bot] avatar izeye avatar jonatan-ivanov avatar marcingrzejszczak avatar rstoyanchev avatar shakuzen avatar simonbasle avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.