diff --git a/package.json b/package.json index 76257cd..0fe600e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@langtrase/typescript-sdk", - "version": "6.1.1", + "version": "6.2.0", "description": "A typescript SDK for Langtrace", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/instrumentation/vercel/anthropic.ts b/src/instrumentation/vercel/anthropic.ts index 18b16b4..8605865 100644 --- a/src/instrumentation/vercel/anthropic.ts +++ b/src/instrumentation/vercel/anthropic.ts @@ -69,11 +69,9 @@ export async function generateTextPatchAnthropic ( try { const resp = await originalMethod.apply(this, args) const responses = JSON.stringify(resp?.responseMessages) - span.addEvent(Event.GEN_AI_PROMPT, { - 'gen_ai.prompt': JSON.stringify([ - { role: 'user', content: args[0]?.prompt } - ]) - }) + // set content to either prompt or messages + const content = args[0]?.prompt ?? JSON.stringify(args[0]?.messages) + span.addEvent(Event.GEN_AI_PROMPT, { 'gen_ai.prompt': content }) span.addEvent(Event.GEN_AI_COMPLETION, { 'gen_ai.completion': responses }) const responseAttributes: Partial = { 'url.full': url, @@ -146,7 +144,8 @@ export async function streamTextPatchAnthropic ( return await context.with(trace.setSpan(context.active(), span), async () => { try { const resp: any = await originalMethod.apply(this, args) - addSpanEvent(span, Event.GEN_AI_PROMPT, { 'gen_ai.prompt': JSON.stringify(args[0]?.prompt) }) + const content = args[0]?.prompt ?? JSON.stringify(args[0]?.messages) + addSpanEvent(span, Event.GEN_AI_PROMPT, { 'gen_ai.prompt': content }) const responseAttributes: Partial = { 'url.full': url, 'url.path': APIS.anthropic.MESSAGES_CREATE.ENDPOINT @@ -231,11 +230,8 @@ export async function generateObjectPatchAnthropic ( try { const resp = await originalMethod.apply(this, args) const responses = JSON.stringify(resp?.object) - span.addEvent(Event.GEN_AI_PROMPT, { - 'gen_ai.prompt': JSON.stringify([ - { role: 'user', content: args[0]?.prompt } - ]) - }) + const content = args[0]?.prompt ?? JSON.stringify(args[0]?.messages) + span.addEvent(Event.GEN_AI_PROMPT, { 'gen_ai.prompt': content }) span.addEvent(Event.GEN_AI_COMPLETION, { 'gen_ai.completion': responses }) const responseAttributes: Partial = { 'url.full': url, @@ -308,7 +304,8 @@ export async function streamObjectPatchAnthropic ( return await context.with(trace.setSpan(context.active(), span), async () => { try { const resp: any = await originalMethod.apply(this, args) - addSpanEvent(span, Event.GEN_AI_PROMPT, { 'gen_ai.prompt': JSON.stringify(args[0]?.prompt) }) + const content = args[0]?.prompt ?? JSON.stringify(args[0]?.messages) + addSpanEvent(span, Event.GEN_AI_PROMPT, { 'gen_ai.prompt': content }) const responseAttributes: Partial = { 'url.full': url, 'url.path': APIS.anthropic.MESSAGES_CREATE.ENDPOINT