Skip to content

feat(agents): Instrument RubyLLM agent runs - #3186

Draft
sl0thentr0py wants to merge 1 commit into
neel/ruby-llm/workflowsfrom
neel/ruby-llm/agent-runs
Draft

sl0thentr0py wants to merge 1 commit into
neel/ruby-llm/workflowsfrom
neel/ruby-llm/agent-runs

Conversation

@sl0thentr0py

@sl0thentr0py sl0thentr0py commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

Summary

Adds RubyLLM agent identity and agent-run tracing.

  • Captures agent identity through the shared RubyLLM::Agent.apply_configuration path.
  • Creates one gen_ai.invoke_agent span per outer operation across complete, generate, run_tools, and step.
  • Suppresses duplicate wrappers for the same chat while preserving genuinely nested agents.
  • Propagates gen_ai.agent.name to model and tool descendants.
  • Finishes agent spans on success and errors without keeping runs open across jobs.

Testing

  • Covers nested agents, duplicate suppression, model and tool descendants, return values, errors, and scope restoration.
  • Verified with RubyLLM 2.2.3 on the Ruby 3.2 and Ruby 4.0 test cells.
  • The complete sentry-agents spec suite and RuboCop pass.

Issues

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

@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 18541b7. Configure here.

ensure
if depth&.positive?
depth.zero? ? chat.remove_instance_variable(DEPTH_IVAR) : chat.instance_variable_set(DEPTH_IVAR, depth)
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.

Agent run depth never resets

High Severity

The ensure in with only restores depth when depth is already positive, so the outer wrapper never clears @sentry_agents_agent_run_depth. After the first run, later calls on the same chat skip gen_ai.invoke_agent spans, including follow-up turns on a reused agent chat.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 18541b7. Configure here.

@sl0thentr0py
sl0thentr0py force-pushed the neel/ruby-llm/agent-runs branch from 18541b7 to cbb73ec Compare November 4, 2026 16:38
@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

Please build this on the new agent.ruby_llm event instead of patching Agent.apply_configuration and Chat. It also fixes two bugs in the current approach: after the first turn on a chat no invoke_agent span is emitted (the depth counter never resets, as Bugbot says), and Rails-backed agents from Agent.create and find get no agent span at all.

@sl0thentr0py
sl0thentr0py force-pushed the neel/ruby-llm/agent-runs branch from cbb73ec to 3c0450d 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 85e3467.

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/agent-runs branch from 3c0450d to 3df5c96 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/agent-runs branch from 3df5c96 to ae6fec6 Compare November 26, 2026 13:20
@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/agent-runs branch from ae6fec6 to 621235d 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/agent-runs branch from 621235d to f97fa14 Compare November 26, 2026 13:25
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 26, 2026
@sl0thentr0py
sl0thentr0py force-pushed the neel/ruby-llm/agent-runs branch from d89d167 to fd044d0 Compare November 26, 2026 14:05
@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/agent-runs branch from fd044d0 to 641d580 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/agent-runs branch from 641d580 to 5700265 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/agent-runs branch from 5700265 to caa9307 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/agent-runs branch from caa9307 to b100396 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