Skip to content

kafka instrumentation native support for apm-python agent. #964

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

Closed
wants to merge 1 commit into from

Conversation

Rohit-dot-KumarAM
Copy link
Contributor

@Rohit-dot-KumarAM Rohit-dot-KumarAM commented Oct 30, 2020

Add instrumentation for KafkaProducer.send method and KafkaConsumer.next method, while running inside framework.

How it works:

-> Considering send is being called from a transaction say Django transaction, it will capture a span out of it.
-> Then in elasticapm/instrumentation/packages/kafka.py for send 1 extra header called trace is being added .
-> this "trace" header will contain the tp-string with the span-id.
-> at the receiver's side while instrumenting "next" the "trace" header will be fetched.
-> If there is a running transaction which is not of type "messaging" then will create span for "next".
-> else if there is a transaction with type messaging we will close the transaction considering that the current transaction was started from previous "next" call.
-> else there is no current transaction running then we will create one and make it child of the send-span, making use of "trace" header which contains our tpstring.

Supported base Technologies:

================
-> Django 1.8.19
-> flask 1.1.2
-> celery 3.1.26.post2 (considering only kafka-send inside a celery task. Not consume.)

Related issues

closes #853

@beniwohli
Copy link
Contributor

@Rohit-dot-KumarAM thanks for your contribution. We'll have a look shortly. In the mean time, can I ask you to stop opening, closing and opening more pull requests? This is causing a lot of notifications on our end :)

@apmmachine
Copy link
Contributor

apmmachine commented Oct 30, 2020

❕ Build Aborted

The PR is not allowed to run in the CI yet

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts

Expand to view the summary

Build stats

  • Build Cause: Branch indexing

  • Reason: The PR is not allowed to run in the CI yet

  • Start Time: 2021-03-01T16:27:25.907+0000

  • Duration: 7 min 51 sec

  • Commit: a07fa79

Trends 🧪

Image of Build Times

Steps errors 2

Expand to view the steps failures

Load a resource file from a shared library
  • Took 0 min 0 sec . View more details on here
  • Description: approval-list/elastic/apm-agent-python.yml
Error signal
  • Took 0 min 0 sec . View more details on here
  • Description: githubPrCheckApproved: The PR is not allowed to run in the CI yet. (Only users with write permissions can do so.)

Log output

Expand to view the last 100 lines of log output

[2021-03-01T16:33:51.085Z]  > git config --get remote.origin.url # timeout=10
[2021-03-01T16:33:51.092Z] using GIT_SSH to set credentials GitHub user @elasticmachine SSH key
[2021-03-01T16:33:51.095Z]  > git merge c58b21329829b7a8cfcef276e0cac2e30cfede8f # timeout=10
[2021-03-01T16:33:51.166Z]  > git rev-parse HEAD^{commit} # timeout=10
[2021-03-01T16:33:51.180Z]  > git config core.sparsecheckout # timeout=10
[2021-03-01T16:33:51.183Z]  > git checkout -f 12a2866d197f0db4b5dc808b6b94d82171ffe30b # timeout=15
[2021-03-01T16:33:54.706Z] Commit message: "Merge commit 'c58b21329829b7a8cfcef276e0cac2e30cfede8f' into HEAD"
[2021-03-01T16:33:54.715Z] First time build. Skipping changelog.
[2021-03-01T16:33:54.715Z] Cleaning workspace
[2021-03-01T16:33:55.353Z] Masking supported pattern matches of $JOB_GCS_BUCKET or $NOTIFY_TO
[2021-03-01T16:33:55.398Z] The timestamps step is unnecessary when timestamps are enabled for all Pipeline builds.
[2021-03-01T16:33:55.463Z] Timeout set to expire in 1 hr 0 min
[2021-03-01T16:33:55.605Z] [INFO] Number of builds to be searched 10
[2021-03-01T16:33:55.779Z] [INFO] 'shallow' is forced to be disabled when running on PullRequests
[2021-03-01T16:33:55.793Z] Running in /var/lib/jenkins/workspace/thon_apm-agent-python-mbp_PR-964/src/github.com/elastic/apm-agent-python
[2021-03-01T16:33:54.710Z]  > git rev-list --no-walk d968bd3722d206f8234dece89a8dba89246ced1e # timeout=10
[2021-03-01T16:33:54.717Z]  > git rev-parse --verify HEAD # timeout=10
[2021-03-01T16:33:54.721Z] Resetting working tree
[2021-03-01T16:33:54.721Z]  > git reset --hard # timeout=10
[2021-03-01T16:33:54.751Z]  > git clean -fdx # timeout=10
[2021-03-01T16:33:55.812Z] [INFO] gitCheckout: Checkout SCM PR-964 with default customisation from the Item.
[2021-03-01T16:33:55.839Z] [INFO] Override default checkout
[2021-03-01T16:33:55.883Z] Sleeping for 10 sec
[2021-03-01T16:34:05.904Z] The recommended git tool is: git
[2021-03-01T16:34:06.019Z] using credential f6c7695a-671e-4f4f-a331-acdce44ff9ba
[2021-03-01T16:34:06.040Z] Wiping out workspace first.
[2021-03-01T16:34:06.048Z] Cloning the remote Git repository
[2021-03-01T16:34:06.048Z] Using shallow clone with depth 3
[2021-03-01T16:34:06.048Z] Avoid fetching tags
[2021-03-01T16:34:06.063Z] Cloning repository git@github.com:elastic/apm-agent-python.git
[2021-03-01T16:34:06.093Z]  > git init /var/lib/jenkins/workspace/thon_apm-agent-python-mbp_PR-964/src/github.com/elastic/apm-agent-python # timeout=10
[2021-03-01T16:34:06.101Z] Fetching upstream changes from git@github.com:elastic/apm-agent-python.git
[2021-03-01T16:34:06.101Z]  > git --version # timeout=10
[2021-03-01T16:34:06.107Z]  > git --version # 'git version 2.17.1'
[2021-03-01T16:34:06.107Z] using GIT_SSH to set credentials GitHub user @elasticmachine SSH key
[2021-03-01T16:34:06.111Z]  > git fetch --no-tags --progress -- git@github.com:elastic/apm-agent-python.git +refs/heads/*:refs/remotes/origin/* # timeout=15
[2021-03-01T16:34:07.322Z] Cleaning workspace
[2021-03-01T16:34:07.335Z] Using shallow fetch with depth 3
[2021-03-01T16:34:07.335Z] Pruning obsolete local branches
[2021-03-01T16:34:07.307Z]  > git config remote.origin.url git@github.com:elastic/apm-agent-python.git # timeout=10
[2021-03-01T16:34:07.310Z]  > git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
[2021-03-01T16:34:07.318Z]  > git config remote.origin.url git@github.com:elastic/apm-agent-python.git # timeout=10
[2021-03-01T16:34:07.325Z]  > git rev-parse --verify HEAD # timeout=10
[2021-03-01T16:34:07.328Z] No valid HEAD. Skipping the resetting
[2021-03-01T16:34:07.329Z]  > git clean -fdx # timeout=10
[2021-03-01T16:34:07.338Z] Fetching upstream changes from git@github.com:elastic/apm-agent-python.git
[2021-03-01T16:34:07.338Z] using GIT_SSH to set credentials GitHub user @elasticmachine SSH key
[2021-03-01T16:34:07.345Z]  > git fetch --no-tags --progress --prune -- git@github.com:elastic/apm-agent-python.git +refs/pull/964/head:refs/remotes/origin/PR-964 +refs/heads/master:refs/remotes/origin/master # timeout=15
[2021-03-01T16:34:07.978Z] Merging remotes/origin/master commit c58b21329829b7a8cfcef276e0cac2e30cfede8f into PR head commit a07fa79d9fd659464b575c9f4620c1fcd8edbf51
[2021-03-01T16:34:08.105Z] Merge succeeded, producing 14e87656c52b9358ca0895c300097ec98185fd37
[2021-03-01T16:34:08.106Z] Checking out Revision 14e87656c52b9358ca0895c300097ec98185fd37 (PR-964)
[2021-03-01T16:34:08.165Z] Commit message: "Merge commit 'c58b21329829b7a8cfcef276e0cac2e30cfede8f' into HEAD"
[2021-03-01T16:34:08.178Z] First time build. Skipping changelog.
[2021-03-01T16:34:08.178Z] Cleaning workspace
[2021-03-01T16:34:07.981Z]  > git config core.sparsecheckout # timeout=10
[2021-03-01T16:34:07.984Z]  > git checkout -f a07fa79d9fd659464b575c9f4620c1fcd8edbf51 # timeout=15
[2021-03-01T16:34:08.031Z]  > git remote # timeout=10
[2021-03-01T16:34:08.034Z]  > git config --get remote.origin.url # timeout=10
[2021-03-01T16:34:08.038Z] using GIT_SSH to set credentials GitHub user @elasticmachine SSH key
[2021-03-01T16:34:08.041Z]  > git merge c58b21329829b7a8cfcef276e0cac2e30cfede8f # timeout=10
[2021-03-01T16:34:08.101Z]  > git rev-parse HEAD^{commit} # timeout=10
[2021-03-01T16:34:08.108Z]  > git config core.sparsecheckout # timeout=10
[2021-03-01T16:34:08.118Z]  > git checkout -f 14e87656c52b9358ca0895c300097ec98185fd37 # timeout=15
[2021-03-01T16:34:08.168Z]  > git rev-list --no-walk d968bd3722d206f8234dece89a8dba89246ced1e # timeout=10
[2021-03-01T16:34:08.181Z]  > git rev-parse --verify HEAD # timeout=10
[2021-03-01T16:34:08.184Z] Resetting working tree
[2021-03-01T16:34:08.184Z]  > git reset --hard # timeout=10
[2021-03-01T16:34:08.208Z]  > git clean -fdx # timeout=10
[2021-03-01T16:34:09.089Z] Masking supported pattern matches of $GIT_USERNAME or $GIT_PASSWORD
[2021-03-01T16:34:09.779Z] + git fetch https://****:****@github.com/elastic/apm-agent-python.git +refs/pull/*/head:refs/remotes/origin/pr/*
[2021-03-01T16:34:11.207Z] Running in /var/lib/jenkins/workspace/thon_apm-agent-python-mbp_PR-964/src/github.com/elastic/apm-agent-python/.git
[2021-03-01T16:34:11.260Z] Archiving artifacts
[2021-03-01T16:34:11.850Z] + git rev-parse HEAD
[2021-03-01T16:34:12.170Z] + git rev-parse HEAD
[2021-03-01T16:34:12.468Z] + git rev-parse origin/pr/964
[2021-03-01T16:34:12.509Z] [INFO] githubEnv: Found Git Build Cause: pr
[2021-03-01T16:34:12.828Z] Masking supported pattern matches of $GITHUB_TOKEN
[2021-03-01T16:34:13.871Z] [INFO] githubPrCheckApproved: Title: kafka instrumentation native support for apm-python agent. - User: Rohit-dot-KumarAM - Author Association: FIRST_TIME_CONTRIBUTOR
[2021-03-01T16:34:14.161Z] ERROR: githubPrCheckApproved: The PR is not allowed to run in the CI yet
[2021-03-01T16:34:14.161Z] ERROR: githubPrCheckApproved: The PR is not allowed to run in the CI yet. (Only users with write permissions can do so.)
[2021-03-01T16:34:14.203Z] [INFO] Let's stop build #38. The PR is not allowed to run in the CI yet
[2021-03-01T16:34:14.222Z] Sleeping for 5 sec
[2021-03-01T16:34:15.183Z] Stage "Sanity checks" skipped due to earlier failure(s)
[2021-03-01T16:34:15.219Z] Stage "Test" skipped due to earlier failure(s)
[2021-03-01T16:34:15.258Z] Stage "Building packages" skipped due to earlier failure(s)
[2021-03-01T16:34:15.294Z] Stage "Integration Tests" skipped due to earlier failure(s)
[2021-03-01T16:34:15.326Z] Stage "Benchmarks" skipped due to earlier failure(s)
[2021-03-01T16:34:15.391Z] Stage "Prepare Release" skipped due to earlier failure(s)
[2021-03-01T16:34:15.407Z] Stage "Prepare Release" skipped due to earlier failure(s)
[2021-03-01T16:34:15.439Z] Stage "Prepare Release" skipped due to earlier failure(s)
[2021-03-01T16:34:15.470Z] Stage "Prepare Release" skipped due to earlier failure(s)
[2021-03-01T16:34:15.865Z] Running on Jenkins in /var/lib/jenkins/workspace/thon_apm-agent-python-mbp_PR-964
[2021-03-01T16:34:16.137Z] [INFO] getVaultSecret: Getting secrets
[2021-03-01T16:34:16.419Z] Masking supported pattern matches of $VAULT_ADDR or $VAULT_ROLE_ID or $VAULT_SECRET_ID
[2021-03-01T16:34:17.162Z] + chmod 755 generate-build-data.sh
[2021-03-01T16:34:17.162Z] + ./generate-build-data.sh https://apm-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/apm-agent-python/apm-agent-python-mbp/PR-964/ https://apm-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/apm-agent-python/apm-agent-python-mbp/PR-964/runs/38 ABORTED 410990
[2021-03-01T16:34:17.412Z] INFO: curl https://apm-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/apm-agent-python/apm-agent-python-mbp/PR-964/runs/38/steps/?limit=10000 -o steps-info.json
[2021-03-01T16:34:18.323Z] INFO: curl https://apm-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/apm-agent-python/apm-agent-python-mbp/PR-964/runs/38/tests/?status=FAILED -o tests-errors.json
[2021-03-01T16:34:18.323Z] Retry 1/3 exited 22, retrying in 1 seconds...
[2021-03-01T16:34:19.234Z] Retry 2/3 exited 22, retrying in 2 seconds...

@Rohit-dot-KumarAM
Copy link
Contributor Author

@Rohit-dot-KumarAM thanks for your contribution. We'll have a look shortly. In the mean time, can I ask you to stop opening, closing and opening more pull requests? This is causing a lot of notifications on our end :)

Extremely apologize for multiple pull requests, this happened because of my confusion in github. Thanks for your time.

@Rohit-dot-KumarAM
Copy link
Contributor Author

@Rohit-dot-KumarAM thanks for your contribution. We'll have a look shortly. In the mean time, can I ask you to stop opening, closing and opening more pull requests? This is causing a lot of notifications on our end :)

Extremely apologize for multiple pull requests, this happened because of my confusion in github. Thanks for your time.

@basepi
Copy link
Contributor

basepi commented Jan 11, 2021

Sorry for the delay here, @Rohit-dot-KumarAM. This is a big change and we're working to make sure we align with other agents on messaging libraries -- in fact, we have an open spec PR here: elastic/apm#380

That, coupled with the holidays and our upcoming 6.0 release has meant this has taken a back seat. But we haven't forgotten about it!

@basepi basepi self-assigned this Feb 10, 2021
Copy link
Contributor

@basepi basepi left a comment

Choose a reason for hiding this comment

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

@Rohit-dot-KumarAM The spec is now merged: https://github.com/elastic/apm/blob/master/specs/agents/tracing-instrumentation-messaging.md

Can you please take a look at it and revise your PR based on the naming conventions and context information laid out in that doc?

Additionally, it looks like you're not using the correct header names as laid out in this spec: https://github.com/elastic/apm/blob/master/specs/agents/tracing-distributed-tracing.md

For example, you are using trace instead of traceparent for the header name.

As an aside, I don't particularly like the situation with get_client() -- I'm working on a more generalized solution for making the client more available so that you don't have to check each framework in turn. I'll post here when it's ready and you can use that instead.

Note: if you don't have time to do the above changes, then when I find some time I can go through and modify your PR myself.

@basepi basepi removed their assignment Mar 11, 2021
@aaccioly
Copy link

Hello @Rohit-dot-KumarAM, thanks a million for your contribution. Is there anything that I can do to help to get this merged? I would love to have automatic instrumentation for Kafka.

@AlexanderWert AlexanderWert added the community Issues opened by the community label Oct 7, 2021
@AlexanderWert AlexanderWert added this to the 8.0 milestone Oct 7, 2021
@Rohit-dot-KumarAM
Copy link
Contributor Author

Hello @Rohit-dot-KumarAM, thanks a million for your contribution. Is there anything that I can do to help to get this merged? I would love to have automatic instrumentation for Kafka.

Hi I did this long back and after that some of the spec changes added, can you help me to align with the spec and also.
@basepi made the makeclient globally available.

I may ruin the entire work due to my limited understanding in instrumentation.

@basepi
Copy link
Contributor

basepi commented Nov 9, 2021

I may ruin the entire work due to my limited understanding in instrumentation.

@Rohit-dot-KumarAM No worries. I have this on my list to push over the finish line in the coming months. We definitely want Kafka support, and we appreciate your effort here.

I may end up making a new PR with @Rohit-dot-KumarAM's work plus some spec fixes and other work. For those with interest in Kafka support, make sure you're watching #853 as well.

@AlexanderWert AlexanderWert modified the milestones: 8.0, 8.1 Dec 1, 2021
@basepi basepi removed this from the 8.1 milestone Mar 7, 2022
beniwohli added a commit to beniwohli/apm-agent-python that referenced this pull request May 23, 2022
Changes include:
 * automatically create transactions when looping over results
 * instrument KadkaConsumer.poll
 * add binary TraceParent handling
 * added support for span links
 * add tests
beniwohli added a commit to beniwohli/apm-agent-python that referenced this pull request May 23, 2022
Changes include:
 * automatically create transactions when looping over results
 * instrument KadkaConsumer.poll
 * add binary TraceParent handling
 * added support for span links
 * add tests
@beniwohli beniwohli mentioned this pull request May 23, 2022
@beniwohli
Copy link
Contributor

Closing in favor of #1555, which is based on this PR.

@beniwohli beniwohli closed this May 23, 2022
beniwohli added a commit that referenced this pull request May 24, 2022
* kafka instrumentation for apm-python agent.

* Adapt #964 for Kafka/messaging support

Changes include:
 * automatically create transactions when looping over results
 * instrument KadkaConsumer.poll
 * add binary TraceParent handling
 * added support for span links
 * add tests

* create/delete topics explicitly in a pytest fixture

* add changelog entry

Co-authored-by: Rohit-dot-KumarAM <rohit.kumaram@maplelabs.com>
@rohitam
Copy link

rohitam commented Nov 30, 2022

Successor Now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
agent-python community Issues opened by the community
7 participants