Conversation
vpellan
commented
Jan 5, 2026
By the time that `Karafka::App#initialized!` is called,
`Karafka.producer` was already initialized.
On top of that, there's really nowhere we can hook in the Karafka
initialization where we can be sure that `Karafka.producer` wasn't yet
initiaized - that's because the Karafka initialization is NOT
necessarily tied to the WaterDrop initialization. For instance, the
following is a possible scenario:
```
$producer = WaterDrop::Producer.new { ... }
Datadog.configure do |c|
c.tracing.instrument :karafka
end
# note that the producer was initialized before the Karafka app (and in
# this case, even before datadog was configured)
Karafka::App.setup do |c|
c.producer = $producer
end
```
So instead of trying to hook somewhere before `Karafka.producer` is
initialized, let's simply listen to a Karafka after-initialization event
and append our middleware to the producer when that event is triggered.
|
👋 Hey @DataDog/ruby-guild, please fill "Change log entry" section in the pull request description. If changes need to be present in CHANGELOG.md you can state it this way **Change log entry**
Yes. A brief summary to be placed into the CHANGELOG.md(possible answers Yes/Yep/Yeah) Or you can opt out like that **Change log entry**
None.(possible answers No/Nope/None) Visited at: 2026-01-05 10:38:29 UTC |
|
✅ Tests 🎉 All green!❄️ No new flaky tests detected 🎯 Code Coverage 🔗 Commit SHA: ba4f861 | Docs | Datadog PR Page | Was this helpful? Give us feedback! |
Typing analysisNote: Ignored files are excluded from the next sections. Untyped methodsThis PR introduces 1 partially typed method. It decreases the percentage of typed methods from 56.93% to 56.9% (-0.03%). Partially typed methods (+1-0)❌ Introduced:If you believe a method or an attribute is rightfully untyped or partially typed, you can add |