-
Notifications
You must be signed in to change notification settings - Fork 87
Adding Customer id & tags #261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @yifan1207, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
Summary of Changes
Hello team,
Gemini here, providing a summary of this pull request. This PR introduces functionality to associate customer IDs and tags with traces. The primary goal, as stated in the description, is to allow users to track customer usage of agents and categorize/filter traces more effectively. This is achieved by adding customer_id and tags fields to the trace data structure and providing methods to set and manage this metadata.
The changes involve modifying the core Trace and Tracer classes to accommodate these new fields and introducing a flexible set_metadata function, along with convenience methods like set_customer_id and set_tags. The metadata is included when traces are saved. A new demo script is also added to illustrate how to use this new feature.
Highlights
- Add Customer ID and Tags to Traces: The
Traceobject now includes optionalcustomer_id(string) andtags(list of strings) attributes to store user-defined metadata. - Implement
set_metadataFunction: A newset_metadatamethod is added to both theTraceandTracerclasses. This method allows settingcustomer_id,tags, and other supported trace metadata fields (likename,has_notification,overwrite,rules) using either a key-value pair or keyword arguments. TheTracerclass method acts as a proxy to set metadata on the currently active trace. - Add Convenience Methods for Metadata: Convenience methods
set_customer_idandset_tagsare added to theTracerclass, providing simpler ways to set these specific metadata fields on the current trace. - Include Metadata in Saved Traces: The
savemethod of theTraceclass is updated to include thecustomer_idandtagswhen sending trace data to the trace manager client. - Add
print_metadataHelper: Aprint_metadatamethod is added to bothTraceandTracerclasses to easily print the current trace's metadata for debugging and verification. - New Demo Script: A new demo file (
src/demo/customer_id_and_tags.py) is included to demonstrate how to use the newset_metadatafunction to add customer IDs and tags to a trace.
Changelog
Click here to see the changelog
- src/demo/customer_id_and_tags.py
- Added new demo script to showcase setting customer ID and tags on a trace using the new
set_metadatafunction.
- Added new demo script to showcase setting customer ID and tags on a trace using the new
- src/judgeval/common/tracer.py
- Added
customer_idandtagsattributes to theTraceclass. - Implemented
set_metadatamethod on theTraceclass to update various trace metadata fields. - Added
set_tagsconvenience method on theTraceclass. - Updated the
savemethod of theTraceclass to includecustomer_idandtagsin the saved payload. - Added
print_metadatamethod to theTraceclass for debugging. - Added proxy methods
set_customer_id,set_tags,set_metadata, andprint_metadatato theTracerclass to operate on the current trace. - Replaced
rprintwith standardprintin thelogmethod.
- Added
- src/judgeval/data/trace.py
- Added
customer_idfield to theTracePydantic model definition.
- Added
- trace_metadata.json
- Added new example output file showing saved trace metadata including customer ID and tags.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Trace flows like a stream,
Metadata, a helpful gleam,
Customer, tag, name,
Guiding the code's game,
Making sense of the dream.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces the ability to add customer ID and tags to traces, along with a set_metadata function to manage trace attributes. The changes look generally good and enhance the usability of tracing.
Summary of Findings
- Boolean Metadata Handling: The conversion of
has_notificationandoverwritemetadata values usingbool(v)can lead to misinterpretation if string inputs like "false" are provided. This should be made more robust. - Consistency for
NoneValues inset_metadata: Theset_metadatamethod inTraceClienthandles setting attributes toNonedifferently based on whether the(key, value)pair or**kwargsstyle is used. This inconsistency should be addressed. - Payload Change Confirmation: The
parent_namefield has been removed from thetrace_datapayload inTraceClient.save(). Confirmation is needed that this change is coordinated with backend API updates. - Attribute Initialization: The
has_notificationattribute could be initialized inTraceClient.__init__for consistency with other new metadata fields likecustomer_idandtags.
Merge Readiness
The pull request introduces valuable features for trace metadata. Before merging, I recommend addressing the identified high and medium severity issues, particularly concerning the boolean metadata handling and the consistency of None value processing in set_metadata. Also, please confirm the coordination of the parent_name payload change with the backend. Once these points are clarified and resolved, the PR should be in good shape. As an AI, I am not authorized to approve pull requests; please ensure further review and approval from team members.
JCamyre
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great Yifan! Couple small requests
trace_metadata.json
Outdated
| @@ -0,0 +1,11 @@ | |||
| { | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete this file
src/demo/customer_id_and_tags.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we removed the src/demo/ folder a few PRs ago.
I'm gonna move this script to the cookbooks repo!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also think we should remove this file in that case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okk!
4f7e7e8 to
0ca7539
Compare
367fb94 to
aee1ed5
Compare
JCamyre
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple quick questions, then good to merge :)
src/judgeval/common/tracer.py
Outdated
| - tags: List of tags for this trace | ||
| - has_notification: Whether this trace has a notification | ||
| - overwrite: Whether to overwrite existing traces | ||
| - rules: Rules for this trace |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this field relate to Minh's rules?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ohh like allow users to edit their rule as part of metadata if they need. should we allow this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not necessary!
src/judgeval/common/tracer.py
Outdated
| """ | ||
| self.set_metadata(tags=tags) | ||
|
|
||
| def print_metadata(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking either making this a private method _print_metadata or deleting entirely.
Do you see an application for this outside of debugging?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think people might want to use this to see what it is, just like a method od convenience?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so - when people are tracing their agents in production they don't want this extra info to clutter their logs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okok delted
src/judgeval/common/tracer.py
Outdated
| except Exception as e: | ||
| warnings.warn(f"Failed to send evaluation runs batch: {e}") | ||
|
|
||
| def _send_traces_batch(self, traces: List[Dict[str, Any]]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confused here - isn't this from Minh's PR? Not sure why it is showing as new here.
Also, does it make sense to send these in parallel
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ohh I think yeaa they are directly from minh's PR? I was making some edit to add compatibility to the semi saving trace span so that bscailly updating metadata would also use the queue to edit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting that it is showing that you added the entire function. Which file did you copy this function from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ohh my bad now I see it basically I can just use minh's queing functions deleted these!
JCamyre
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple last things!
src/judgeval/common/tracer.py
Outdated
| - tags: List of tags for this trace | ||
| - has_notification: Whether this trace has a notification | ||
| - overwrite: Whether to overwrite existing traces | ||
| - rules: Rules for this trace |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not necessary!
src/judgeval/common/tracer.py
Outdated
| """ | ||
| self.set_metadata(tags=tags) | ||
|
|
||
| def print_metadata(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so - when people are tracing their agents in production they don't want this extra info to clutter their logs.
src/judgeval/common/tracer.py
Outdated
| except Exception as e: | ||
| warnings.warn(f"Failed to send evaluation runs batch: {e}") | ||
|
|
||
| def _send_traces_batch(self, traces: List[Dict[str, Any]]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting that it is showing that you added the entire function. Which file did you copy this function from?
src/judgeval/common/tracer.py
Outdated
| } | ||
| self._span_queue.put(eval_data) | ||
|
|
||
| def queue_trace(self, trace_data: Dict[str, Any]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
src/judgeval/common/tracer.py
Outdated
| else: | ||
| warnings.warn("No current trace found, cannot set tags") | ||
|
|
||
| def print_metadata(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think we should delete
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okkk!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed!
JCamyre
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
📝 Summary
Adding cusomter id and tags columns in DB and adding set_metadata() function to enable users to update and set metadata of a trace including
Supported keys:
- customer_id: ID of the customer using this trace
- tags: List of tags for this trace
- has_notification: Whether this trace has a notification
- overwrite: Whether to overwrite existing traces
- rules: Rules for this trace
- name: Name of the trace
🎯 Purpose
give user ability to track customer usage of agents
give user ability to add tags to better carategotize and filter their traces
Merge with Judgment PR https://github.com/JudgmentLabs/judgment/pull/339
🎥 Demo of Changes
🧪 Testing
✅ Checklist
📌 Linear Issue
✏️ Additional Notes