MCPcopy Create free account
hub / github.com/apache/skywalking-nodejs / install

Method install

src/plugins/MySQL2Plugin.ts:46–132  ·  view source on GitHub ↗
(installer: PluginInstaller)

Source from the content-addressed store, hash-verified

44 }
45
46 install(installer: PluginInstaller): void {
47 const Connection = (installer.require?.('mysql2') ?? require('mysql2')).Connection;
48 const _query = Connection.prototype.query;
49
50 Connection.prototype.query = function (sql: any, values: any, cb: any) {
51 let query: any;
52
53 const host = `${this.config.host}:${this.config.port}`;
54 const span = ContextManager.current.newExitSpan('mysql/query', Component.MYSQL);
55
56 span.start();
57
58 try {
59 span.component = Component.MYSQL;
60 span.layer = SpanLayer.DATABASE;
61 span.peer = host;
62
63 span.tag(Tag.dbType('Mysql'));
64 span.tag(Tag.dbInstance(`${this.config.database}`));
65
66 let _sql: any;
67 let _values: any;
68 let streaming: any;
69
70 if (typeof sql === 'function') {
71 sql = wrapCallback(span, sql, 0);
72 } else if (typeof sql === 'object') {
73 _sql = sql.sql;
74
75 if (typeof values === 'function') {
76 values = wrapCallback(span, values, 0);
77 _values = sql.values;
78 } else if (values !== undefined) {
79 _values = values;
80
81 if (typeof cb === 'function') {
82 cb = wrapCallback(span, cb, 0);
83 } else {
84 streaming = true;
85 }
86 } else {
87 streaming = true;
88 }
89 } else {
90 _sql = sql;
91
92 if (typeof values === 'function') {
93 values = wrapCallback(span, values, 0);
94 } else if (values !== undefined) {
95 _values = values;
96
97 if (typeof cb === 'function') {
98 cb = wrapCallback(span, cb, 0);
99 } else {
100 streaming = true;
101 }
102 } else {
103 streaming = true;

Callers

nothing calls this directly

Calls 8

wrapCallbackFunction · 0.90
wrapEmitFunction · 0.90
stringifyMethod · 0.80
errorMethod · 0.80
newExitSpanMethod · 0.65
startMethod · 0.65
stopMethod · 0.65
asyncMethod · 0.65

Tested by

no test coverage detected