dd-trace-py
dd-trace-py copied to clipboard
feat(anthropic): support user_id metadata tag
Summary
Add tag support for metdata.user_id in Anthropic message calls (seen here https://docs.anthropic.com/en/api/messages#body-metadata) so that you can filter traces by user_id properly.
Currently anthropic.request.paramters contains a string of the dict which can't be filtered. Similar to user being tracked as a tag in openai.request.user but for Anthropic.
Risks
See PR comment; Removes user_id from anthropic.request.params based on how it's coded. If people have trace filters, APM Metrics, etc by looking for user_id in their string already, it would break that. We could keep it in there for legacy reasons if needed.
Checklist
- [X] PR author has checked that all the criteria below are met
- The PR description includes an overview of the change
- The PR description articulates the motivation for the change
- The change includes tests OR the PR description describes a testing strategy
- The PR description notes risks associated with the change, if any
- Newly-added code is easy to change
- The change follows the library release note guidelines
- The change includes or references documentation updates if necessary
- Backport labels are set (if applicable)
Reviewer Checklist
- [ ] Reviewer has checked that all the criteria below are met
- Title is accurate
- All changes are related to the pull request's stated goal
- Avoids breaking API changes
- Testing strategy adequately addresses listed risks
- Newly-added code is easy to change
- Release note makes sense to a user of the library
- If necessary, author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment
- Backport labels are set in a manner that is consistent with the release branch maintenance policy