Skip to content
This repository was archived by the owner on Nov 17, 2025. It is now read-only.

Commit 169b0b8

Browse files
committed
update sqlcommenter-ruby docs
1 parent 2f8841a commit 169b0b8

File tree

4 files changed

+70
-26
lines changed

4 files changed

+70
-26
lines changed

docs/ruby/ruby-on-rails/README.md

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,31 @@
22
![](../../images/activerecord_marginalia-logo.png)
33

44
- [Ruby on Rails](#ruby-on-rails)
5-
- [Introduction](#introduction)
6-
- [Installation](#installation)
7-
- [Usage](#usage)
8-
- [Fields](#fields)
9-
- [End to end example](#end-to-end-example)
10-
- [Results](#results)
11-
- [GET /posts](#get-posts)
12-
- [POST /posts](#post-posts)
13-
- [References](#references)
14-
15-
## Introduction
5+
- [Rails 7.1 and up](#rails-7.1-and-up)
6+
- [Rails 7.0](#rails-7.0)
7+
- [Rails 6.1 and under](#rails-6.1-and-under)
8+
- [Introduction](#introduction)
9+
- [Installation](#installation)
10+
- [Usage](#usage)
11+
- [Fields](#fields)
12+
- [End to end example](#end-to-end-example)
13+
- [Results](#results)
14+
- [GET /posts](#get-posts)
15+
- [POST /posts](#post-posts)
16+
- [References](#references)
17+
- [Tracing support in Rails](#tracing-support-in-rails)
18+
19+
Support for SQLCommenter in Ruby on Rails varies, depending on the version. Select your version of Rails below to enable SQLCommenter.
20+
21+
## Rails 7.1 and up
22+
23+
SQLCommenter is supported by default. Enable [query_log_tags](https://guides.rubyonrails.org/configuring.html#config-active-record-query-log-tags-enabled), and SQLCommenter formatting will be [enabled by default](https://edgeguides.rubyonrails.org/configuring.html#config-active-record-query-log-tags-format).
24+
25+
## Rails 7.0
26+
Enable [query_log_tags](https://guides.rubyonrails.org/configuring.html#config-active-record-query-log-tags-enabled) and install the [PlanetScale SQLCommenter gem](https://github.com/planetscale/activerecord-sql_commenter#installation) for SQLCommenter support.
27+
28+
29+
## Rails 6.1 and under
1630

1731
[sqlcommenter_rails](https://github.com/open-telemetry/opentelemetry-sqlcommenter/tree/main/ruby/sqlcommenter-ruby/sqlcommenter_rails) adds comments to your SQL statements.
1832

@@ -22,14 +36,16 @@ comments if you use the [opencensus gem].
2236
[sqlcommenter_rails](https://github.com/open-telemetry/opentelemetry-sqlcommenter/tree/main/ruby/sqlcommenter-ruby/sqlcommenter_rails) configures [marginalia](https://github.com/basecamp/marginalia) and [marginalia-opencensus](https://github.com/open-telemetry/opentelemetry-sqlcommenter/tree/main/ruby/sqlcommenter-ruby/marginalia-opencensus) to
2337
match the SQLCommenter format.
2438

25-
## Installation
39+
Compared to newer versions of Rails, this method requires additional work because you will have to install a fork of the [marginalia](https://github.com/basecamp/marginalia/) gem, which has since been consolidated into newer versions of Rails (7.0 and up).
40+
41+
### Installation
2642

2743
Currently, this gem is not released on rubygems. But can be installed from source.
2844

29-
The gem requires functionality provided by an [open PR](https://github.com/basecamp/marginalia/pull/89) to [marginalia](https://github.com/basecamp/marginalia). Install the PR by cloning [glebm's fork of marginalia](https://github.com/glebm/marginalia) one directory above this folder.
45+
The gem requires functionality provided by an [open PR](https://github.com/basecamp/marginalia/pull/130) to [marginalia](https://github.com/basecamp/marginalia). Install the PR by cloning [modulitos' fork of marginalia](https://github.com/modulitos/marginalia) one directory above this folder.
3046

3147
```shell
32-
git clone https://github.com/glebm/marginalia.git ../marginalia
48+
git clone https://github.com/modulitos/marginalia.git ../marginalia
3349
```
3450
Add the following lines to your application's Gemfile:
3551

@@ -49,11 +65,11 @@ To enable [OpenCensus](https://opencensus.io) support, add the [`opencensus`](ht
4965
require 'opencensus/trace/integrations/rails'
5066
```
5167

52-
## Usage
68+
### Usage
5369

5470
All of the SQL queries initiated by the application will now come with comments!
5571

56-
## Fields
72+
### Fields
5773

5874
The following fields will be added to your SQL statements as comments:
5975

@@ -79,7 +95,7 @@ To include the `traceparent` field, install the [marginalia-opencensus](https://
7995

8096
To change which fields are included, set `Marginalia::Comment.components = [ :field1, :field2, ... ]` in `config/initializers/marginalia.rb` as described in the [marginalia documentation](https://github.com/basecamp/marginalia#components).
8197

82-
## End to end example
98+
### End to end example
8399

84100
A Rails 6 [sqlcommenter_rails](https://github.com/open-telemetry/opentelemetry-sqlcommenter/tree/main/ruby/sqlcommenter-ruby/sqlcommenter_rails) demo is available at:
85101
<https://github.com/open-telemetry/opentelemetry-sqlcommenter/tree/main/ruby/sqlcommenter-ruby/sqlcommenter_rails>
@@ -162,11 +178,11 @@ log with the following command:
162178
tail -f log/development.log | grep 'Post '
163179
```
164180

165-
### Results
181+
#### Results
166182

167183
The demo application has 2 endpoints: `GET /posts` and `POST /posts`.
168184

169-
#### GET /posts
185+
##### GET /posts
170186

171187
```shell
172188
curl localhost:3000/posts
@@ -180,7 +196,7 @@ framework='rails_v6.0.0.rc1',route='/posts',
180196
traceparent='00-ff19308b1f17fedc5864e929bed1f44e-6ddace73a9debf63-01'*/
181197
```
182198

183-
#### POST /posts
199+
##### POST /posts
184200

185201
```shell
186202
curl -X POST localhost:3000/posts -d 'title=my-post'
@@ -194,7 +210,7 @@ framework='rails_v6.0.0.rc1',route='/posts',
194210
traceparent='00-ff19308b1f17fedc5864e929bed1f44e-6ddace73a9debf63-01'*/
195211
```
196212

197-
## References
213+
### References
198214

199215
| Resource | URL |
200216
|-------------------------|-------------------------------------------------------------------------------------------------|
@@ -204,3 +220,8 @@ traceparent='00-ff19308b1f17fedc5864e929bed1f44e-6ddace73a9debf63-01'*/
204220
| The opencensus gem | <https://github.com/census-instrumentation/opencensus-ruby > |
205221
| marginalia-opencensus | <https://github.com/google/sqlcommenter/tree/master/ruby/sqlcommenter-ruby/marginalia-opencensus> |
206222

223+
## Tracing support in Rails
224+
225+
Tracing support has been implemented in the [marginalia-opencensus gem]: https://github.com/open-telemetry/opentelemetry-sqlcommenter/tree/main/ruby/sqlcommenter-ruby/marginalia-opencensus. Note that this only works for Rails versions below 7.0, before the [marginalia](https://github.com/basecamp/marginalia/) gem was consolidated into Rails.
226+
227+
Re-purposing that gem for Rails versions >=7.0 should only require minor modifications (contributions are welcome!).

ruby/sqlcommenter-ruby/README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,18 @@
1-
# sqlcommenter-ruby
1+
# sqlcommenter-ruby
2+
3+
## SQLCommenter support in Rails
4+
5+
Support for [SQLCommenter](https://open-telemetry.github.io/opentelemetry-sqlcommenter) in [Ruby on Rails](https://rubyonrails.org/) varies, depending on your versions of Rails.
6+
7+
If you are on Rails version:
8+
9+
- **7.1 and above:** SQLCommenter is supported by default. Enable [query_log_tags](https://guides.rubyonrails.org/configuring.html#config-active-record-query-log-tags-enabled), and SQLCommenter formatting will be [enabled by default](https://edgeguides.rubyonrails.org/configuring.html#config-active-record-query-log-tags-format).
10+
- **7.0:** Enable [query_log_tags](https://guides.rubyonrails.org/configuring.html#config-active-record-query-log-tags-enabled) and install the [PlanetScale SQLCommenter gem](https://github.com/planetscale/activerecord-sql_commenter#installation) for SQLCommenter support.
11+
- **Below 7.0:** Refer to the [sqlcommenter_rails gem](https://github.com/open-telemetry/opentelemetry-sqlcommenter/tree/main/ruby/sqlcommenter-ruby/sqlcommenter_rails) in this directory for adding SQLCommenter support. Note that this requires additional work because you will have to install a fork of the [marginalia](https://github.com/basecamp/marginalia/) gem, which has since been consolidated into Rails 7.0 and up.
12+
13+
## Tracing support in Rails
14+
15+
Tracing support has been implemented in the [marginalia-opencensus gem]: https://github.com/open-telemetry/opentelemetry-sqlcommenter/tree/main/ruby/sqlcommenter-ruby/marginalia-opencensus. Note that this only works for Rails versions below 7.0, before the [marginalia](https://github.com/basecamp/marginalia/) gem was consolidated into Rails.
16+
17+
Re-purposing that gem for Rails versions >=7.0 should only require minor modifications (contributions are welcome!).
18+

ruby/sqlcommenter-ruby/sqlcommenter_rails/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# sqlcommenter_rails
22

3+
**If you are on Rails version 7.0 and up, refer to the [sqlcommenter-ruby README] instead**
4+
35
[sqlcommenter] for [Ruby on Rails].
46

57
Powered by [marginalia] and [marginalia-opencensus].
@@ -8,16 +10,17 @@ Powered by [marginalia] and [marginalia-opencensus].
810
[Ruby on Rails]: https://rubyonrails.org/
911
[marginalia]: https://github.com/basecamp/marginalia/
1012
[marginalia-opencensus]: https://github.com/open-telemetry/opentelemetry-sqlcommenter/tree/master/ruby/sqlcommenter-ruby/marginalia-opencensus
13+
[sqlcommenter-ruby README]: https://github.com/open-telemetry/opentelemetry-sqlcommenter/blob/main/ruby/sqlcommenter-ruby/README.md
1114

1215
## Installation
1316

1417
Currently, this gem is not released on rubygems.
1518
But can be installed from source.
1619

17-
The gem requires functionality provided by an [open PR](https://github.com/basecamp/marginalia/pull/89) to [marginalia](https://github.com/basecamp/marginalia). Install the PR by cloning [glebm's fork of marginalia](https://github.com/glebm/marginalia) one directory above this folder.
20+
The gem requires functionality provided by an [open PR](https://github.com/basecamp/marginalia/pull/130) to [marginalia](https://github.com/basecamp/marginalia). Install the PR by cloning [modulitos' fork of marginalia](https://github.com/modulitos/marginalia) one directory above this folder.
1821

1922
```bash
20-
git clone https://github.com/glebm/marginalia.git ../marginalia
23+
git clone https://github.com/modulitos/marginalia.git ../marginalia
2124
```
2225

2326
Add the following lines to your application's Gemfile:

ruby/sqlcommenter-ruby/sqlcommenter_rails_demo/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
# sqlcommenter_rails demo
22

3+
**If you are on Rails version 7.0 and up, refer to the [sqlcommenter-ruby README] instead**
4+
35
This is a demo [Rails API] application to demonstrate [sqlcommenter_rails] integration.
46

57
[Rails API]: https://guides.rubyonrails.org/api_app.html
68
[sqlcommenter_rails]: https://github.com/open-telemetry/opentelemetry-sqlcommenter/ruby/sqlcommenter-ruby/sqlcommenter_rails
9+
[sqlcommenter-ruby README]: https://github.com/open-telemetry/opentelemetry-sqlcommenter/blob/main/ruby/sqlcommenter-ruby/README.md
710

811
## Setup
912

1013
Install [Ruby v2.6.3](https://www.ruby-lang.org/en/news/2019/04/17/ruby-2-6-3-released/) if you don't already have it installed.
1114

12-
This demo requires functionality provided by an [open PR](https://github.com/basecamp/marginalia/pull/89) to [marginalia](https://github.com/basecamp/marginalia). Install the PR by cloning [glebm's fork of marginalia](https://github.com/glebm/marginalia) one directory above this demo. Starting from the root directory of this demo:
15+
This demo requires functionality provided by an [open PR](https://github.com/basecamp/marginalia/pull/130) to [marginalia](https://github.com/basecamp/marginalia). Install the PR by cloning [modulitos' fork of marginalia](https://github.com/modulitos/marginalia) one directory above this demo. Starting from the root directory of this demo:
1316

1417
```bash
15-
git clone https://github.com/glebm/marginalia.git ../marginalia
18+
git clone https://github.com/modulitos/marginalia.git ../marginalia
1619
git -C ../marginalia checkout formatting
1720
```
1821

0 commit comments

Comments
 (0)