Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The ability to trace SQL queries is not yet implemented. #91

Open
y-mitsuyoshi opened this issue Apr 18, 2023 · 0 comments
Open

The ability to trace SQL queries is not yet implemented. #91

y-mitsuyoshi opened this issue Apr 18, 2023 · 0 comments

Comments

@y-mitsuyoshi
Copy link

y-mitsuyoshi commented Apr 18, 2023

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

#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

      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.

      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.

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

No branches or pull requests

1 participant