Skip to content

fix(sdk): log errors from Fetcher.api_post instead of printing to stdout#4344

Open
CAN-Aidoo wants to merge 1 commit into
traceloop:mainfrom
CAN-Aidoo:fix/sdk-fetcher-error-logging
Open

fix(sdk): log errors from Fetcher.api_post instead of printing to stdout#4344
CAN-Aidoo wants to merge 1 commit into
traceloop:mainfrom
CAN-Aidoo:fix/sdk-fetcher-error-logging

Conversation

@CAN-Aidoo

@CAN-Aidoo CAN-Aidoo commented Jul 2, 2026

Copy link
Copy Markdown

Summary

Replace print(e) in Fetcher.api_post with logging.error(\"Failed to post to %s: %s\", api, e).

Motivation

Every other error path in fetcher.py uses logging.error(...) — see lines 108, 111, 143. The print(e) in api_post was the odd one out:

  • Errors bypassed the log stream (invisible to log aggregators and level filters).
  • Message dropped all context (no endpoint name, no traceback).
  • Emitted to stdout instead of stderr.

The other print(...) calls in traceloop/sdk/__init__.py, tracing.py, and experiment/* are intentional colorama-styled user-facing startup output and are out of scope.

Test plan

  • New tests/test_fetcher_logging.py asserts an ERROR record is emitted through the log stream with the endpoint name in the formatted message, and that stdout stays silent.
  • uv run ruff check passes on the modified files.

Summary by CodeRabbit

  • Bug Fixes
    • Error handling for API requests now logs failures instead of printing them to the console.
    • Failure messages include the affected endpoint and the error details, making issues easier to trace.
    • Added coverage to ensure errors are logged correctly and not sent to standard output.

Fetcher.api_post caught exceptions and called print(e), which bypassed the log stream, dropped all context (endpoint name, no traceback), and wrote to stdout. Every other error path in fetcher.py already uses logging.error(...). Switch to logging.error with the endpoint name so failures surface in log aggregators and respect log-level filtering.
@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3040cf44-b694-4d61-a999-f56563a2d33b

📥 Commits

Reviewing files that changed from the base of the PR and between 93429cf and db0f712.

📒 Files selected for processing (2)
  • packages/traceloop-sdk/tests/test_fetcher_logging.py
  • packages/traceloop-sdk/traceloop/sdk/fetcher.py

📝 Walkthrough

Walkthrough

The exception handler in Fetcher.api_post was changed to log errors via logging.error instead of printing them to stdout. A new test verifies that failures are logged with the endpoint and error message and are no longer printed.

Changes

Fetcher error handling

Layer / File(s) Summary
Log errors instead of printing
packages/traceloop-sdk/traceloop/sdk/fetcher.py, packages/traceloop-sdk/tests/test_fetcher_logging.py
api_post now logs exceptions via logging.error("Failed to post to %s: %s", api, e) instead of print(e), and a new test confirms an ERROR log is emitted with the endpoint and error text while nothing is printed to stdout.

Estimated code review effort: 1 (Trivial) | ~3 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately summarizes the main change: replacing stdout printing with logging in Fetcher.api_post.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

1 participant