Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Karafka integration #4147

Open
wants to merge 48 commits into
base: master
Choose a base branch
from
Open

Conversation

nvh0412
Copy link
Contributor

@nvh0412 nvh0412 commented Nov 22, 2024

What does this PR do?

Fixed #1660

In this PR, we introduce the Kafka integration for the Karafka gem. Which includes:

  1. Distributed tracing by utilizing message.metadata.headers
  2. Traces for worker.process and each message executor inside the batch, so we can link them to the origin trace if the distributed tracing is on

Motivation:

We’re integrating Karafka to implement proper distributed tracing in our system with Datadog, as it lacks an official integration. This integration will also enable distributed tracing if the message headers include distributed tracing data.

Distributed tracing will help us create a proper service map, connecting Kafka producers and consumers.

Change log entry

Yes. Add Karafka integration for distributed tracing.

(Added by @ivoanjo)

Additional Notes:

How to test the change?

Screenshot 2024-11-22 at 3 43 09 PM

@github-actions github-actions bot added integrations Involves tracing integrations tracing labels Nov 22, 2024
@nvh0412 nvh0412 marked this pull request as ready for review November 22, 2024 06:07
@nvh0412 nvh0412 requested review from a team as code owners November 22, 2024 06:07
@drichards-87
Copy link

Created a Jira card for Docs Team editorial review.

@drichards-87 drichards-87 added the editorial review Waiting for a review from the docs team label Nov 22, 2024
@codecov-commenter
Copy link

codecov-commenter commented Nov 22, 2024

Codecov Report

Attention: Patch coverage is 80.58252% with 20 lines in your changes missing coverage. Please review.

Project coverage is 97.75%. Comparing base (ce4393e) to head (27e5711).
Report is 41 commits behind head on master.

Files with missing lines Patch % Lines
lib/datadog/tracing/contrib/karafka/patcher.rb 51.61% 15 Missing ⚠️
lib/datadog/tracing/contrib/karafka.rb 80.00% 4 Missing ⚠️
lib/datadog/tracing/contrib/karafka/integration.rb 95.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4147      +/-   ##
==========================================
- Coverage   97.78%   97.75%   -0.03%     
==========================================
  Files        1353     1358       +5     
  Lines       81817    81920     +103     
  Branches     4145     4150       +5     
==========================================
+ Hits        80001    80081      +80     
- Misses       1816     1839      +23     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mensfeld
Copy link

FYI feel free to ping me once remarks are done. I will be happy to help and maybe in the future retire my own instrumentation in favour of the DD one ;)

Copy link

@drichards-87 drichards-87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a couple of very small suggestions from Docs and approved the PR.

Use Tracing.trace wrapper to add consumer trace
Use Instrumentation::Monitor to instrument and have a proper trace wrapper
@TonyCTHsu
Copy link
Contributor

Sorry, the pull request is currently blocked and I am working on

  1. With Datadog's Github admin and security team to configure workflows to run properly in order to acquire the required status for merging pull requests.
  2. Discussion with the maintainer about the minimum version to target for support.

@TonyCTHsu
Copy link
Contributor

TonyCTHsu commented Mar 12, 2025

👋 @marco I have prepared a branch tmp/karafka-tracing to circumvent the security measures preventing secret access.

Basically, rebase tmp/karafka-tracing onto the branch of (karafka-tracing) of this pull request and push to trigger the CI. This will trigger our Gitlab pipeline, unit tests and system tests to acquire the required status check to be merged.

Currently, the unit tests are failing because of the minimum version defined subject to test. Static analysis is failing with rubocop and steep .

I did cherrypicked the changes containing autogenerated gemfiles and lockfiles. You might do the same in order to change your dependencies for testing.

@taltcher
Copy link

Hi - is there an ETA when this feature could be released? this is something we are really waiting for :-)

* master: (209 commits)
  Fix method override warning in profiler (DataDog#4549)
  Fix warnings in DI and tracing generated with -w (DataDog#4547)
  Add telemetry to tracking middleware patcher
  Improve devise instrumentation
  Add signature for devise tracking middleware
  Fix gateway push of identity.set_user
  Add prefix in ID extraction for Hash-like objects
  Push AppSec identity event into gateway
  Add debug logging into patches and middleware
  Switch into update system-tests
  Change login success/failure by set usr.login
  Add multi-user support in signin/signup tracking
  Add libddwaf into user tracking
  Adjust AppSec::Anonymizer interface
  Refactor Devise patches and middleware
  Add Devise::DataExtractor to extract id and login
  Update auto_user_instrumentation configuration
  Set AppSec collection mode tag in identity kit
  Add tests for SDK and automated instrumentation
  Add authenticated user tracking implementation
  ...
def patch
require_relative 'monitor'

::Karafka::App.config.monitor = Monitor.new
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be replacing another monitor added by the application?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@p-datadog not really: https://karafka.io/docs/Monitoring-and-Logging/#monitor-wrapping-and-replacement

both are supported and in this case there has to be a custom monitor to handle the tracing as far as I understand (karafka author here)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mensfeld Thank you for the response. Can you clarify what happens when the monitor is replaced - is the original monitor going to continue receiving events?

I made a small change that patches the Karafka Monitor to invoke dd-trace-rb instrumentation which should work with any installed monitor. What is your opininion of this change?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@p-datadog when monitor is replaced it is replaced. You can use a monitor that wraps a different one and document it. 98-99% of people stick with the default one so it is in my opinion an edge case.

@p-datadog
Copy link
Member

karafka 2.0.41 (min version we are testing) uses Concurrent::Array without declaring a dependency on or requiring concurrent-ruby, which karafka-core 2.3.0 (that is being used currently by CI) does also not use in any way. I think the solution here is to pin to and older karafka-core version for karafka 2.0.41.

@mensfeld
Copy link

mensfeld commented Apr 1, 2025

karafka 2.0.41 (min version we are testing) uses Concurrent::Array without declaring a dependency on or requiring concurrent-ruby, which karafka-core 2.3.0 (that is being used currently by CI) does also not use in any way. I think the solution here is to pin to and older karafka-core version for karafka 2.0.41.

2.0.41 is totally EOL and making any decisions based on it does not make any sense: https://karafka.io/docs/Versions-Lifecycle-and-EOL/#karafka-components-support

this dependency reference was fixed later on. Concurrent ruby was completely removed in 2.3.

@p-datadog
Copy link
Member

What minimum karafka version would you suggest we support? 2.3?

@mensfeld
Copy link

mensfeld commented Apr 1, 2025

Yes. 2.3 is already EOL but it has all the dependency issues solved and a stable API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
editorial review Waiting for a review from the docs team integrations Involves tracing integrations tracing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Distributed tracing support through Kafka integration
9 participants