apps/opik-documentation/documentation/fern/docs/tracing/annotate_traces.mdx
Logging user feedback and scoring traces is a crucial aspect of evaluating and improving your agent. By systematically recording qualitative or quantitative feedback on specific interactions or entire conversation flows, you can:
You can use the SDKs to log user feedback and score traces:
<CodeBlocks> ```typescript title="Typescript SDK" language="typescript" import { Opik } from "opik";const client = new Opik();
// Create a new trace with a span const trace = client.trace({ name: "my_trace", input: { input: "Hi!" }, output: { output: "Hello!" }, });
const span = trace.span({ name: "processing", input: { step: 1 }, }); span.update({ output: { result: "processed" } }); span.end(); trace.end();
// Log feedback scores to existing traces client.logTracesFeedbackScores([ { id: trace.data.id, name: "overall_quality", value: 0.9, reason: "Good answer" }, { id: trace.data.id, name: "coherence", value: 0.8 } ]);
// Log feedback scores to existing spans client.logSpansFeedbackScores([ { id: span.data.id, name: "accuracy", value: 0.95 } ]);
// Flush to ensure all data is sent await client.flush();
```python title="Python Function Decorator" language="python"
import opik
from opik import opik_context
@opik.track
def my_function():
opik_context.update_current_trace(
feedback_scores=[
{
"name": "user_feedback",
"value": 1,
"reason": "Good answer" # Optional
}
]
)
return "Hello, world!"
import opik
client = opik.Opik()
# Log feedback scores to an existing trace
client.log_traces_feedback_scores(
scores=[
{"id": "trace_id", "name": "user_feedback", "value": 1, "project_name": "my-project"},
{"id": "trace_id", "name": "accuracy", "value": 1, "reason": "Good answer", "project_name": "my-project"} # Optional reason score
]
)
# Log feedback score to a new trace
client.trace(
name="my_trace",
input={"input": "Hi!"},
output={"output": "Hello!"},
feedback_scores=[
{"name": "user_feedback", "value": 1, "reason": "Good answer"}
]
)
To annotate traces through the UI, you can navigate to the trace you want to annotate in the traces
page and click on the Annotate button. This will open a sidebar where you can add annotations to
the trace.
You can annotate both traces and spans through the UI, make sure you have selected the correct span in the sidebar.
<Frame> </Frame>Once a feedback scores has been provided, you can also add a reason to explain why this particular score was provided. This is useful to add additional context to the score.
If multiple team members are annotating the same trace, you can see the annotations of each team
member in the UI in the Feedback scores section. The average score will be displayed at a trace
and trace level.
You don't need to manually annotate each trace to measure the performance of your agents! By using Opik's online evaluation feature, you can define LLM as a Judge metrics that will automatically score all, or a subset, of your production traces.
While online evaluation automatically scores traces based on sampling rates and enabled rules, manual evaluation gives you complete control over which traces or threads get evaluated and when. This is particularly useful when you want to:
Manual evaluation allows you to apply any existing evaluation rule to selected traces or threads directly from the UI, bypassing sampling rates and rule enablement status. You can trigger manual evaluation from:
When you trigger manual evaluation:
This gives you the flexibility to evaluate exactly what you need, when you need it, without waiting for the next sampled trace or modifying your online evaluation configuration.
You can go one step further and: