MDC Context lost its associated to individual thread

Aperta
#7,376 10 commenti 1 reazione 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 3 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
java, mongodb, spring

Direzione di ricerca

Inizia con il POC collegato, avvia l’applicazione e chiama l’endpoint quiz documentato per riprodurre il valore di baggage mancante. Leggi i log relativi al WebFilter reattivo, all’operazione MongoDB e al gestore degli errori, quindi esamina la issue correlata 5055. Il lavoro è completato quando il valore di baggage aggiornato rimane nei log delle eccezioni e degli errori senza l’avviso di chiusura dello scope.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
Java
Stelle
2.5k
Fork
1.1k
Merge medio
5g 11h
PR unite (30g)
41

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di open-telemetry/opentelemetry-java

Tutte le issue di open-telemetry/opentelemetry-java

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.