{"size": 981, "ext": "js", "max_stars_repo_path": "lib/hooks/mysql2.js", "max_stars_repo_name": "sqlwwx/egg-jaeger", "max_stars_repo_stars_event_min_datetime": "2019-04-16T07:17:47.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-22T11:35:45.000Z", "max_issues_repo_path": "lib/hooks/mysql2.js", "max_issues_repo_name": "sqlwwx/egg-jaeger", "max_issues_repo_issues_event_min_datetime": "2021-01-22T03:40:49.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-08T23:35:07.000Z", "max_forks_repo_path": "lib/hooks/mysql2.js", "max_forks_repo_name": "sqlwwx/egg-jaeger", "max_forks_repo_forks_event_min_datetime": "2021-07-10T08:18:26.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-10T08:18:26.000Z"}
{"max_stars_count": 4, "max_issues_count": 7, "max_forks_count": 1, "avg_line_length": 26.5135135135, "max_line_length": 73, "alphanum_fraction": 0.4729867482}
'use strict';

const util = require('../util');
module.exports = app => {
  try {
    const Connection = require('mysql2/lib/connection');
    util.wrap(Connection.prototype, 'query', original => {
      return function query(sql, values, cb) {
        const span = app.startSpan('mysql.query', {
          'db.statement': sql,
          'db.type': 'mysql',
          component: 'mysql2',
          'span.kind': 'client',
          'db.instance': this.config.database || 'sql',
        });
        const sequence = original.call(this, sql, values, (err, ret) => {
          if (err) {
            span.addTags({
              'error.type': err.name,
              'error.msg': err.message,
              'error.stack': err.stack,
            });
          }
          span.finish();
          cb(err, ret);
        });
        sequence.on('end', () => {
          span.finish();
        });
        return sequence;
      };
    });
  } catch (err) {
    console.warn(err);
  }
};
