Learn how to attach prompt ids and prompt versions to traces in Langtrace. You can use the withAdditionalAttributes or inject_additional_attributes function to pass prompt ids / versions. This can inturn be used within Langtrace for filtering and grouping traces.
You can attach prompt ids and prompt versions to traces in Langtrace by simply wrapping your code with the withAdditionalAttributes for typescript or inject_additional_attributes function for python. This will add the specified attributes to the trace spans. Make sure to pass the prompt id or prompt versions as a key-value pair to the function.The keys are prompt_id and prompt_version and the values should be the prompt id and version respectively.
Copy
import * as Langtrace from "@langtrase/typescript-sdk";import OpenAI from 'openai'Langtrace.init({ write_spans_to_console: true,})const openai = new OpenAI()export const run = async ()=>{ const response = await Langtrace.withAdditionalAttributes(async () => { return await openai.chat.completions.create({ model: 'gpt-4', messages: [ { role: 'system', content: 'Talk like a pirate' }, { role: 'user', content: 'Tell me a story in 3 sentences or less.' } ], stream: false }) }, { prompt_id: "prompt1234", prompt_version: "1" })}run().then(() => console.log('done'))
DO NOT USE this the Python decorator - with_additional_attributes. It will be
deprecated soon. Please use inject_additional_attributes function instead.
Now, you can filter and group traces based on the prompt id. This can be useful for debugging and monitoring purposes.