Skip to content

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

@y-mitsuyoshi

Description

@y-mitsuyoshi

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions