Skip to content

Add db_runtime instrumentation for ActiveGraph - #1741

Open
NA-V10 wants to merge 1 commit into
neo4jrb:12from
NA-V10:add-db-runtime-support
Open

Add db_runtime instrumentation for ActiveGraph#1741
NA-V10 wants to merge 1 commit into
neo4jrb:12from
NA-V10:add-db-runtime-support

Conversation

@NA-V10

@NA-V10 NA-V10 commented Jul 18, 2026

Copy link
Copy Markdown

Fixes #1291

This pull introduces/changes:

  • Adds ActiveGraph database runtime instrumentation through ActiveSupport::Notifications
  • Adds ActiveGraph::RuntimeRegistry to accumulate Neo4j Bolt request runtime
  • Exposes accumulated database runtime as payload[:db_runtime] for Rails controller actions
  • Integrates controller runtime tracking through ActiveSupport.on_load(:action_controller)
  • Adds unit tests for runtime accumulation, reset behavior, and controller payload integration

Summary

Adds ActiveGraph database runtime instrumentation to expose db_runtime in Rails controller payloads.

This brings ActiveGraph closer to ActiveRecord's database runtime instrumentation behavior.

Changes

  • Added ActiveGraph::RuntimeRegistry to accumulate Neo4j Bolt request runtime.
  • Subscribed to neo4j.core.bolt.request using ActiveSupport::Notifications.monotonic_subscribe.
  • Added controller runtime integration through ActiveSupport.on_load(:action_controller).
  • Reset runtime before controller actions.
  • Added accumulated database runtime to payload[:db_runtime].
  • Added unit tests for runtime accumulation and controller payload integration.

Testing

  • Added unit tests for runtime accumulation and reset behavior.
  • Added controller runtime tests.

Local test execution is currently pending Ruby/Bundler setup on the development environment.

Summary by CodeRabbit

  • New Features
    • Added database runtime tracking for Neo4j Bolt requests.
    • Controller request payloads now include accumulated database runtime (db_runtime), including support for incrementing when a value is already present.
    • Ensures runtime counters are cleared/reset around each controller action for accurate per-request metrics.
  • Tests
    • Added unit specs covering runtime accumulation/reset behavior and controller lifecycle integration.

@coderabbitai

coderabbitai Bot commented Jul 18, 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 Plus

Run ID: f85d6f1a-1e0c-496c-b4d4-45bbbed1a9eb

📥 Commits

Reviewing files that changed from the base of the PR and between c28c7f9 and 1e70270.

📒 Files selected for processing (5)
  • lib/active_graph/railtie.rb
  • lib/active_graph/railties/controller_runtime.rb
  • lib/active_graph/runtime_registry.rb
  • spec/unit/railties/controller_runtime_spec.rb
  • spec/unit/runtime_registry_spec.rb
🚧 Files skipped from review as they are similar to previous changes (5)
  • spec/unit/runtime_registry_spec.rb
  • spec/unit/railties/controller_runtime_spec.rb
  • lib/active_graph/railties/controller_runtime.rb
  • lib/active_graph/railtie.rb
  • lib/active_graph/runtime_registry.rb

📝 Walkthrough

Walkthrough

Adds ActiveGraph::RuntimeRegistry to accumulate Neo4j Bolt request durations and integrates it with Rails controllers. Controller payloads now expose :db_runtime, with Railtie wiring and unit tests covering registry accumulation, reset behavior, and lifecycle hooks.

Changes

Database runtime tracking

Layer / File(s) Summary
Runtime registry and notification collection
lib/active_graph/runtime_registry.rb, spec/unit/runtime_registry_spec.rb
Runtime statistics are stored per isolated execution, accumulated from Neo4j Bolt notification timings, reset through a public API, and covered by unit tests.
Controller lifecycle integration
lib/active_graph/railtie.rb, lib/active_graph/railties/controller_runtime.rb, spec/unit/railties/controller_runtime_spec.rb
The Railtie includes the controller concern, which resets runtime before actions and adds the reset value as payload[:db_runtime]; lifecycle behavior is tested.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Neo4jBolt
  participant RuntimeRegistry
  participant RailsController
  participant ActionPayload
  Neo4jBolt->>RuntimeRegistry: report Bolt request duration
  RailsController->>RuntimeRegistry: reset before process_action
  RailsController->>RailsController: execute action
  RailsController->>RuntimeRegistry: reset accumulated runtime
  RuntimeRegistry->>ActionPayload: provide db_runtime
  RailsController->>ActionPayload: append db_runtime
Loading
🚥 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 is concise and accurately summarizes the new db_runtime instrumentation for ActiveGraph.
Linked Issues check ✅ Passed The PR adds runtime accumulation, controller payload reporting, and tests matching the db_runtime support requested in #1291.
Out of Scope Changes check ✅ Passed The changes stay focused on db_runtime instrumentation and related tests, with no clear unrelated additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
spec/unit/railties/controller_runtime_spec.rb (1)

31-38: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Test that it adds to existing db_runtime.

If you update append_info_to_payload to accumulate db_runtime (so as not to overwrite metrics from other ORMs), consider updating this test or adding another context to verify the accumulation.

💡 Proposed test addition
       payload = {}
 
       controller.send(:append_info_to_payload, payload)
 
       expect(payload[:db_runtime]).to eq(250.0)
     end
+
+    it 'adds to existing database runtime in the payload' do
+      ActiveGraph::RuntimeRegistry.call('neo4j.core.bolt.request', 1.0, 1.25, 'id', {})
+      payload = { db_runtime: 100.0 }
+
+      controller.send(:append_info_to_payload, payload)
+
+      expect(payload[:db_runtime]).to eq(350.0)
+    end
   end
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@spec/unit/railties/controller_runtime_spec.rb` around lines 31 - 38, Update
the test around append_info_to_payload to initialize payload[:db_runtime] with
an existing runtime value, invoke the method, and assert that the result
includes both the existing value and the newly recorded 250.0 runtime. Preserve
the current assertion for an empty payload as a separate case if needed.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@lib/active_graph/railties/controller_runtime.rb`:
- Around line 15-19: Update append_info_to_payload so
ActiveGraph::RuntimeRegistry.reset is added to any existing payload[:db_runtime]
value rather than replacing it, preserving accumulated runtime from ActiveRecord
or other ORM/ODM integrations.

---

Nitpick comments:
In `@spec/unit/railties/controller_runtime_spec.rb`:
- Around line 31-38: Update the test around append_info_to_payload to initialize
payload[:db_runtime] with an existing runtime value, invoke the method, and
assert that the result includes both the existing value and the newly recorded
250.0 runtime. Preserve the current assertion for an empty payload as a separate
case if needed.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: b5690518-79b6-4533-901e-2d32b2222247

📥 Commits

Reviewing files that changed from the base of the PR and between f952b9f and c28c7f9.

📒 Files selected for processing (5)
  • lib/active_graph/railtie.rb
  • lib/active_graph/railties/controller_runtime.rb
  • lib/active_graph/runtime_registry.rb
  • spec/unit/railties/controller_runtime_spec.rb
  • spec/unit/runtime_registry_spec.rb

Comment thread lib/active_graph/railties/controller_runtime.rb
@NA-V10
NA-V10 force-pushed the add-db-runtime-support branch from c28c7f9 to 1e70270 Compare July 18, 2026 15:32
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.

Add db_runtime support to Neo4jrb

1 participant