aws / aws/aws-xray-sdk-ruby

The ability to trace SQL queries is not yet implemented.

Open
#91 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Ruby
Stars
60
Forks
54
PR merge metrics
No merged PRs in 30d

Description

The following pull-link said the feature would be implemented, but it doesn't seem to be supported yet.

https://github.com/aws/aws-xray-sdk-ruby/pull/21

Would you be willing to merge the code similar to the pull request author's suggestion?

The part I want to fix is the following record method.

https://github.com/aws/aws-xray-sdk-ruby/blob/5d482e76d86b7610d5fe8e404c44cd0bce9e9547/lib/aws-xray-sdk/facets/rails/active_record.rb

```ruby
def record(transaction)
payload = transaction.payload
pool, conn = get_pool_n_conn(payload[:connection_id])

return if IGNORE_OPS.include?(payload[:name]) || pool.nil? || conn.nil?
# The spec notation is Rails < 6.1, later this can be found in the db_config
db_config = if pool.respond_to?(:spec)
pool.spec.config
else
pool.db_config.configuration_hash
end
name, sql = build_name_sql_meta config: db_config, conn: conn
subsegment = XRay.recorder.begin_subsegment name, namespace: 'remote'
# subsegment is nil in case of context missing
return if subsegment.nil?
subsegment.start_time = transaction.time.to_f
subsegment.sql = sql
XRay.recorder.end_subsegment end_time: transaction.end.to_f
end
```

I would like to add **sql[:sanitized_query] = payload[:sql]** to the above code as follows.
```ruby
def record(transaction)
payload = transaction.payload
pool, conn = get_pool_n_conn(payload[:connection_id])

return if IGNORE_OPS.include?(payload[:name]) || pool.nil? || conn.nil?
# The spec notation is Rails < 6.1, later this can be found in the db_config
db_config = if pool.respond_to?(:spec)
pool.spec.config
else
pool.db_config.configuration_hash
end
name, sql = build_name_sql_meta config: db_config, conn: conn
sql[:sanitized_query] = payload[:sql]
subsegment = XRay.recorder.begin_subsegment name, namespace: 'remote'
# subsegment is nil in case of context missing
return if subsegment.nil?
subsegment.start_time = transaction.time.to_f
subsegment.sql = sql
XRay.recorder.end_subsegment end_time: transaction.end.to_f
end
```

If it is too difficult, put SQL in the metadata.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.