Skip to content

chore(llmobs): dac strip io from anthropic #13767

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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

jsimpher
Copy link
Contributor

@jsimpher jsimpher commented Jun 25, 2025

Remove potentially sensitive i/o data from apm spans. This way, prompt and completion data will only appear on the llm obs spans, which are/will be subject to data access controls.

Mostly, this just removes io tag sets. A few things (mostly metrics) have llmobs tags dependent on span tags, so there is a bit more refactoring there.

Let me know if I removed anything that should really stay, or if I missed something that should be restricted.

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

Copy link
Contributor

github-actions bot commented Jun 25, 2025

CODEOWNERS have been resolved as:

releasenotes/notes/remove-io-data-from-span-anthropic-integration-a8b9ccdd3ac1d22d.yaml  @DataDog/apm-python
ddtrace/contrib/internal/anthropic/_streaming.py                        @DataDog/ml-observability
ddtrace/contrib/internal/anthropic/patch.py                             @DataDog/ml-observability
ddtrace/contrib/internal/anthropic/utils.py                             @DataDog/ml-observability
ddtrace/llmobs/_integrations/anthropic.py                               @DataDog/ml-observability
tests/snapshots/tests.contrib.anthropic.test_anthropic.test_anthropic_llm.json  @DataDog/ml-observability
tests/snapshots/tests.contrib.anthropic.test_anthropic.test_anthropic_llm_create_image.json  @DataDog/ml-observability
tests/snapshots/tests.contrib.anthropic.test_anthropic.test_anthropic_llm_error.json  @DataDog/ml-observability
tests/snapshots/tests.contrib.anthropic.test_anthropic.test_anthropic_llm_multiple_prompts.json  @DataDog/ml-observability
tests/snapshots/tests.contrib.anthropic.test_anthropic.test_anthropic_llm_multiple_prompts_with_chat_history.json  @DataDog/ml-observability
tests/snapshots/tests.contrib.anthropic.test_anthropic.test_anthropic_llm_stream.json  @DataDog/ml-observability
tests/snapshots/tests.contrib.anthropic.test_anthropic.test_anthropic_llm_stream_helper.json  @DataDog/ml-observability
tests/snapshots/tests.contrib.anthropic.test_anthropic.test_anthropic_llm_tools.json  @DataDog/ml-observability
tests/snapshots/tests.contrib.anthropic.test_anthropic.test_anthropic_llm_tools_full_use.json  @DataDog/ml-observability
tests/snapshots/tests.contrib.anthropic.test_anthropic.test_anthropic_llm_tools_full_use_stream.json  @DataDog/ml-observability
tests/snapshots/tests.contrib.anthropic.test_anthropic.test_anthropic_llm_tools_stream.json  @DataDog/ml-observability
tests/snapshots/tests.contrib.anthropic.test_anthropic.test_anthropic_llm_tools_stream_helper.json  @DataDog/ml-observability
tests/snapshots/tests.contrib.anthropic.test_anthropic.test_anthropic_llm_unserializable_arg.json  @DataDog/ml-observability

@jsimpher jsimpher changed the title dac strip io from anthropic chore(llmobs): dac strip io from anthropic Jun 25, 2025
Copy link
Contributor

github-actions bot commented Jun 25, 2025

Bootstrap import analysis

Comparison of import times between this PR and base.

Summary

The average import time from this PR is: 277 ± 2 ms.

The average import time from base is: 278 ± 2 ms.

The import time difference between this PR and base is: -1.53 ± 0.1 ms.

Import time breakdown

The following import paths have shrunk:

ddtrace.auto 1.937 ms (0.70%)
ddtrace.bootstrap.sitecustomize 1.259 ms (0.45%)
ddtrace.bootstrap.preload 1.259 ms (0.45%)
ddtrace.internal.remoteconfig.client 0.623 ms (0.23%)
ddtrace 0.678 ms (0.24%)
ddtrace.internal._unpatched 0.031 ms (0.01%)
json 0.031 ms (0.01%)
json.decoder 0.031 ms (0.01%)
re 0.031 ms (0.01%)
enum 0.031 ms (0.01%)
types 0.031 ms (0.01%)

@pr-commenter
Copy link

pr-commenter bot commented Jun 25, 2025

Benchmarks

Benchmark execution time: 2025-06-27 17:35:48

Comparing candidate commit a6f1f47 in PR branch jsimpher/dac-strip-io-from-anthropic with baseline commit b47c205 in branch main.

Found 0 performance improvements and 1 performance regressions! Performance is the same for 568 metrics, 3 unstable metrics.

scenario:iastaspects-lstrip_aspect

  • 🟥 execution_time [+756.693ns; +825.084ns] or [+7.242%; +7.896%]

@jsimpher jsimpher marked this pull request as ready for review June 27, 2025 16:42
@jsimpher jsimpher requested review from a team as code owners June 27, 2025 16:42
@jsimpher jsimpher requested review from wantsui and nsrip-dd June 27, 2025 16:42
Copy link
Contributor

@ncybul ncybul left a comment

Choose a reason for hiding this comment

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

Just a few comments, but glad the integration code was trimmed down so much! Looks great!

@@ -155,7 +154,7 @@ def _process_finished_stream(integration, span, args, kwargs, streamed_chunks):
try:
resp_message = _construct_message(streamed_chunks)
if integration.is_pc_sampled_span(span):
_tag_streamed_chat_completion_response(integration, span, resp_message)
_tag_streamed_chat_completion_usage(integration, span, resp_message)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this depend on integration.is_pc_sampled_span?

@@ -10,30 +10,19 @@
"error": 0,
"meta": {
"_dd.p.dm": "-0",
"_dd.p.tid": "665f5f5200000000",
"_dd.p.tid": "685c01fa00000000",
"anthropic.request.api_key": "sk-...key>",
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we still need API key on the APM span?

Comment on lines +197 to +201
metrics[OUTPUT_TOKENS_METRIC_KEY] = output_tokens
total_tokens = total_tokens + output_tokens if total_tokens else output_tokens
if total_tokens is not None:
metrics[TOTAL_TOKENS_METRIC_KEY] = total_tokens
span._set_ctx_item(METRICS, metrics)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we probably should be consistent with the old way of calculating the total tokens (e.g. we only set total tokens if both input and output tokens are set). I think in your new implementation, we could end up with total_tokens being just input_tokens or output_tokens.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants