MDC Context lost its associated to individual thread

オープン
#7,376 コメント 10 件 リアクション 1 件 担当者 0 名 GitHub で見る

メンテナーはふだん 3 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
java, mongodb, spring

調査の方向性

リンクされた POC から始め、アプリケーションを起動し、ドキュメント化された quiz エンドポイントを呼び出して、欠落している baggage 値を再現します。リアクティブな WebFilter、MongoDB 操作、エラーハンドラー周辺のログを読み、その後、関連する issue 5055 を確認します。更新された baggage 値が例外ログとエラーログに残り、scope の終了に関する警告が表示されなければ完了です。

索引モデルが issue の本文から書いたものです。

説明

Bug

Describe the bug
We have a use case where we are setting the baggage in scope during the webfilter but in the flow the value being lost

Steps to reproduce
we have attached a poc, which contains 2 endpoint, you can just bootrun the application and hit the api localhost:8089/api/quizzes/5d20cccab90a07e7190b2b9f. when we hit the api we get the below in logs, If i explain well, we have created the baggage for username with value "sub" then later we override the value after calling the api with "sub-service1" and we expect the "sub-service1" to be available when we are throwing the IllegalArgumentException

025-05-28T09:53:33.335+05:30 "DEBUG[otel-tracing,7c400339c6954d64fa1da33cc40da8ec,6c5c7f76e35841ea,sub]" 10988 --- [otel-tracing] [ctor-http-nio-3] [7c400339c6954d64fa1da33cc40da8ec-6c5c7f76e35841ea] s.w.r.r.m.a.RequestMappingHandlerMapping : [bc350e2f-1] Mapped to com.example.otel_tracing.resource.QuestionResource#findById(ObjectId)
2025-05-28T09:53:33.545+05:30 "DEBUG[otel-tracing,7c400339c6954d64fa1da33cc40da8ec,6c5c7f76e35841ea,sub]" 10988 --- [otel-tracing] [ctor-http-nio-3] [7c400339c6954d64fa1da33cc40da8ec-6c5c7f76e35841ea] o.s.d.m.core.ReactiveMongoTemplate       : findOne using query: { "id" : { "$oid" : "5d20cccab90a07e7190b2b9f"}} fields: Document{{}} for class: class com.example.otel_tracing.model.entity.Question in collection: question
2025-05-28T09:53:33.581+05:30 " INFO[otel-tracing,7c400339c6954d64fa1da33cc40da8ec,6c5c7f76e35841ea,sub]" 10988 --- [otel-tracing] [ctor-http-nio-3] [7c400339c6954d64fa1da33cc40da8ec-6c5c7f76e35841ea] c.e.o.resource.QuestionResource          : Finding question
2025-05-28T09:53:33.587+05:30 " INFO[otel-tracing,7c400339c6954d64fa1da33cc40da8ec,6c5c7f76e35841ea,sub]" 10988 --- [otel-tracing] [ctor-http-nio-3] [7c400339c6954d64fa1da33cc40da8ec-6c5c7f76e35841ea] c.e.o.service.QuestionService            : finding question with id: 5d20cccab90a07e7190b2b9f
2025-05-28T09:53:33.703+05:30 "DEBUG[otel-tracing,7c400339c6954d64fa1da33cc40da8ec,6c5c7f76e35841ea,sub-service1]" 10988 --- [otel-tracing] [ctor-http-nio-3] [7c400339c6954d64fa1da33cc40da8ec-6c5c7f76e35841ea] org.mongodb.driver.cluster               : Server selection started for operation with ID 7. Selector: ReadPreferenceServerSelector{readPreference=primary}, topology description: {type=REPLICA_SET, servers=[{address=localhost:27017, type=REPLICA_SET_PRIMARY, roundTripTime=131.2 ms, state=CONNECTED}]
2025-05-28T09:53:33.719+05:30 "DEBUG[otel-tracing,7c400339c6954d64fa1da33cc40da8ec,6c5c7f76e35841ea,sub-service1]" 10988 --- [otel-tracing] [ctor-http-nio-3] [7c400339c6954d64fa1da33cc40da8ec-6c5c7f76e35841ea] org.mongodb.driver.cluster               : Server selection succeeded for operation with ID 7. Selected server: localhost:27017. Selector: ReadPreferenceServerSelector{readPreference=primary}, topology description: {type=REPLICA_SET, servers=[{address=localhost:27017, type=REPLICA_SET_PRIMARY, roundTripTime=131.2 ms, state=CONNECTED}]
2025-05-28T09:53:33.730+05:30 "DEBUG[otel-tracing,7c400339c6954d64fa1da33cc40da8ec,6c5c7f76e35841ea,sub-service1]" 10988 --- [otel-tracing] [ctor-http-nio-3] [7c400339c6954d64fa1da33cc40da8ec-6c5c7f76e35841ea] org.mongodb.driver.connection            : Checkout started for connection to localhost:27017
2025-05-28T09:53:33.742+05:30 "DEBUG[otel-tracing,7c400339c6954d64fa1da33cc40da8ec,6c5c7f76e35841ea,sub-service1]" 10988 --- [otel-tracing] [ctor-http-nio-3] [7c400339c6954d64fa1da33cc40da8ec-6c5c7f76e35841ea] i.o.context.ThreadLocalContextStorage    :  Trying to close scope which does not represent current context. Ignoring the call.
2025-05-28T09:53:34.021+05:30 "DEBUG[otel-tracing,7c400339c6954d64fa1da33cc40da8ec,6c5c7f76e35841ea,]" 10988 --- [otel-tracing] [ntLoopGroup-3-3] [7c400339c6954d64fa1da33cc40da8ec-6c5c7f76e35841ea] a.w.r.e.AbstractErrorWebExceptionHandler : [bc350e2f-1] Resolved [IllegalArgumentException: Question with id 5d20cccab90a07e7190b2b9f not found] for HTTP GET /api/quizzes/5d20cccab90a07e7190b2b9f
2025-05-28T09:53:34.022+05:30 "ERROR[otel-tracing,7c400339c6954d64fa1da33cc40da8ec,6c5c7f76e35841ea,]" 10988 --- [otel-tracing] [ntLoopGroup-3-3] [7c400339c6954d64fa1da33cc40da8ec-6c5c7f76e35841ea] a.w.r.e.AbstractErrorWebExceptionHandler : [bc350e2f-1]  500 Server Error for HTTP GET "/api/quizzes/5d20cccab90a07e7190b2b9f"

What did you expect to see?
Previously we were using brave implementation just now we have migrated to otel implementation, with brave we have the following logs username value sub-service1 is not lost.

2025-05-28T09:44:07.924+05:30 "DEBUG[otel-tracing,68368d8fc5f4102aed3a583a71288585,ed3a583a71288585,sub]" 16920 --- [otel-tracing] [ctor-http-nio-3] [68368d8fc5f4102aed3a583a71288585-ed3a583a71288585] s.w.r.r.m.a.RequestMappingHandlerMapping : [6973f811-1] Mapped to com.example.otel_tracing.resource.QuestionResource#findById(ObjectId)
2025-05-28T09:44:08.268+05:30 "DEBUG[otel-tracing,68368d8fc5f4102aed3a583a71288585,ed3a583a71288585,sub]" 16920 --- [otel-tracing] [ctor-http-nio-3] [68368d8fc5f4102aed3a583a71288585-ed3a583a71288585] o.s.d.m.core.ReactiveMongoTemplate       : findOne using query: { "id" : { "$oid" : "5d20cccab90a07e7190b2b9f"}} fields: Document{{}} for class: class com.example.otel_tracing.model.entity.Question in collection: question
2025-05-28T09:44:08.341+05:30 " INFO[otel-tracing,68368d8fc5f4102aed3a583a71288585,ed3a583a71288585,sub]" 16920 --- [otel-tracing] [ctor-http-nio-3] [68368d8fc5f4102aed3a583a71288585-ed3a583a71288585] c.e.o.resource.QuestionResource          : Finding question
2025-05-28T09:44:08.349+05:30 " INFO[otel-tracing,68368d8fc5f4102aed3a583a71288585,ed3a583a71288585,sub]" 16920 --- [otel-tracing] [ctor-http-nio-3] [68368d8fc5f4102aed3a583a71288585-ed3a583a71288585] c.e.o.service.QuestionService            : finding question with id: 5d20cccab90a07e7190b2b9f
2025-05-28T09:44:08.511+05:30 "DEBUG[otel-tracing,68368d8fc5f4102aed3a583a71288585,ed3a583a71288585,sub-service1]" 16920 --- [otel-tracing] [ctor-http-nio-3] [68368d8fc5f4102aed3a583a71288585-ed3a583a71288585] org.mongodb.driver.cluster               : Server selection started for operation with ID 5. Selector: ReadPreferenceServerSelector{readPreference=primary}, topology description: {type=REPLICA_SET, servers=[{address=localhost:27017, type=REPLICA_SET_PRIMARY, roundTripTime=155.1 ms, state=CONNECTED}]
2025-05-28T09:44:08.533+05:30 "DEBUG[otel-tracing,68368d8fc5f4102aed3a583a71288585,ed3a583a71288585,sub-service1]" 16920 --- [otel-tracing] [ctor-http-nio-3] [68368d8fc5f4102aed3a583a71288585-ed3a583a71288585] org.mongodb.driver.cluster               : Server selection succeeded for operation with ID 5. Selected server: localhost:27017. Selector: ReadPreferenceServerSelector{readPreference=primary}, topology description: {type=REPLICA_SET, servers=[{address=localhost:27017, type=REPLICA_SET_PRIMARY, roundTripTime=155.1 ms, state=CONNECTED}]
2025-05-28T09:44:08.550+05:30 "DEBUG[otel-tracing,68368d8fc5f4102aed3a583a71288585,ed3a583a71288585,sub-service1]" 16920 --- [otel-tracing] [ctor-http-nio-3] [68368d8fc5f4102aed3a583a71288585-ed3a583a71288585] org.mongodb.driver.connection            : Checkout started for connection to localhost:27017
2025-05-28T09:44:08.884+05:30 "DEBUG[otel-tracing,68368d8fc5f4102aed3a583a71288585,ed3a583a71288585,sub-service1]" 16920 --- [otel-tracing] [ntLoopGroup-3-3] [68368d8fc5f4102aed3a583a71288585-ed3a583a71288585] a.w.r.e.AbstractErrorWebExceptionHandler : [6973f811-1] Resolved [IllegalArgumentException: Question with id 5d20cccab90a07e7190b2b9f not found] for HTTP GET /api/quizzes/5d20cccab90a07e7190b2b9f
2025-05-28T09:44:08.887+05:30 "ERROR[otel-tracing,68368d8fc5f4102aed3a583a71288585,ed3a583a71288585,sub-service1]" 16920 --- [otel-tracing] [ntLoopGroup-3-3] [68368d8fc5f4102aed3a583a71288585-ed3a583a71288585] a.w.r.e.AbstractErrorWebExceptionHandler : [6973f811-1]  500 Server Error for HTTP GET "/api/quizzes/5d20cccab90a07e7190b2b9f"

What did you see instead?
A clear and concise description of what you saw instead.

What version and what artifacts are you using?
Artifacts:

Image

Version: (e.g., v0.4.0, 1eb551b, etc)
How did you reference these artifacts? (excerpt from your build.gradle, pom.xml, etc)

Environment
Compiler: oracle openjdk 17.0.12"
OS: Windows 11
Runtime (if different from JDK above): (e.g., "Oracle JRE 8u251")
OS (if different from OS compiled on): (e.g., "Windows Server 2019")

Additional context
In the logs we often see Trying to close scope which does not represent current context. Ignoring the call. Some modification done in the past to close the scope https://github.com/open-telemetry/opentelemetry-java/issues/5055

主要言語
Java
スター
2.5k
フォーク
1.1k
平均マージ
5日 11時間
マージ済み PR(30日)
41

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

open-telemetry/opentelemetry-java のほかの issue

open-telemetry/opentelemetry-java の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。