diff --git a/lib/llm/event.js b/lib/llm/event.js index afb9385121..24ff0fa327 100644 --- a/lib/llm/event.js +++ b/lib/llm/event.js @@ -92,6 +92,16 @@ class LlmEvent { const attrs = tx?.trace?.custom.get(0x01 | 0x02 | 0x04 | 0x08) return attrs?.['llm.conversation_id'] } + + /** + * Removes the complex objects from the event + * This will be called right before the event is enqueued to the custom event aggregator + */ + serialize() { + delete this.bedrockCommand + delete this.bedrockResponse + delete this.constructionParams + } } module.exports = LlmEvent diff --git a/lib/v3/bedrock.js b/lib/v3/bedrock.js index e53d54af4a..a44356cdc8 100644 --- a/lib/v3/bedrock.js +++ b/lib/v3/bedrock.js @@ -34,6 +34,7 @@ function shouldSkipInstrumentation(config) { * @param {object} params.msg LLM event */ function recordEvent({ agent, type, msg }) { + msg.serialize() agent.customEventAggregator.add([{ type, timestamp: Date.now() }, msg]) } diff --git a/tests/unit/llm/event.tap.js b/tests/unit/llm/event.tap.js index c4a19d855e..547574839a 100644 --- a/tests/unit/llm/event.tap.js +++ b/tests/unit/llm/event.tap.js @@ -71,3 +71,12 @@ tap.test('create creates a new instance', async (t) => { t.equal(event['request.max_tokens'], null) t.equal(event.error, false) }) + +tap.test('serializes the event', (t) => { + const event = new LlmEvent(t.context) + event.serialize() + t.notOk(event.bedrockCommand) + t.notOk(event.bedrockResponse) + t.notOk(event.constructionParams) + t.end() +})