クラス PropagationContextElement

java.lang.ObjectSE
kotlin.coroutines.AbstractCoroutineContextElement
org.springframework.core.PropagationContextElement
実装されているすべてのインターフェース:
kotlin.coroutines.CoroutineContext, kotlin.coroutines.CoroutineContext.Element, kotlinx.coroutines.ThreadContextElement<io.micrometer.context.ContextSnapshot.Scope>

public final class PropagationContextElement extends kotlin.coroutines.AbstractCoroutineContextElement implements kotlinx.coroutines.ThreadContextElement<io.micrometer.context.ContextSnapshot.Scope>
ThreadContextElement は、スレッド上でコルーチンが再開された際に、Micrometer コンテキスト伝播ライブラリに登録されたコンテキストがキャプチャーされ、復元されることを保証します。これは通常、Kotlin の中断された関数における Micrometer トレースのサポートに使用されます。

io.micrometer:context-propagation ライブラリが必要です。クラスパスに org.jetbrains.kotlinx:kotlinx-coroutines-reactor 依存関係も存在する場合、この要素は Reactor と Context もサポートします。

PropagationContextElement は次のように使用できます。

fun main() {
    runBlocking(Dispatchers.IO + PropagationContextElement()) {
        suspendingFunction()
    }
}

suspend fun suspendingFunction() {
    delay(1)
    logger.info("Log statement with traceId")
}
導入:
7.0
作成者:
Brian Clozel, Sebastien Deleuze
  • ネストされたクラスの要約

    ネストされたクラス
    修飾子と型
    クラス
    説明
    static final class

    インターフェース kotlin.coroutines.CoroutineContext から継承されたネストクラス / インターフェース

    kotlin.coroutines.CoroutineContext.Element

    インターフェース kotlin.coroutines.CoroutineContext.Element から継承されたネストクラス / インターフェース

    kotlin.coroutines.CoroutineContext.Element.DefaultImpls

    インターフェース kotlinx.coroutines.ThreadContextElement から継承されたネストクラス / インターフェース

    kotlinx.coroutines.ThreadContextElement.DefaultImpls
  • フィールドのサマリー

    フィールド
    修飾子と型
    フィールド
    説明
    PropagationContextElement キー。
  • コンストラクターの概要

    コンストラクター
    コンストラクター
    説明
  • メソッドのサマリー

    修飾子と型
    メソッド
    説明
    void
    restoreThreadContext(kotlin.coroutines.CoroutineContext context, io.micrometer.context.ContextSnapshot.Scope oldState)
    io.micrometer.context.ContextSnapshot.Scope
    updateThreadContext(kotlin.coroutines.CoroutineContext context)

    クラス kotlin.coroutines.AbstractCoroutineContextElement から継承されたメソッド

    fold, get, getKey, minusKey, plus

    クラス ObjectSE から継承されたメソッド

    clone, equalsSE, finalize, getClass, hashCode, notify, notifyAll, toString, wait, waitSE, waitSE

    インターフェース kotlin.coroutines.CoroutineContext から継承されたメソッド

    plus

    インターフェース kotlin.coroutines.CoroutineContext.Element から継承されたメソッド

    fold, get, getKey, minusKey
  • フィールドの詳細

  • コンストラクターの詳細

    • PropagationContextElement

      public PropagationContextElement()
  • メソッドの詳細

    • restoreThreadContext

      public void restoreThreadContext(kotlin.coroutines.CoroutineContext context, io.micrometer.context.ContextSnapshot.Scope oldState)
      次で指定:
      インターフェース kotlinx.coroutines.ThreadContextElement<io.micrometer.context.ContextSnapshot.Scope>restoreThreadContext 
    • updateThreadContext

      public io.micrometer.context.ContextSnapshot.Scope updateThreadContext(kotlin.coroutines.CoroutineContext context)
      次で指定:
      インターフェース kotlinx.coroutines.ThreadContextElement<io.micrometer.context.ContextSnapshot.Scope>updateThreadContext