From 793abe8c9854b80fb1cf42f839a7db6a646cdc0b Mon Sep 17 00:00:00 2001 From: Svetlana Brennan <50715937+svetlanabrennan@users.noreply.github.com> Date: Tue, 5 Mar 2024 11:45:57 -0600 Subject: [PATCH] feat: Added tool_id to langchain error event (#2064) --- lib/instrumentation/langchain/tools.js | 2 +- lib/llm-events/error-message.js | 4 +++- test/unit/llm-events/{openai => }/error.test.js | 7 ++++--- test/versioned/langchain/tools.tap.js | 1 + 4 files changed, 9 insertions(+), 5 deletions(-) rename test/unit/llm-events/{openai => }/error.test.js (76%) diff --git a/lib/instrumentation/langchain/tools.js b/lib/instrumentation/langchain/tools.js index d15cd1c73..3abb65df7 100644 --- a/lib/instrumentation/langchain/tools.js +++ b/lib/instrumentation/langchain/tools.js @@ -57,7 +57,7 @@ module.exports = function initialize(shim, tools) { new LlmErrorMessage({ response: {}, cause: err, - summary: {} + tool: toolEvent }) ) } diff --git a/lib/llm-events/error-message.js b/lib/llm-events/error-message.js index cf28e7012..6d355448a 100644 --- a/lib/llm-events/error-message.js +++ b/lib/llm-events/error-message.js @@ -20,8 +20,9 @@ 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 @@ -29,6 +30,7 @@ module.exports = class LlmErrorMessage { this.completion_id = summary?.id this.embedding_id = embedding?.id this.vector_store_id = vectorsearch?.id + this.tool_id = tool?.id } get [Symbol.toStringTag]() { diff --git a/test/unit/llm-events/openai/error.test.js b/test/unit/llm-events/error.test.js similarity index 76% rename from test/unit/llm-events/openai/error.test.js rename to test/unit/llm-events/error.test.js index 24d4a634d..6ec461e45 100644 --- a/test/unit/llm-events/openai/error.test.js +++ b/test/unit/llm-events/error.test.js @@ -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 } @@ -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() diff --git a/test/versioned/langchain/tools.tap.js b/test/versioned/langchain/tools.tap.js index 0f2b680ee..0028d520b 100644 --- a/test/versioned/langchain/tools.tap.js +++ b/test/versioned/langchain/tools.tap.js @@ -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()