MCPcopy Index your code
hub / github.com/apache/skywalking-nodejs / install

Method install

src/plugins/PgPlugin.ts:32–108  ·  view source on GitHub ↗
(installer: PluginInstaller)

Source from the content-addressed store, hash-verified

30 readonly versions = '*';
31
32 install(installer: PluginInstaller): void {
33 const Client = installer.require?.('pg/lib/client') ?? require('pg/lib/client');
34
35 let Cursor: any;
36
37 try {
38 Cursor = installer.require?.('pg-cursor') ?? require('pg-cursor');
39 } catch {
40 /* Linter food */
41 }
42
43 const _query = Client.prototype.query;
44
45 Client.prototype.query = function (config: any, values: any, callback: any) {
46 let query: any;
47
48 const host = `${this.host}:${this.port}`;
49 const span = ContextManager.current.newExitSpan('pg/query', Component.POSTGRESQL);
50
51 span.start();
52
53 try {
54 span.component = Component.POSTGRESQL;
55 span.layer = SpanLayer.DATABASE;
56 span.peer = host;
57
58 span.tag(Tag.dbType('PostgreSQL'));
59 span.tag(Tag.dbInstance(`${this.connectionParameters.database}`));
60
61 let _sql: any;
62 let _values: any;
63
64 if (typeof config === 'string') _sql = config;
65 else if (config !== null && config !== undefined) {
66 _sql = config.text;
67 _values = config.values;
68
69 if (typeof config.callback === 'function') config.callback = wrapCallback(span, config.callback, 0);
70 }
71
72 if (typeof values === 'function') values = wrapCallback(span, values, 0);
73 else if (values !== undefined) _values = values;
74
75 if (typeof callback === 'function') callback = wrapCallback(span, callback, 0);
76
77 span.tag(Tag.dbStatement(`${_sql}`));
78
79 if (agentConfig.sqlTraceParameters && _values) {
80 let vals = _values.map((v: any) => (v === undefined ? 'undefined' : JSON.stringify(v))).join(', ');
81
82 if (vals.length > agentConfig.sqlParametersMaxLength)
83 vals = vals.slice(0, agentConfig.sqlParametersMaxLength) + ' ...';
84
85 span.tag(Tag.dbSqlParameters(`[${vals}]`));
86 }
87
88 query = _query.call(this, config, values, callback);
89

Callers

nothing calls this directly

Calls 9

wrapCallbackFunction · 0.90
wrapEmitFunction · 0.90
wrapPromiseFunction · 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