Skip to content

Commit 1b0738c

Browse files
committed
fix(wrapQuery): fix when no readStream or promise is returned
1 parent 858e73a commit 1b0738c

File tree

4 files changed

+38
-20
lines changed

4 files changed

+38
-20
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,7 @@ Desktop.ini
2929
.idea
3030
*.iml
3131
.vscode
32+
33+
# RCs
34+
.nvmrc
35+
.npmrc

.npmignore

+4
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,7 @@ Desktop.ini
4444
.idea
4545
*.iml
4646
.vscode
47+
48+
#RCs
49+
.nvmrc
50+
.npmrc

lib/instrumentations/utils/wrapQuery.js

+29-19
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ function wrapQuery (original, args, agent, params) {
5151
} else if (continuationMethod === 'readStream') {
5252
return wrapReadStream.call(this, original, args, reporter)
5353
} else if (continuationMethod === 'callback') { // uses callback
54-
return wrapCallback.call(this, original, _params, args, reporter)
54+
return wrapCallback.call(this, original, args, reporter)
5555
} else {
5656
return original.apply(this, args) // we might not want to instrument the method
5757
}
5858
}
5959

60-
function wrapCallback (original, params, args, reporter) {
60+
function wrapCallback (original, args, reporter) {
6161
var wrappedCallback = function (original) {
6262
return function (err) {
6363
reporter.reportReceive(err)
@@ -78,33 +78,43 @@ function wrapCallback (original, params, args, reporter) {
7878
}
7979

8080
function wrapPromise (original, args, reporter) {
81-
reporter.reportSend()
8281
var originalPromise = original.apply(this, args)
83-
return originalPromise.then(
84-
function (v) { reporter.reportReceive(); return v },
85-
function (err) { reporter.reportReceive(err); throw err }
86-
)
82+
if (originalPromise) {
83+
reporter.reportSend()
84+
return originalPromise.then(
85+
function (v) {
86+
reporter.reportReceive()
87+
return v
88+
},
89+
function (err) {
90+
reporter.reportReceive(err)
91+
throw err
92+
}
93+
)
94+
}
8795
}
8896

8997
function wrapReadStream (original, args, reporter) {
90-
reporter.reportSend()
9198
var originalStream = original.apply(this, args)
9299

93-
originalStream.on('end', function () {
94-
reporter.reportReceive()
95-
})
100+
if (originalStream) {
101+
reporter.reportSend()
102+
originalStream.on('end', function () {
103+
reporter.reportReceive()
104+
})
96105

97-
originalStream.on('error', function (err) {
98-
reporter.reportReceive(err)
106+
originalStream.on('error', function (err) {
107+
reporter.reportReceive(err)
99108

100-
if (typeof originalStream.listenerCount === 'function') {
101-
if (originalStream.listenerCount('error') < 2) {
109+
if (typeof originalStream.listenerCount === 'function') {
110+
if (originalStream.listenerCount('error') < 2) {
111+
throw err
112+
}
113+
} else if (EventEmitter.listenerCount(originalStream, 'error') < 2) {
102114
throw err
103115
}
104-
} else if (EventEmitter.listenerCount(originalStream, 'error') < 2) {
105-
throw err
106-
}
107-
})
116+
})
117+
}
108118

109119
return originalStream
110120
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@risingstack/trace",
3-
"version": "2.33.0",
3+
"version": "3.0.2",
44
"author": "RisingStack, Inc.",
55
"license": "SEE LICENSE IN LICENSE",
66
"contributors": "RisingStack",

0 commit comments

Comments
 (0)