Skip to content

Commit c5469ea

Browse files
authored
chore: Add subcomponent attribute to LangChain tool traces (newrelic#3706)
1 parent 532729a commit c5469ea

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/subscribers/langchain/tool.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class LangchainToolSubscriber extends AiMonitoringSubscriber {
5656
input = JSON.stringify(request)
5757
}
5858

59+
segment.addSpanAttribute('subcomponent', `{"type":"APM-AI_TOOL","name":"${name}"}`)
5960
segment.end()
6061

6162
const toolEvent = new LangChainTool({

test/versioned/langchain/tools.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,21 @@ test('should properly merge tags from instance and params', (t, end) => {
273273
end()
274274
})
275275
})
276+
277+
test('should add subcomponent attribute to segment', (t, end) => {
278+
const { agent, tool, input } = t.nr
279+
helper.runInTransaction(agent, async (tx) => {
280+
await tool.call(input)
281+
282+
const [segment] = tx.trace.getChildren(tx.trace.root.id)
283+
const attributes = segment.attributes.get(DESTINATIONS.SPAN_EVENT)
284+
assert.ok(attributes.subcomponent, 'subcomponent attribute should exist')
285+
286+
const attr = JSON.parse(attributes.subcomponent)
287+
assert.equal(attr.type, 'APM-AI_TOOL', 'subcomponent type should be APM-AI_TOOL')
288+
assert.equal(attr.name, tool.name, 'subcomponent name should match tool name')
289+
290+
tx.end()
291+
end()
292+
})
293+
})

0 commit comments

Comments
 (0)