Skip to content

feat(transformer): add objectName+propertyName selector to #fromFunctionQuery#58

Merged
bizob2828 merged 5 commits intonodejs:mainfrom
crysmags:fix/add-this-property-name
Apr 6, 2026
Merged

feat(transformer): add objectName+propertyName selector to #fromFunctionQuery#58
bizob2828 merged 5 commits intonodejs:mainfrom
crysmags:fix/add-this-property-name

Conversation

@crysmags
Copy link
Copy Markdown
Contributor

@crysmags crysmags commented Apr 6, 2026

What does this PR do?

Adds objectName and propertyName fields to #fromFunctionQuery in lib/transformer.js, generating an esquery selector that targets async functions assigned to a specific property on a specific object:

// objectName: 'this', propertyName: '_queryPromise'
AssignmentExpression[left.object.type=ThisExpression][left.property.name="_queryPromise"] > [async]

// objectName: 'conn', propertyName: 'query'
AssignmentExpression[left.object.name="conn"][left.property.name="query"] > [async]

this is handled as a special case because it is a ThisExpression node in the AST, not an Identifier — so it cannot be matched with left.object.name.

Why existing query types don't cover this

The target pattern is an arrow function assigned to an object property inside a function constructor:

function Connection(opts) {
  this._queryPromise = async (sql, values) => { ... }
}
  • methodName targets ClassBody > MethodDefinition and Property (object literal) nodes — a different AST shape entirely. Assignment expressions in constructors are not matched.
  • expressionName does generate AssignmentExpression[left.property.name="..."] selectors, but without any constraint on the receiver. In files where the same property name is assigned on multiple different objects, this produces false positives and instruments the wrong functions.

objectName + propertyName pins both the receiver and the property, giving a precise match equivalent to what className + methodName gives for class methods.

Usage

// matches: this._queryPromise = async () => {}
functionQuery: { objectName: 'this', propertyName: '_queryPromise', kind: 'Async' }

// matches: conn.query = async () => {}
functionQuery: { objectName: 'conn', propertyName: 'query', kind: 'Async' }

crysmags added 2 commits April 6, 2026 11:03
…transformer.js, generating an esquery selector that targets async functions assigned to a specific property on a specific object
Copy link
Copy Markdown
Contributor

@bizob2828 bizob2828 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@crysmags can you add tests that affect this new behavior?

@crysmags
Copy link
Copy Markdown
Contributor Author

crysmags commented Apr 6, 2026

Thank you for the review! Ready to merge when you are 🫡

@bizob2828 bizob2828 merged commit 3f0e14d into nodejs:main Apr 6, 2026
6 checks passed
crysmags added a commit to DataDog/dd-trace-js that referenced this pull request Apr 7, 2026
…trion-config

Replaces custom rewriter instrumentations/mariadb.js with entries in
orchestrion-config/index.js using the standard YAML format. thisPropertyName
is expressed as object_name/property_name per nodejs/orchestrion-js#58.
noCallbackFallback entries are marked with TODO comments pending
nodejs/orchestrion-js support.

Reverts rewriter changes to transformer.js, transforms.js,
instrumentations/index.js, and associated tests.
crysmags added a commit to DataDog/dd-trace-js that referenced this pull request Apr 7, 2026
…trion-config

Replaces custom rewriter instrumentations/mariadb.js with entries in
orchestrion-config/index.js using the standard YAML format. thisPropertyName
is expressed as object_name/property_name per nodejs/orchestrion-js#58.
noCallbackFallback entries are marked with TODO comments pending
nodejs/orchestrion-js support.

Reverts rewriter changes to transformer.js, transforms.js,
instrumentations/index.js, and associated tests.
@rochdev
Copy link
Copy Markdown
Contributor

rochdev commented Apr 7, 2026

Why add propertyName? Why not add only objectName and pair it with the existing methodName? Adding propertyName seems like an unnecessary addition to remember and it does the same thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants