Skip to content

Conversation

emhagman
Copy link

@emhagman emhagman commented Jun 26, 2025

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.

ddtrace_anthropic_userid

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

  • 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

@emhagman emhagman requested review from a team as code owners June 26, 2025 17:53
@emhagman emhagman requested review from avara1986 and sabrenner June 26, 2025 17:53
@@ -88,6 +88,10 @@ def tag_params_on_span(span, kwargs, integration):
for k, v in kwargs.items():
if k == "system" and integration.is_pc_sampled_span(span):
span.set_tag_str("anthropic.request.system", integration.trunc(str(v)))
elif k == "metadata" and isinstance(v, dict):
Copy link
Author

@emhagman emhagman Jun 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does remove it from anthropic.request.params, not sure if we should include it for legacy reasons in case anyone was using string matching here in their traces (@anthropic.request.params:"...") or if it's OK to change this.

@github-actions github-actions bot added the stale label Aug 1, 2025
Copy link
Contributor

github-actions bot commented Aug 3, 2025

This pull request has been automatically closed after a period of inactivity.
After this much time, it will likely be easier to open a new pull request with the
same changes than to update this one from the base branch. Please comment or reopen
if you think this pull request was closed in error.

@github-actions github-actions bot closed this Aug 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants