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 38 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
@nvh0412
Copy link
Contributor Author

nvh0412 commented Feb 6, 2025

Hey @marcotc , do you know how to have these 2 envs?

Neither DATADOG_API_KEY nor DD_API_KEY is in your environment.

re: https://app.circleci.com/pipelines/github/DataDog/dd-trace-rb/19004/workflows/45a01e1d-a2ee-441b-8443-775013999391/jobs/665625

@nvh0412 nvh0412 requested a review from marcotc February 13, 2025 14:11
Copy link
Member

@marcotc marcotc left a comment

Choose a reason for hiding this comment

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

👋 @nvh0412, thank you so much for your patience.
We are in the middle of a CI migration, so the test runs are a bit confusing now.

One thing I noticed missing is the entry for karafka in the Rakefile, which means tests are not running in CI. It should be added here:

dd-trace-rb/Rakefile

Lines 222 to 269 in 30f6e21

# Datadog Tracing integrations
# REMINDER: If adding a new task here, make sure also add it to the `Matrixfile`
[
:action_cable,
:action_mailer,
:action_pack,
:action_view,
:active_model_serializers,
:active_record,
:active_support,
:aws,
:concurrent_ruby,
:dalli,
:delayed_job,
:elasticsearch,
:ethon,
:excon,
:faraday,
:grape,
:grpc,
:http,
:httpclient,
:httprb,
:kafka,
:lograge,
:mongodb,
:mysql2,
:opensearch,
:pg,
:presto,
:que,
:racecar,
:rack,
:rake,
:redis,
:resque,
:roda,
:rest_client,
:semantic_logger,
:sequel,
:shoryuken,
:sidekiq,
:sinatra,
:sneakers,
:stripe,
:sucker_punch,
:suite,
:trilogy

As well as in the Matrixfile, which you probably copy the current entry for kafka to use for your tests:

dd-trace-rb/Matrixfile

Lines 109 to 111 in 30f6e21

'kafka' => {
'activesupport' => '✅ 2.5 / ✅ 2.6 / ✅ 2.7 / ✅ 3.0 / ✅ 3.1 / ✅ 3.2 / ✅ 3.3 / ✅ 3.4 / ✅ jruby'
},

@nvh0412
Copy link
Contributor Author

nvh0412 commented Feb 25, 2025

Sacrifice for the linting gods ☠️

This commit msg actually made my day

@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.

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
6 participants