(installer: PluginInstaller)
| 30 | readonly versions = '*'; |
| 31 | |
| 32 | install(installer: PluginInstaller): void { |
| 33 | const Connection = installer.require?.('mysql/lib/Connection') ?? require('mysql/lib/Connection'); |
| 34 | const _query = Connection.prototype.query; |
| 35 | |
| 36 | Connection.prototype.query = function (sql: any, values: any, cb: any) { |
| 37 | let query: any; |
| 38 | |
| 39 | const host = `${this.config.host}:${this.config.port}`; |
| 40 | const span = ContextManager.current.newExitSpan('mysql/query', Component.MYSQL); |
| 41 | |
| 42 | span.start(); |
| 43 | |
| 44 | try { |
| 45 | span.component = Component.MYSQL; |
| 46 | span.layer = SpanLayer.DATABASE; |
| 47 | span.peer = host; |
| 48 | |
| 49 | span.tag(Tag.dbType('Mysql')); |
| 50 | span.tag(Tag.dbInstance(`${this.config.database}`)); |
| 51 | |
| 52 | let _sql: any; |
| 53 | let _values: any; |
| 54 | let streaming: any; |
| 55 | |
| 56 | if (typeof sql === 'function') { |
| 57 | sql = wrapCallback(span, sql, 0); |
| 58 | } else if (typeof sql === 'object') { |
| 59 | _sql = sql.sql; |
| 60 | |
| 61 | if (typeof values === 'function') { |
| 62 | values = wrapCallback(span, values, 0); |
| 63 | _values = sql.values; |
| 64 | } else if (values !== undefined) { |
| 65 | _values = values; |
| 66 | |
| 67 | if (typeof cb === 'function') { |
| 68 | cb = wrapCallback(span, cb, 0); |
| 69 | } else { |
| 70 | streaming = true; |
| 71 | } |
| 72 | } else { |
| 73 | streaming = true; |
| 74 | } |
| 75 | } else { |
| 76 | _sql = sql; |
| 77 | |
| 78 | if (typeof values === 'function') { |
| 79 | values = wrapCallback(span, values, 0); |
| 80 | } else if (values !== undefined) { |
| 81 | _values = values; |
| 82 | |
| 83 | if (typeof cb === 'function') { |
| 84 | cb = wrapCallback(span, cb, 0); |
| 85 | } else { |
| 86 | streaming = true; |
| 87 | } |
| 88 | } else { |
| 89 | streaming = true; |
nothing calls this directly
no test coverage detected