Monitoring
Tags
A Tag object includes the tag’s key, and its value. You can use tags to add extra information to a trace or request.
client.tag(key: str, value: str, metadata: Dict, tag_type: str) -> Tag:
Arguments
key
string
requiredvalue
string/numeric/boolean/object/array
requiredmetadata
object
tag_type
string
The type of tag. Default tag types are tag
, log
, variable
, and
feedback
.
Instructions
With a traced OpenAI client, after it is created:
client.tag (key="project", value="customer support")
Adding tags to a completed trace or completion
After a trace or completion has completed, you may want to add extra tags based on feedback collected later. To do this, store the trace_id
and, for completions, the completion_id
. Use the tag
, log
, or feedback
functions to add tags, specifying trace_id
and completion_id
as needed.
from baserun import OpenAI, log, feedback
client = OpenAI(name="trace to be resumed")
completion = client.chat.completions.create(
name="completion to be resumed",
model="gpt-4o",
messages=[{"role": "user", "content": "What are three activities to do in Paris?"}],
)
# Store these values
trace_id = client.trace_id
completion_id = completion.completion_id
# A few moments later...
log("Tagging resumed", trace_id=trace_id, completion_id=completion_id)
feedback("User satisfaction", 0.9, trace_id=trace_id, completion_id=completion_id)