Skip to content

Fix MDC connector context not propagating to async querier thread#1613

Draft
Sangeet Mishra (sangeet259) wants to merge 1 commit into10.8.xfrom
fix-mdc-context-propagation-async-querier
Draft

Fix MDC connector context not propagating to async querier thread#1613
Sangeet Mishra (sangeet259) wants to merge 1 commit into10.8.xfrom
fix-mdc-context-propagation-async-querier

Conversation

@sangeet259
Copy link
Member

@sangeet259 Sangeet Mishra (sangeet259) commented Feb 27, 2026

Summary

  • Fixes regression in v10.8.5 where logs from the async query path (TableQuerierProcessor, TableQuerier, etc.) lost the [connector-name|task-N] prefix
  • Root cause: MDC is thread-local and wasn't propagated to the executor thread introduced by RecordQueue (PR CC-36403: Add record queue #1535)
  • Fix: capture MDC on the poll thread before async handoff, restore it on the executor thread

Verified with kafka-docker-playground

Ran a JDBC MySQL source connector with the fix applied. Logs from the async query thread now include the connector context:

After fix (v10.8.6-SNAPSHOT):

[2026-02-27 13:03:18,962] INFO [mysql-source|task-0|tableQuerierProcessor] Begin using SQL query: SELECT * FROM `mydb`.`team` WHERE ... (io.confluent.connect.jdbc.source.TableQuerier:182)

Before fix (v10.8.5):

[2026-02-27 04:01:07,958] INFO Begin using SQL query: Select * FROM testDB.dbo.customers2 WHERE ... (io.confluent.connect.jdbc.source.TableQuerier:186)

Test plan

  • New ConnectLogContextTest — MDC append, prefix fallback, nested contexts
  • New RecordQueueMdcTest — MDC propagation to executor, cleanup between executions, no-MDC fallback
  • Existing JdbcSourceTaskLifecycleTest passes
  • E2E verified with kafka-docker-playground MySQL source connector

@confluent-cla-assistant
Copy link

🎉 All Contributor License Agreements have been signed. Ready to merge.
Please push an empty commit if you would like to re-run the checks to verify CLA status for all contributors.

Since v10.8.5, logs from the async query path (TableQuerierProcessor,
TableQuerier, etc.) lost the [connector-name|task-N] prefix because
Kafka Connect's MDC is thread-local and was not propagated to the
background executor thread introduced by the RecordQueue architecture.

Capture MDC.getCopyOfContextMap() on the calling (poll) thread before
submitting to the executor, then restore it on the executor thread
before ConnectLogContext is created. This allows ConnectLogContext to
find and extend the connector.context MDC entry as intended. MDC is
cleared in a finally block to prevent leaking to pooled threads.
@airlock-confluentinc airlock-confluentinc bot force-pushed the fix-mdc-context-propagation-async-querier branch from fe4863d to 27a0b79 Compare February 27, 2026 11:15
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.

1 participant