Skip to content

feat(agents): Instrument RubyLLM tools - #3184

Draft
sl0thentr0py wants to merge 1 commit into
neel/ruby-llm/chat-instrumentationfrom
neel/ruby-llm/tool-instrumentation
Draft

sl0thentr0py wants to merge 1 commit into
neel/ruby-llm/chat-instrumentationfrom
neel/ruby-llm/tool-instrumentation

Conversation

@sl0thentr0py

@sl0thentr0py sl0thentr0py commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

Summary

Adds RubyLLM local tool execution tracing and concurrent-tool context propagation.

  • Records gen_ai.execute_tool spans with tool names and privacy-gated JSON arguments and results.
  • Preserves tool return values and exceptions while ensuring response data is recorded.
  • Wraps RubyLLM::Chat::ToolConcurrency.run without patching global thread behavior.
  • Gives each concurrent execution an isolated Sentry hub while retaining the parent span recorder, keeping tool spans in the original trace.
  • Uses the shared instrumenter and DataConventions used by chat instrumentation.

Testing

  • Covers sequential and concurrent tool spans, parent-span recorder retention, scope restoration, and privacy gates.
  • Verified with RubyLLM 2.2.3 on the Ruby 3.2 and Ruby 4.0 test cells.

Issues

@sl0thentr0py
sl0thentr0py added this pull request to stack #3182 November 4, 2026 16:19

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 01f1aad. Configure here.

ensure
Sentry.send(:set_current_hub_internal, previous_hub)
end
end

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fiber tool runs corrupt hub state

Medium Severity

with_hub save/restores the current hub via thread-local storage, and run applies that wrap in every concurrency mode. RubyLLM :fibers runs tools as cooperative fibers on the same thread, so overlapping with_hub calls overwrite each other's saved hub. After the batch finishes, the request thread can be left with a stale cloned hub instead of the original, so later spans and events lose the request scope.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 01f1aad. Configure here.

@sl0thentr0py
sl0thentr0py marked this pull request as draft November 4, 2026 16:54
@linear-code

linear-code Bot commented Nov 4, 2026

Copy link
Copy Markdown

RUBY-217

@crmne

crmne commented Nov 7, 2026

Copy link
Copy Markdown

Blocking for 2.2: please replace the ToolConcurrency.run patch with capture_context / with_context on your instrumenter wrapper, as described on #3183. That also handles Bugbot's fibers concern, since context is set per tool rather than per thread. Optional: gen_ai.tool.call.id, gen_ai.tool.type and gen_ai.tool.description are all in the payload.

@sl0thentr0py
sl0thentr0py force-pushed the neel/ruby-llm/tool-instrumentation branch from 01f1aad to ae9b359 Compare November 26, 2026 13:14
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 26, 2026
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

PR risk: medium

For commit 7ee5e08.

Main concerns: data sent to Sentry, host performance, reach.

This label is a hint for reviewers, not an approval.

@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: medium PR risk score: medium labels Nov 26, 2026
@sl0thentr0py
sl0thentr0py force-pushed the neel/ruby-llm/tool-instrumentation branch from ae9b359 to fcdcfa8 Compare November 26, 2026 13:19
@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: medium PR risk score: medium labels Nov 26, 2026
@sl0thentr0py
sl0thentr0py force-pushed the neel/ruby-llm/tool-instrumentation branch from fcdcfa8 to b9df3c7 Compare November 26, 2026 13:20
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 26, 2026
@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: medium PR risk score: medium labels Nov 26, 2026
@sl0thentr0py
sl0thentr0py force-pushed the neel/ruby-llm/tool-instrumentation branch from b9df3c7 to d1cdf71 Compare November 26, 2026 13:24
@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: medium PR risk score: medium labels Nov 26, 2026
@sl0thentr0py
sl0thentr0py force-pushed the neel/ruby-llm/tool-instrumentation branch from d1cdf71 to 3e23c60 Compare November 26, 2026 13:25
@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: medium PR risk score: medium labels Nov 26, 2026
@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: medium PR risk score: medium labels Nov 26, 2026
@sl0thentr0py
sl0thentr0py force-pushed the neel/ruby-llm/tool-instrumentation branch from dc4ffc1 to 5514614 Compare November 26, 2026 14:08
@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: medium PR risk score: medium labels Nov 26, 2026
@sl0thentr0py
sl0thentr0py force-pushed the neel/ruby-llm/tool-instrumentation branch from 5514614 to d794fdc Compare November 26, 2026 14:23
@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: medium PR risk score: medium labels Nov 26, 2026
@sl0thentr0py
sl0thentr0py force-pushed the neel/ruby-llm/tool-instrumentation branch from d794fdc to 92f6b48 Compare November 26, 2026 14:37
@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: medium PR risk score: medium labels Nov 26, 2026
@sl0thentr0py
sl0thentr0py force-pushed the neel/ruby-llm/tool-instrumentation branch from 92f6b48 to 4f801a0 Compare November 26, 2026 14:44
@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: medium PR risk score: medium labels Nov 26, 2026
Co-Authored-By: OpenAI <noreply@openai.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants