newrelic 8.17.1 → 9.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,62 +0,0 @@
1
- /*
2
- * Copyright 2020 New Relic Corporation. All rights reserved.
3
- * SPDX-License-Identifier: Apache-2.0
4
- */
5
-
6
- 'use strict'
7
-
8
- // TODO: remove in favor of /lib/db/query-parsers/sql.js
9
- // This module is currently used only in the Oracle instrumentation
10
-
11
- const logger = require('../logger').child({ component: 'parse_sql' })
12
- const StatementMatcher = require('./statement-matcher')
13
- const ParsedStatement = require('./parsed-statement')
14
- const stringify = require('json-stringify-safe')
15
-
16
- const OPERATIONS = [
17
- new StatementMatcher('select', /^\s*select[\S\s]*from[\s\[]+([^\]\s,)(;]*).*/gi),
18
- new StatementMatcher('update', /^\s*update\s+([^\s,;]*).*/gi),
19
- new StatementMatcher('insert', /^\s*insert(?:\s+ignore)?\s+into\s+([^\s(,;]*).*/gi),
20
- new StatementMatcher('delete', /^\s*delete\s+from\s+([^\s,(;]*).*/gi)
21
- ]
22
- const COMMENT_PATTERN = /\/\\*.*?\\*\//
23
-
24
- // This must be called synchronously after the initial db call for backtraces to
25
- // work correctly
26
-
27
- module.exports = function parseSql(type, sql) {
28
- // Sometimes we get an object here from MySQL. We have been unable to
29
- // reproduce it, so we'll just log what that object is and return a statement
30
- // type of `other`.
31
- if (typeof sql === 'object' && sql.sql !== undefined) {
32
- sql = sql.sql
33
- }
34
- if (typeof sql !== 'string') {
35
- if (logger.traceEnabled()) {
36
- try {
37
- logger.trace('parseSQL got an a non-string sql that looks like: %s', stringify(sql))
38
- } catch (err) {
39
- logger.debug(err, 'Unabled to stringify SQL')
40
- }
41
- }
42
- return new ParsedStatement(type, 'other', null, sql)
43
- }
44
-
45
- sql = sql.replace(COMMENT_PATTERN, '').trim()
46
-
47
- let parsedStatement
48
-
49
- for (let i = 0, l = OPERATIONS.length; i < l; i++) {
50
- parsedStatement = OPERATIONS[i].getParsedStatement(sql)
51
- if (parsedStatement) {
52
- return new ParsedStatement(
53
- type,
54
- parsedStatement.operation,
55
- parsedStatement.collection,
56
- parsedStatement.query
57
- )
58
- }
59
- }
60
-
61
- return new ParsedStatement(type, 'other', null, sql)
62
- }
@@ -1,130 +0,0 @@
1
- /*
2
- * Copyright 2020 New Relic Corporation. All rights reserved.
3
- * SPDX-License-Identifier: Apache-2.0
4
- */
5
-
6
- 'use strict'
7
-
8
- const logger = require('../logger').child({ component: 'oracle' })
9
- const shimmer = require('../shimmer')
10
- const parseSql = require('../db/parse-sql')
11
- const ORACLE = require('../metrics/names').ORACLE
12
-
13
- module.exports = function initialize(agent, oracle) {
14
- const tracer = agent.tracer
15
- let wrapped = false
16
-
17
- logger.trace('wrapping oracle.connect and oracle.connectSync')
18
-
19
- shimmer.wrapMethod(oracle, 'Oracle', 'connect', function wrapMethod(connect) {
20
- return function wrappedConnect(connectData, cb) {
21
- return connect.call(this, connectData, tracer.bindFunction(wrapConnection))
22
-
23
- function wrapConnection(err, connection) {
24
- if (!err) {
25
- ensureConnectionWrapped(connection)
26
- }
27
- return cb(err, connection)
28
- }
29
- }
30
- })
31
-
32
- shimmer.wrapMethod(oracle, 'Oracle', 'connectSync', function wrapSyncConnect(connect) {
33
- return function wrappedSyncConnect() {
34
- const connection = connect.apply(this, arguments)
35
- ensureConnectionWrapped(connection)
36
- return connection
37
- }
38
- })
39
-
40
- function ensureConnectionWrapped(connection) {
41
- // return early in case called from an async connect after wrapping
42
- if (wrapped) {
43
- return
44
- }
45
- logger.trace('wrapping oracle connection prototype')
46
- wrapped = true
47
-
48
- oracle.connectSync.__NR_unwrap()
49
- oracle.connect.__NR_unwrap()
50
- shimmer.wrapMethod(oracle, 'Oracle', 'connect', function wrapMethod(connect) {
51
- return tracer.wrapFunctionNoSegment(connect, 'connect')
52
- })
53
-
54
- const proto = Object.getPrototypeOf(connection)
55
- wrapConnectionExecute(proto, tracer)
56
- wrapConnectionPrepare(proto, tracer)
57
-
58
- shimmer.wrapMethod(proto, 'Oracle', 'reader', function wrapMethod(createReader) {
59
- return function wrappedConnect(sql) {
60
- const reader = createReader.apply(this, arguments)
61
- wrapReader(reader, tracer, sql)
62
- return reader
63
- }
64
- })
65
- }
66
- }
67
-
68
- function wrapConnectionExecute(connection, tracer) {
69
- shimmer.wrapMethod(connection, 'Oracle.connection', 'execute', wrapExecute)
70
-
71
- function wrapExecute(execute) {
72
- return tracer.wrapFunction(ORACLE.STATEMENT + 'other/', null, execute, wrappedExecute)
73
- }
74
-
75
- function wrappedExecute(segment, args, bind) {
76
- const ps = parseSql(ORACLE.PREFIX, args[0])
77
- const collection = ps.collection
78
- const operation = ps.operation
79
-
80
- segment.name = ORACLE.STATEMENT + collection + '/Connection.execute/' + operation
81
- logger.trace('capturing oracle query. collection: %s, Operation: %s', collection, operation)
82
-
83
- segment.transaction.addRecorder(ps.recordMetrics.bind(ps, segment))
84
- args[2] = bind(args[2])
85
- return args
86
- }
87
- }
88
-
89
- function wrapReader(reader, tracer, sql) {
90
- const ps = parseSql(ORACLE.PREFIX, sql)
91
- shimmer.wrapMethod(reader, 'Oracle.Reader', 'nextRow', wrapNextRow)
92
- shimmer.wrapMethod(reader, 'Oracle.Reader', 'nextRows', wrapNextRows)
93
-
94
- function wrapNextRow(nextRow) {
95
- return tracer.wrapFunctionLast(
96
- ORACLE.STATEMENT + ps.collection + '/Reader.nextRow/' + ps.operation,
97
- ps.recordMetrics.bind(ps),
98
- nextRow
99
- )
100
- }
101
-
102
- function wrapNextRows(nextRows) {
103
- return tracer.wrapFunctionLast(
104
- ORACLE.STATEMENT + ps.collection + '/Reader.nextRows/' + ps.operation,
105
- ps.recordMetrics.bind(ps),
106
- nextRows
107
- )
108
- }
109
- }
110
-
111
- function wrapConnectionPrepare(connection, tracer) {
112
- shimmer.wrapMethod(connection, 'Oracle.connection', 'prepare', wrapPrepare)
113
-
114
- function wrapPrepare(prepare) {
115
- return function wrappedPrepare(sql) {
116
- const ps = parseSql(ORACLE.PREFIX, sql)
117
- const prepared = prepare.apply(this, arguments)
118
- shimmer.wrapMethod(prepared, 'Oracle', 'execute', wrapExecute)
119
- return prepared
120
-
121
- function wrapExecute(execute) {
122
- return tracer.wrapFunctionLast(
123
- ORACLE.STATEMENT + ps.collection + '/Statement.execute/' + ps.operation,
124
- ps.recordMetrics.bind(ps),
125
- execute
126
- )
127
- }
128
- }
129
- }
130
- }