Skip to content

fix: preserve Kafka telemetry spans during concurrent processing - #119

Merged
lesnik512 merged 3 commits into
mainfrom
fix/concurrent-kafka-telemetry
Nov 6, 2026
Merged

lesnik512 merged 3 commits into
mainfrom
fix/concurrent-kafka-telemetry

Conversation

@lesnik512

@lesnik512 lesnik512 commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Summary

FastStream can run telemetry cleanup after concurrent dispatch returns, before the background task starts or finishes. This can leave the Kafka consumer process span unexported or end it too early.

During FastStream application startup, initialize_concurrent_processing() automatically adapts existing FastStream KafkaTelemetryMiddleware registrations that follow KafkaConcurrentProcessingMiddleware. The adapter preserves middleware order and telemetry settings, and ends the process span after both consume execution and middleware cleanup finish.

Downstream services using this setup only need to upgrade faststream-concurrent-aiokafka. They keep their existing middleware registrations and OpenTelemetry dependencies. The base package still works without OpenTelemetry.

Validation

  • Live Kafka telemetry tests passed on unpatched FastStream 0.7.1 and 0.7.8, covering successful processing, handler failure, cancellation, inline processing, router registration, and repeated initialization.
  • A clean base installation initialized successfully without OpenTelemetry.
  • Full suite passed with 262 tests and 100% coverage. Ruff and ty checks passed.

@lesnik512
lesnik512 merged commit 88342a1 into main Nov 6, 2026
13 checks passed
@lesnik512
lesnik512 deleted the fix/concurrent-kafka-telemetry branch November 6, 2026 08:53
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