Skip to content

Commit 313fe22

Browse files
authored
fix: fix minor azure-function and mariadb bugs (#7007)
Azure functions was in some circumstances attaching the span to a parent span instead of acting as a root span by missing a return statement. Mariadb v2 did not track promise errors in all cases. This was detected by adding the no-unused-expressions lint rule. To address confusion, JSDoc was added about childOf being `null` and its meaning. In addition, the azure tests are now using the latest version again, since their library fixed the former support range issue. The void is now allowed as statement to address issues around e.g., `error.stack` access for triggering the stack calculation.
1 parent da07fea commit 313fe22

File tree

17 files changed

+471
-50
lines changed

17 files changed

+471
-50
lines changed

eslint.config.mjs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,6 @@ export default [
6767
eslintPluginJs.configs.recommended,
6868
eslintPluginJSDoc.configs['flat/recommended'],
6969
{
70-
// The following config and rules have been inlined from `eslint-config-standard` with the following modifications:
71-
// - Rules that were overridden elsewhere in this file have been removed.
72-
// - Deprecated rules have been replaced with their official replacements.
73-
//
74-
// We've inlined these to avoid having to depend on `eslint-config-standard` as:
75-
// 1. It's no longer maintained.
76-
// 2. It came with an older bundled version of `eslint-plugin-n` which conflicted with our version.
77-
//
7870
// TODO: Move these rules to dd-trace/defaults or where they otherwise belong.
7971
name: 'standard',
8072
languageOptions: {
@@ -337,7 +329,7 @@ export default [
337329
'packages/datadog-plugin-next/test/app/**/*.js',
338330
'packages/datadog-plugin-next/test/**/pages/**/*.js',
339331
'packages/datadog-plugin-next/test/middleware.js',
340-
'**/*.mjs', // TODO: This shoudln't be required, research why it is
332+
'**/*.mjs', // TODO: This shouldn't be required, research why it is
341333
],
342334
},
343335
{
@@ -458,7 +450,9 @@ export default [
458450
'no-await-in-loop': 'error',
459451
'no-else-return': ['error', { allowElseIf: true }],
460452
'no-implicit-coercion': ['error', { boolean: true, number: true, string: true, allow: ['!!'] }],
453+
'no-unused-expressions': 'error',
461454
'no-useless-assignment': 'error',
455+
'no-void': ['error', { allowAsStatement: true }],
462456
'operator-assignment': 'error',
463457
'prefer-exponentiation-operator': 'error',
464458
'prefer-object-has-own': 'error',

packages/datadog-instrumentations/src/couchbase.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ function wrap (prefix, fn) {
9898
return fn.apply(this, arguments)
9999
} catch (error) {
100100
ctx.error = error
101-
error.stack // trigger getting the stack at the original throwing point
101+
void error.stack // trigger getting the stack at the original throwing point
102102
errorCh.publish(ctx)
103103

104104
throw error
@@ -164,7 +164,7 @@ function wrapCBandPromise (fn, name, startData, thisArg, args) {
164164
)
165165
return res
166166
} catch (e) {
167-
e.stack
167+
void e.stack
168168
ctx.error = e
169169
errorCh.publish(ctx)
170170
throw e
@@ -228,7 +228,7 @@ addHook({ name: 'couchbase', file: 'lib/bucket.js', versions: ['^2.6.12'] }, Buc
228228
try {
229229
return _n1qlReq.apply(this, arguments)
230230
} catch (err) {
231-
err.stack // trigger getting the stack at the original throwing point
231+
void err.stack // trigger getting the stack at the original throwing point
232232
ctx.error = err
233233
errorCh.publish(ctx)
234234

packages/datadog-instrumentations/src/dns.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ function wrap (prefix, fn, expectedArgs, rrtype) {
8585
return fn.apply(this, arguments)
8686
// TODO deal with promise versions when we support `dns/promises`
8787
} catch (error) {
88-
error.stack // trigger getting the stack at the original throwing point
88+
void error.stack // trigger getting the stack at the original throwing point
8989
ctx.error = error
9090
errorCh.publish(ctx)
9191

packages/datadog-instrumentations/src/elasticsearch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ function createWrapRequest (name) {
9999
}
100100
return promise
101101
} catch (err) {
102-
err.stack // trigger getting the stack at the original throwing point
102+
void err.stack // trigger getting the stack at the original throwing point
103103
errorCh.publish(err)
104104

105105
throw err

packages/datadog-instrumentations/src/graphql.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ function wrapParse (parse) {
105105

106106
return ctx.document
107107
} catch (err) {
108-
err.stack
108+
void err.stack
109109
ctx.error = err
110110
parseErrorCh.publish(ctx)
111111

@@ -134,7 +134,7 @@ function wrapValidate (validate) {
134134
}
135135
return errors
136136
} catch (err) {
137-
err.stack
137+
void err.stack
138138
ctx.error = err
139139
validateErrorCh.publish(ctx)
140140

packages/datadog-instrumentations/src/mariadb.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function createWrapQuery (options) {
6565
finishCh.publish(ctx)
6666
return result
6767
}, error => {
68-
ctx.error
68+
ctx.error = error
6969
errorCh.publish(ctx)
7070
finishCh.publish(ctx)
7171
throw error

packages/datadog-instrumentations/src/mysql.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ addHook({ name: 'mysql', file: 'lib/Connection.js', versions: ['>=2'] }, Connect
4444

4545
return res
4646
} catch (err) {
47-
err.stack // trigger getting the stack at the original throwing point
47+
void err.stack // trigger getting the stack at the original throwing point
4848
ctx.error = err
4949
errorCh.publish(ctx)
5050

packages/datadog-plugin-azure-functions/src/index.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,11 @@ function mapTriggerTag (methodName) {
113113
}
114114

115115
function extractTraceContext (tracer, ctx) {
116-
switch (String(triggerMap[ctx.methodName])) {
117-
case 'Http':
118-
return tracer.extract('http_headers', Object.fromEntries(ctx.httpRequest.headers))
119-
default:
120-
null
116+
if (triggerMap[ctx.methodName] === 'Http') {
117+
return tracer.extract('http_headers', Object.fromEntries(ctx.httpRequest.headers))
121118
}
119+
// Returning null indicates that the span is a root span
120+
return null
122121
}
123122

124123
// message & messages & batch with cardinality of 1 == applicationProperties

packages/datadog-plugin-azure-functions/test/integration-test/eventhubs-test/eventhubs.spec.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,12 @@ const {
1212
curlAndAssertMessage,
1313
} = require('../../../../../integration-tests/helpers')
1414
const { withVersions } = require('../../../../dd-trace/test/setup/mocha')
15-
const { NODE_MAJOR } = require('../../../../../version')
1615

1716
describe('esm', () => {
1817
let agent
1918
let proc
2019

21-
// TODO: Allow newer versions in Node.js 18 when their breaking change is reverted.
22-
// See https://github.com/Azure/azure-functions-nodejs-library/pull/357
23-
withVersions('azure-functions', '@azure/functions', NODE_MAJOR < 20 ? '<4.7.3' : '*', version => {
20+
withVersions('azure-functions', '@azure/functions', version => {
2421
useSandbox([
2522
`@azure/functions@${version}`,
2623
'azure-functions-core-tools@4',

packages/datadog-plugin-azure-functions/test/integration-test/http-test/client.spec.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,12 @@ const {
1111
curlAndAssertMessage,
1212
} = require('../../../../../integration-tests/helpers')
1313
const { withVersions } = require('../../../../dd-trace/test/setup/mocha')
14-
const { NODE_MAJOR } = require('../../../../../version')
1514

1615
describe('esm', () => {
1716
let agent
1817
let proc
1918

20-
// TODO: Allow newer versions in Node.js 18 when their breaking change is reverted.
21-
// See https://github.com/Azure/azure-functions-nodejs-library/pull/357
22-
withVersions('azure-functions', '@azure/functions', NODE_MAJOR < 20 ? '<4.7.3' : '*', version => {
19+
withVersions('azure-functions', '@azure/functions', version => {
2320
useSandbox([
2421
`@azure/functions@${version}`,
2522
'azure-functions-core-tools@4',

0 commit comments

Comments
 (0)