-
Notifications
You must be signed in to change notification settings - Fork 35
Fix Tuple IndexError issue in Kafka instrumentations. #816
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
Conversation
|
❌ @pvital the
📝 What should I do to fix it?All proposed commits should include a sign-off in their messages, ideally at the end. ❔ Why it is requiredThe Developer Certificate of Origin (DCO) is a lightweight way for contributors to certify that they wrote or otherwise have the right to submit the code they are contributing to the project. Here is the full text of the DCO, reformatted for readability:
Contributors sign-off that they adhere to these requirements by adding a Git even has a |
3037546 to
3234567
Compare
Fixed IndexError in `confluent_kafka_python.py` by handling both positional and keyword arguments for the topic parameter in the `trace_kafka_produce` function. The issue occurred when the topic was passed as a keyword argument, resulting in an empty args tuple and causing an IndexError when trying to access `args[0]`. The solution: 1. Modified the `trace_kafka_produce` function to get the topic from either `args` or `kwargs` 2. Added safety checks to handle edge cases 3. Added two new test methods to verify the fix works with different argument patterns: - `test_trace_confluent_kafka_produce_with_keyword_topic` - `test_trace_confluent_kafka_produce_with_keyword_args` This fix ensures that the Kafka instrumentation works correctly regardless of how the `produce` method is called, improving the robustness of the Python sensor. Signed-off-by: Paulo Vital <paulo.vital@ibm.com>
Fixed potential IndexError in `kafka_python.py` by handling both positional and keyword arguments for the topic parameter in the `trace_kafka_send` function. The issue is similar to the one fixed in `confluent_kafka_python.py`, where an IndexError could occur when the topic was passed as a keyword argument, resulting in an empty `args` tuple. The solution: 1. Modified the `trace_kafka_send` function to get the topic from either `args` or `kwargs` 2. Added safety checks to handle edge cases 3. Added two new test methods to verify the fix works with different argument patterns: - `test_trace_kafka_python_send_with_keyword_topic` - `test_trace_kafka_python_send_with_keyword_args` This fix ensures that the Kafka instrumentation works correctly regardless of how the `send` method is called, improving the robustness of the Python sensor. Signed-off-by: Paulo Vital <paulo.vital@ibm.com>
3234567 to
ee1db84
Compare
|
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.
LGTM



This PR fixes a Tuple IndexError in both
confluent_kafka_python.pyandkafka_python.pyimplementations.It handles both positional and keyword arguments for the
topicparameter in the respectivetrace_kafka_produceandtrace_kafka_sendfunctions. The issue occurred when thetopicwas passed as a keyword argument, resulting in an emptyargstuple and causing an IndexError when trying to accessargs[0].confluent_kafka_python.py:
trace_kafka_producefunction to handle both positional and keyword arguments for the topic parameterkafka_python.py:
trace_kafka_sendfunctionBoth fixes ensure that the Kafka instrumentation works correctly regardless of how the methods are called, improving the robustness of the Python sensor. The changes are minimal and focused on the specific issue, maintaining compatibility with existing code.
These changes should prevent the IndexError from occurring in the future, even when users pass the topic as a keyword argument instead of a positional argument.