-
Notifications
You must be signed in to change notification settings - Fork 739
Utilize instruments-any in fastapi, kafka, and psycopg2 #3612
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
Draft
jeremydvoss
wants to merge
11
commits into
open-telemetry:main
Choose a base branch
from
jeremydvoss:instruments-either-use
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
bf72030
Utilize instruments_either in fastapi, kafka, and psycopg2
jeremydvoss 8e2ece4
changelog entries
jeremydvoss a9bd19c
Add instruments_either to bootstrap
jeremydvoss efd2e33
generate bootstrap code
jeremydvoss d38dd3c
generate readme fix
jeremydvoss 4048c8e
instruments-any and _instruments_any
jeremydvoss 19390ed
sync
jeremydvoss 0890970
uv.lock
jeremydvoss 30e6b48
uv.lock
jeremydvoss de08183
gen
jeremydvoss 90e9a7b
remove upload dates from uv.lock
jeremydvoss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the python side is how we do the in code dependency checks.
The _instruments* are used by this function here
https://github.com/open-telemetry/opentelemetry-python-contrib/blob/main/instrumentation/opentelemetry-instrumentation-kafka-python/src/opentelemetry/instrumentation/kafka/__init__.py#L108-L126
Which is then loaded here. https://github.com/open-telemetry/opentelemetry-python-contrib/blob/main/opentelemetry-instrumentation/src/opentelemetry/instrumentation/instrumentor.py#L88
During instrumentation time.
This change doesn't make sense to me as the logic for "either" is already inside the instrumentation_dependencies function. (https://github.com/open-telemetry/opentelemetry-python-contrib/blob/main/instrumentation/opentelemetry-instrumentation-kafka-python/src/opentelemetry/instrumentation/kafka/__init__.py#L108-L126)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That get_dependencies method can be overwritten to achieve your desired result, though it's not its intended purpose. The problem is really that overriding it does not solve the scenario where we want to do dependency check before we load the instrumentation. That scenario is fundamental to cloud Auto instrumentation and it was the approach autoinsteumentation used prior to your change. This PR solves the problem from the ground up. Instrumentations no longer need to overwrite methods to provide hacky solutions for narrow scenarios. Now the SDK itself supports either/or scenarios -- whether the check happens before or after loading the instrumentation. In other words, with this change, partial solutions such as those implemented by Kafka and psycopg2 aren't required anymore. However they can still exist. That's why I haven't changed those method overwrites in the pr. This way it shouldn't break existing apps that already adopted that pattern. Let me know if that clears it up. We can sync tomorrow too or discuss in sig.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I was mostly reacting to the comment which made it seem like this was still an open question. I do like that we may not need to use the instrumentation_dependencies method anymore but I am worried that its still there at all. Is it possible we could only do the toml method?
I do understand the need for handling more complicated scenarios, (a couple ifs and some ands etc), but in a case like this, the proposed solution in #3610 doesn't work either.
An exact example would be
This logic gets super complicated super quickly which is why I went towards doing it in python via the instrumentation_dependencies method but I also totally get that we may not need any more complexity than and's and or's and we can maybe refactor more fully if when we ever need this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, i think I understand. Yeah this method works for all current cases, but I see what you mean about possible "branching" scenarios. This method does not have infinite customizability. I agree that a refactor like that would be a much bigger subject. My focus now is fixing all existing scenarios cleanly without the need for custom overwrites or hacks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Just a thought for what a long term solution that could support infinite branching might look like: a json-like "instruments" value that includes the logic within and the sdk merely executes.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missed that you were responding to my inline comment. I understand it but just forgot to remove my comment lol.