Skip to content

Commit

Permalink
NH-94970: remove marginalia code and add psql patch for dbo
Browse files Browse the repository at this point in the history
  • Loading branch information
xuan-cao-swi committed Dec 12, 2024
1 parent 77162dd commit 2eb54f6
Show file tree
Hide file tree
Showing 22 changed files with 158 additions and 627 deletions.
24 changes: 9 additions & 15 deletions CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,24 +165,18 @@ SELECT * FROM SAMPLE_TABLE WHERE user_id = 1;
SELECT * FROM SAMPLE_TABLE WHERE user_id = 1; /* traceparent=7435a9fe510ae4533414d425dadf4e18-49e60702469db05f-01 */
```

For Rails < 7 and non-Rails applications, we use a port of [Marginalia](https://github.com/basecamp/marginalia) that patches ActiveRecord to inject the comment.
#### Limitation

For Rails >= 7, Marginalia is [integrated into ActiveRecord](https://api.rubyonrails.org/classes/ActiveRecord/QueryLogs.html) so enabling this feature should be done through Rails [configuration](https://guides.rubyonrails.org/v7.0/configuring.html#config-active-record-query-log-tags-enabled). For example:
Currently, tag queries don't support prepared statements. Active Record uses the PostgreSQL adapter (pg) by default to prepare statements. So, when you choose to use PostgreSQL and wish to enable trace context, please set `prepared_statements` to false."

```ruby
class Application < Rails::Application
config.active_record.query_log_tags_enabled = true
config.active_record.query_log_tags = [
{
traceparent: -> {
SolarWindsAPM::SWOMarginalia::Comment.traceparent
}
}
]
end
```
e.g.

Note that with Rails >= 7.1 the comment format can be specified via the `config.active_record.query_log_tags_format` option. SolarWinds Observability functionality depends on the default `:sqlcommenter` format, it is not recommended to change this value.
```yaml
development:
adapter: postgresql
# ...
prepared_statements: false
```
### Background Jobs
Expand Down
4 changes: 0 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,6 @@ BUNDLE_GEMFILE=gemfiles/unit.gemfile bundle update

BUNDLE_GEMFILE=gemfiles/unit.gemfile bundle exec ruby -I test test/opentelemetry/solarwinds_exporter_test.rb
BUNDLE_GEMFILE=gemfiles/unit.gemfile bundle exec ruby -I test test/opentelemetry/solarwinds_propagator_test.rb

# marginalia tests require the rails_6x.gemfile dependencies
BUNDLE_GEMFILE=gemfiles/rails_6x.gemfile bundle install
BUNDLE_GEMFILE=gemfiles/rails_6x.gemfile bundle exec ruby -I test test/support/swomarginalia/swomarginalia_test.rb
```

To run a specific test (that requires unit.gemfile):
Expand Down
6 changes: 1 addition & 5 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,13 @@ Rake::TestTask.new do |t|
gem_file = ENV['BUNDLE_GEMFILE']&.split('/')&.last

case gem_file
when 'rails_6x.gemfile'
t.test_files = FileList['test/support/swomarginalia/*_test.rb']

when 'unit.gemfile'
t.test_files = FileList['test/api/*_test.rb'] +
FileList['test/solarwinds_apm/*_test.rb'] +
FileList['test/opentelemetry/*_test.rb'] +
FileList['test/noop/*_test.rb'] +
FileList['test/ext/*_test.rb'] +
FileList['test/support/*_test.rb'] -
FileList['test/support/swomarginalia/*_test.rb']
FileList['test/support/*_test.rb']
end
end

Expand Down
9 changes: 0 additions & 9 deletions gemfiles/rails_6x.gemfile

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,5 @@
# Example:
# SELECT `posts`.* FROM `posts` /*traceparent=00-a448f096d441e167d12ebd32a927c1a5-a29655a47e430119-01*/
#
# This option can add a small overhead for prepared statements since the traceparent value is unique per execution.
# This feature uses marginalia, see its caveat and possible workaround
# https://github.com/basecamp/marginalia/blob/master/README.md#prepared-statements
#
SolarWindsAPM::Config[:tag_sql] = false
end
2 changes: 0 additions & 2 deletions lib/solarwinds_apm/patch/tag_sql/sw_mysql2_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
#
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

require_relative 'swo_dbo_utils'

module SolarWindsAPM
module Patch
module TagSql
Expand Down
2 changes: 0 additions & 2 deletions lib/solarwinds_apm/patch/tag_sql/sw_pg_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#
# SPDX-License-Identifier: Apache-2.0

require_relative 'swo_dbo_utils'

module SolarWindsAPM
module Patch
module TagSql
Expand Down
1 change: 1 addition & 0 deletions lib/solarwinds_apm/patch/tag_sql_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
#
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

require_relative 'tag_sql/sw_dbo_utils'
require_relative 'tag_sql/sw_mysql2_patch'
require_relative 'tag_sql/sw_pg_patch'
20 changes: 0 additions & 20 deletions lib/solarwinds_apm/support/swomarginalia/LICENSE

This file was deleted.

46 changes: 0 additions & 46 deletions lib/solarwinds_apm/support/swomarginalia/README.md

This file was deleted.

206 changes: 0 additions & 206 deletions lib/solarwinds_apm/support/swomarginalia/comment.rb

This file was deleted.

Loading

0 comments on commit 2eb54f6

Please sign in to comment.