Skip to content

Commit

Permalink
feat: Added tool_id to langchain error event (#2064)
Browse files Browse the repository at this point in the history
  • Loading branch information
svetlanabrennan committed Mar 5, 2024
1 parent 3c50606 commit 793abe8
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/instrumentation/langchain/tools.js
Expand Up @@ -57,7 +57,7 @@ module.exports = function initialize(shim, tools) {
new LlmErrorMessage({
response: {},
cause: err,
summary: {}
tool: toolEvent
})
)
}
Expand Down
4 changes: 3 additions & 1 deletion lib/llm-events/error-message.js
Expand Up @@ -20,15 +20,17 @@ module.exports = class LlmErrorMessage {
* if it was an embedding conversation.
* @param {LlmVectorStoreSearch} [params.vectorsearch] Details about the vector
* search if it was a vector search event.
* @param {LlmTool} [params.tool] Details about the tool event if it was a tool event.
*/
constructor({ response, cause, summary, embedding, vectorsearch } = {}) {
constructor({ response, cause, summary, embedding, vectorsearch, tool } = {}) {
this['http.statusCode'] = response?.status ?? cause?.status
this['error.message'] = cause?.message
this['error.code'] = response?.code ?? cause?.error?.code
this['error.param'] = response?.param ?? cause?.error?.param
this.completion_id = summary?.id
this.embedding_id = embedding?.id
this.vector_store_id = vectorsearch?.id
this.tool_id = tool?.id
}

get [Symbol.toStringTag]() {
Expand Down
Expand Up @@ -6,8 +6,8 @@
'use strict'

const tap = require('tap')
const LlmErrorMessage = require('../../../../lib/llm-events/error-message')
const { req, chatRes } = require('./common')
const LlmErrorMessage = require('../../../lib/llm-events/error-message')
const { req, chatRes } = require('./openai/common')

tap.test('LlmErrorMessage', (t) => {
const res = { ...chatRes, code: 'insufficient_quota', param: 'test-param', status: 429 }
Expand All @@ -19,7 +19,8 @@ tap.test('LlmErrorMessage', (t) => {
'error.param': 'test-param',
'completion_id': undefined,
'embedding_id': undefined,
'vector_store_id': undefined
'vector_store_id': undefined,
'tool_id': undefined
}
t.same(errorMsg, expected)
t.end()
Expand Down
1 change: 1 addition & 0 deletions test/versioned/langchain/tools.tap.js
Expand Up @@ -163,6 +163,7 @@ tap.test('Langchain instrumentation - tools', (t) => {
t.equal(exceptions.length, 1)
const str = Object.prototype.toString.call(exceptions[0].customAttributes)
t.equal(str, '[object LlmErrorMessage]')
t.equal(exceptions[0].customAttributes.tool_id, toolEvent.id)

tx.end()
t.end()
Expand Down

0 comments on commit 793abe8

Please sign in to comment.