Skip to content

Add Trilogy adapter support#3

Open
prathamesh-sonpatki wants to merge 1 commit intomainfrom
feat/trilogy-adapter
Open

Add Trilogy adapter support#3
prathamesh-sonpatki wants to merge 1 commit intomainfrom
feat/trilogy-adapter

Conversation

@prathamesh-sonpatki
Copy link
Member

Summary

  • Add Trilogy adapter for OpenTelemetry context enrichment, following the same pattern as the existing PG and MySQL2 adapters
  • Patches ::Trilogy#query to add source location, ActiveRecord context, and slow query duration attributes to OTel spans
  • Add configuration options (trilogy_slow_query_enabled, trilogy_slow_query_threshold_ms) with env var support
  • Comprehensive test suite with 8 tests covering slow/fast queries, AR context, span naming, invalid contexts, and install guards

Test plan

  • All 28 tests pass across 7 test files (0 failures)
  • Trilogy adapter follows same pattern as MySQL2 adapter
  • Configuration defaults and env var overrides tested
  • Double-prepend guard tested

🤖 Generated with Claude Code

Adds support for the Trilogy MySQL client (used by GitHub, built into
Rails 7.1+). Follows the same pattern as the existing Mysql2 adapter.

New files:
- lib/rails_otel_context/adapters/trilogy.rb
- test/trilogy_adapter_test.rb (8 tests)

Modified files:
- lib/rails_otel_context/adapters.rb - register Trilogy adapter
- lib/rails_otel_context/configuration.rb - add trilogy config options
- lib/rails_otel_context.rb - add env var support
- test/configuration_test.rb - add Trilogy env var assertions

Configuration:
  trilogy_slow_query_enabled (default: true)
  trilogy_slow_query_threshold_ms (default: 200.0)

Environment variables:
  RAILS_OTEL_CONTEXT_TRILOGY_SLOW_QUERY_ENABLED
  RAILS_OTEL_CONTEXT_TRILOGY_SLOW_QUERY_MS
@prathamesh-sonpatki
Copy link
Member Author

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

The Trilogy adapter correctly follows the established MySQL2 adapter pattern with appropriate differences:

  • query(sql) takes a single argument (no options hash), matching Trilogy's API
  • No prepare method (Trilogy handles prepared statements at the ActiveRecord adapter layer)
  • Configuration, env vars, and install guards are consistent with existing adapters
  • Test coverage is comprehensive (8 tests covering slow/fast queries, AR context, span naming, invalid contexts, missing source locations, install guards, and double-prepend protection)

🤖 Generated with Claude Code

- If this code review was useful, please react with 👍. Otherwise, react with 👎.

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