Skip to content

fix(sagemaker): Improve _handle_call to safely parse JSON, CSV, and byte inputs #2963

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

Merged
merged 5 commits into from
Jun 24, 2025

Conversation

swa-kn
Copy link
Contributor

@swa-kn swa-kn commented May 28, 2025

  • I have added tests that cover my changes.
  • If adding a new instrumentation or changing an existing one, I've added screenshots from some observability platform showing the change. The change done is to Improve _handle_call to safely parse JSON, CSV, and byte inputs in Sagemaker tracing to make the tags visible.
image
  • PR name follows conventional commits format: feat(instrumentation): ... or fix(instrumentation): ....
  • (If applicable) I have updated the documentation accordingly.

Important

Improve _handle_call in Sagemaker tracing to safely parse JSON, CSV, and byte inputs using _try_parse_json.

  • Behavior:
    • Improve _handle_call in __init__.py to safely parse JSON, CSV, and byte inputs.
    • Introduce _try_parse_json to decode JSON from strings or bytes, fallback to raw value on failure.
    • Apply _try_parse_json to request_body and response_body in _handle_call.
  • Functions:
    • Add _try_parse_json to handle JSON decoding with error handling.
    • Modify _handle_call to use _try_parse_json for input parsing.

This description was created by Ellipsis for 65f79e7. You can customize this summary. It will automatically update as commits are pushed.

@swa-kn swa-kn changed the title fix(instrumentation): Improve _handle_call to safely parse JSON, CSV,… fix(instrumentation): Improve _handle_call to safely parse JSON, CSV, and byte inputs in Sagemaker tracing May 28, 2025
@swa-kn swa-kn marked this pull request as ready for review May 28, 2025 14:19
Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

Caution

Changes requested ❌

Reviewed everything up to 65f79e7 in 2 minutes and 2 seconds. Click for details.
  • Reviewed 45 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 2 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. packages/opentelemetry-instrumentation-sagemaker/opentelemetry/instrumentation/sagemaker/__init__.py:164
  • Draft comment:
    In _handle_call the outputs from _try_parse_json (request_body and response_body) are later passed to json.dumps. If _try_parse_json returns a non-serializable type (like bytes), json.dumps might raise an error. Ensure that the fallback values from _try_parse_json are properly converted to a JSON-serializable format.
  • Reason this comment was not posted:
    Marked as duplicate.
2. packages/opentelemetry-instrumentation-sagemaker/opentelemetry/instrumentation/sagemaker/__init__.py:147
  • Draft comment:
    The PR title suggests improved handling for CSV inputs as well, but _try_parse_json only attempts JSON parsing. If CSV inputs are expected, consider clarifying the behavior (or adding explicit CSV parsing) to match the PR title and description.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 10% vs. threshold = 50% The comment makes assumptions about requirements based on the PR title rather than the code itself. The function is actually well-designed - it tries JSON parsing but gracefully falls back to the raw value if that fails. This means CSV data will pass through unchanged, which is likely the intended behavior. The comment is speculative and asks for clarification rather than pointing out a clear issue. I could be wrong about the requirements - maybe explicit CSV parsing really was intended. The PR title suggesting CSV support provides some evidence for this. Even if CSV parsing was mentioned in the PR title, the code's current behavior of passing through non-JSON data unchanged is a valid approach. Without seeing clear requirements that CSV must be parsed, this comment is too speculative. The comment should be deleted as it's speculative and asks for clarification rather than pointing out a clear code issue. The current code behavior of falling back to raw values is reasonable.

Workflow ID: wflow_dTZhh7VXJkw6mWPA

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
Copy link
Contributor

@adharshctr adharshctr left a comment

Choose a reason for hiding this comment

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

LGTM

@gyliu513
Copy link
Contributor

LGTM

@nirga @galkleinman can u help review and comment? Thanks!

@nirga nirga changed the title fix(instrumentation): Improve _handle_call to safely parse JSON, CSV, and byte inputs in Sagemaker tracing fix(sagemaker): Improve _handle_call to safely parse JSON, CSV, and byte inputs in Sagemaker tracing May 29, 2025
@nirga nirga changed the title fix(sagemaker): Improve _handle_call to safely parse JSON, CSV, and byte inputs in Sagemaker tracing fix(sagemaker): Improve _handle_call to safely parse JSON, CSV, and byte inputs May 29, 2025
Copy link
Member

@nirga nirga left a comment

Choose a reason for hiding this comment

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

@swa-kn thanks! can we add tests to that?
(also note the failing lint)

@swa-kn
Copy link
Contributor Author

swa-kn commented Jun 9, 2025

Hey @nirga
I believe, the tests already cover the code I have added. Not sure if you want me to add unit tests for the same.

@swa-kn swa-kn requested a review from nirga June 9, 2025 11:53
@swa-kn swa-kn requested a review from nirga June 19, 2025 05:35
@nirga nirga merged commit 8449df8 into traceloop:main Jun 24, 2025
9 checks passed
@swa-kn swa-kn deleted the sagemaker-trace-corrections branch June 26, 2025 05:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants