Skip to content

Commit fbc82c2

Browse files
authored
fix(langchain, core): properly handle class expressions with orchestrion (#7339)
* support var class instance method patching * add additional test for non-var case
1 parent 137125b commit fbc82c2

6 files changed

Lines changed: 87 additions & 0 deletions

File tree

packages/datadog-instrumentations/src/helpers/rewriter/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ function fromFunctionQuery (functionQuery) {
127127
if (className) {
128128
queries.push(
129129
`[id.name="${className}"]`,
130+
`[id.name="${className}"] > ClassExpression`,
130131
`[id.name="${className}"] > ClassBody > [key.name="${methodName}"] > [async]`,
131132
`[id.name="${className}"] > ClassExpression > ClassBody > [key.name="${methodName}"] > [async]`
132133
)

packages/datadog-instrumentations/test/helpers/rewriter/index.spec.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,32 @@ describe('check-require-cache', () => {
6565
kind: 'Callback'
6666
},
6767
channelName: 'test_invoke'
68+
},
69+
{
70+
module: {
71+
name: 'test-trace-class-instance-method',
72+
versionRange: '>=0.1',
73+
filePath: 'index.js'
74+
},
75+
functionQuery: {
76+
className: 'Foo',
77+
methodName: 'test',
78+
kind: 'Sync'
79+
},
80+
channelName: 'test_invoke'
81+
},
82+
{
83+
module: {
84+
name: 'test-trace-var-class-instance-method',
85+
versionRange: '>=0.1',
86+
filePath: 'index.js'
87+
},
88+
functionQuery: {
89+
className: 'Foo',
90+
methodName: 'test',
91+
kind: 'Sync'
92+
},
93+
channelName: 'test_invoke'
6894
}
6995
]
7096
})
@@ -118,4 +144,34 @@ describe('check-require-cache', () => {
118144

119145
test.test(() => {})
120146
})
147+
148+
it('should auto instrument class instance methods', done => {
149+
const test = compile('test-trace-class-instance-method')
150+
151+
subs = {
152+
start () {
153+
done()
154+
}
155+
}
156+
157+
ch = tracingChannel('orchestrion:test-trace-class-instance-method:test_invoke')
158+
ch.subscribe(subs)
159+
160+
test.test()
161+
})
162+
163+
it('should auto instrument var class instance methods', done => {
164+
const test = compile('test-trace-var-class-instance-method')
165+
166+
subs = {
167+
start () {
168+
done()
169+
}
170+
}
171+
172+
ch = tracingChannel('orchestrion:test-trace-var-class-instance-method:test_invoke')
173+
ch.subscribe(subs)
174+
175+
test.test()
176+
})
121177
})

packages/datadog-instrumentations/test/helpers/rewriter/node_modules/test-trace-class-instance-method/index.js

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/datadog-instrumentations/test/helpers/rewriter/node_modules/test-trace-class-instance-method/package.json

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/datadog-instrumentations/test/helpers/rewriter/node_modules/test-trace-var-class-instance-method/index.js

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/datadog-instrumentations/test/helpers/rewriter/node_modules/test-trace-var-class-instance-method/package.json

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)