Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion content/en/llm_observability/instrumentation/sdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -1836,6 +1836,24 @@ def rag_workflow(user_question):

{{< /code-block >}}

To annotate session ID on auto-instrumented spans, provide the `session_id` tag:

{{< code-block lang="python" >}}
from ddtrace.llmobs import LLMObs
from ddtrace.llmobs.decorators import workflow

@workflow
def run_chat(user_question, session_id):
with LLMObs.annotation_context(
tags = {
"session_id": session_id
},
):
completion = openai_client.chat.completions.create(...)
return completion.choices[0].message.content

{{< /code-block >}}

{{% /tab %}}

{{% tab "Node.js" %}}
Expand Down Expand Up @@ -1874,14 +1892,34 @@ function ragWorkflow(userQuestion) {
},
name: "augmented_generation"
}, async () => {
const completion = await openai_client.chat.completions.create(...);
const completion = await openaiClient.chat.completions.create(...);
return completion.choices[0].message.content;
});
}

{{< /code-block >}}

To annotate session ID on auto-instrumented spans, provide the `session_id` tag:

{{< code-block lang="javascript" >}}
const { llmobs } = require('dd-trace');

async function runChat(userQuestion, sessionId) {
return llmobs.annotationContext({
const completion = await llmobs.annotationContext({
tags: {
session_id: sessionId
}
}, async () => {
const completion = await openaiClient.chat.completions.create(...);
return completion.choices[0].message.content;
});
}

{{< /code-block >}}

{{% /tab %}}

{{< /tabs >}}

## Prompt tracking
Expand Down
Loading