Skip to content

Commit acca3df

Browse files
rochdevtlhunter
authored andcommitted
fix grpc custom errors not being reported (#3230)
1 parent 1518fc0 commit acca3df

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

packages/datadog-instrumentations/src/grpc/server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ function wrapStream (call, requestResource, onCancel) {
107107
function wrapCallback (callback, call, requestResource, parentResource, onCancel) {
108108
return function (err, value, trailer, flags) {
109109
requestResource.runInAsyncScope(() => {
110-
if (err instanceof Error) {
110+
if (err) {
111111
errorChannel.publish(err)
112112
finishChannel.publish(err)
113113
} else {

packages/datadog-plugin-grpc/test/server.spec.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,27 @@ describe('Plugin', () => {
250250
})
251251
})
252252

253+
it('should handle custom errors', async () => {
254+
const client = await buildClient({
255+
getUnary: (_, callback) => {
256+
const metadata = new grpc.Metadata()
257+
258+
metadata.set('extra', 'information')
259+
260+
callback({ message: 'foobar', code: grpc.status.NOT_FOUND }, {}, metadata)
261+
}
262+
})
263+
264+
client.getUnary({ first: 'foobar' }, () => {})
265+
266+
return agent
267+
.use(traces => {
268+
expect(traces[0][0]).to.have.property('error', 1)
269+
expect(traces[0][0].meta).to.have.property(ERROR_MESSAGE, 'foobar')
270+
expect(traces[0][0].metrics).to.have.property('grpc.status.code', 5)
271+
})
272+
})
273+
253274
it('should handle stream errors', async () => {
254275
let error = null
255276

packages/dd-trace/src/util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function isError (value) {
1616
if (value instanceof Error) {
1717
return true
1818
}
19-
if (value && value.message && value.stack) {
19+
if (value && value.message) {
2020
return true
2121
}
2222
return false

0 commit comments

Comments
 (0)