Skip to content
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

feat(botocore): add support for tagging bedrock message input/outputs #8798

Merged
merged 5 commits into from
Mar 28, 2024

Conversation

Yun-Kim
Copy link
Contributor

@Yun-Kim Yun-Kim commented Mar 27, 2024

This PR adds support to the botocore integration's bedrock service to correctly tag input/output messages from Anthropic calls.

Previously bedrock's models only supported raw text prompts and returned text outputs. However, Anthropic's newest claude 3 supports a chat message API, which means we need to support that as well.

This change also switches to using tracer.trace() instead of tracer.start_span(..., activate=False) for bedrock spans, because the latter meant that bedrock spans would always be root spans (messing up parenting for traces containing non-root bedrock spans).
Additionally by getting rid of the activate=False argument, this means that bedrock spans will now continue to be the active span until the stream/body is completely consumed. Previously we allowed bedrock spans to not be active, but if other downstream operations happen in the bedrock span then they would not correctly be child spans of the bedrock spans.

Checklist

  • Change(s) are motivated and described in the PR description
  • Testing strategy is described if automated tests are not included in the PR
  • Risks are described (performance impact, potential for breakage, maintainability)
  • Change is maintainable (easy to change, telemetry, documentation)
  • Library release note guidelines are followed or label changelog/no-changelog is set
  • Documentation is included (in-code, generated user docs, public corp docs)
  • Backport labels are set (if applicable)
  • If this PR changes the public interface, I've notified @DataDog/apm-tees.
  • If change touches code that signs or publishes builds or packages, or handles credentials of any kind, I've requested a review from @DataDog/security-design-and-guidance.

Reviewer Checklist

  • Title is accurate
  • All changes are related to the pull request's stated goal
  • Description motivates each change
  • Avoids breaking API changes
  • Testing strategy adequately addresses listed risks
  • Change is maintainable (easy to change, telemetry, documentation)
  • Release note makes sense to a user of the library
  • 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

@Yun-Kim Yun-Kim marked this pull request as ready for review March 27, 2024 23:41
@Yun-Kim Yun-Kim requested review from a team as code owners March 27, 2024 23:41
@datadog-dd-trace-py-rkomorn
Copy link

datadog-dd-trace-py-rkomorn bot commented Mar 28, 2024

Datadog Report

Branch report: yunkim/bedrock-anthropic-messages-support
Commit report: 682aded
Test service: dd-trace-py

✅ 0 Failed, 2990 Passed, 299 Skipped, 1h 31m 8.67s Total duration (4m 26.02s time saved)

@pr-commenter
Copy link

pr-commenter bot commented Mar 28, 2024

Benchmarks

Benchmark execution time: 2024-03-28 00:48:04

Comparing candidate commit 5c08ffd in PR branch yunkim/bedrock-anthropic-messages-support with baseline commit be880c1 in branch main.

Found 6 performance improvements and 0 performance regressions! Performance is the same for 195 metrics, 9 unstable metrics.

scenario:httppropagationextract-large_header_no_matches

  • 🟩 max_rss_usage [-770.113KB; -549.209KB] or [-3.521%; -2.511%]

scenario:httppropagationextract-medium_header_no_matches

  • 🟩 max_rss_usage [-757.711KB; -513.278KB] or [-3.464%; -2.346%]

scenario:httppropagationextract-wsgi_invalid_span_id_header

  • 🟩 max_rss_usage [-812.180KB; -726.688KB] or [-3.712%; -3.322%]

scenario:httppropagationextract-wsgi_invalid_trace_id_header

  • 🟩 max_rss_usage [-766.730KB; -673.833KB] or [-3.510%; -3.085%]

scenario:httppropagationextract-wsgi_large_header_no_matches

  • 🟩 max_rss_usage [-765.449KB; -685.764KB] or [-3.497%; -3.133%]

scenario:httppropagationextract-wsgi_medium_header_no_matches

  • 🟩 max_rss_usage [-789.064KB; -707.615KB] or [-3.609%; -3.237%]

@Yun-Kim Yun-Kim changed the title feat(botocore): Add support for tagging message input/outputs for bedrock feat(botocore): add support for tagging bedrock message input/outputs Mar 28, 2024
Copy link
Contributor

@lievan lievan left a comment

Choose a reason for hiding this comment

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

Looks good, just have a question about the placeholder text for images

ddtrace/contrib/botocore/services/bedrock.py Show resolved Hide resolved
ddtrace/llmobs/_integrations/bedrock.py Show resolved Hide resolved
ddtrace/llmobs/_integrations/bedrock.py Outdated Show resolved Hide resolved
ddtrace/llmobs/_integrations/bedrock.py Outdated Show resolved Hide resolved
@Yun-Kim Yun-Kim enabled auto-merge (squash) March 28, 2024 18:04
@Yun-Kim Yun-Kim merged commit 8ab2d72 into main Mar 28, 2024
68 of 69 checks passed
@Yun-Kim Yun-Kim deleted the yunkim/bedrock-anthropic-messages-support branch March 28, 2024 18:42
christophe-papazian pushed a commit that referenced this pull request Mar 29, 2024
…#8798)

This PR adds support to the botocore integration's bedrock service to
correctly tag input/output messages from Anthropic calls.

Previously bedrock's models only supported raw text prompts and returned
text outputs. However, Anthropic's newest claude 3 supports a chat
message API, which means we need to support that as well.

This change also switches to using `tracer.trace()` instead of
`tracer.start_span(..., activate=False)` for bedrock spans, because the
latter meant that bedrock spans would always be root spans (messing up
parenting for traces containing non-root bedrock spans).
Additionally by getting rid of the `activate=False` argument, this means
that bedrock spans will now continue to be the active span until the
stream/body is completely consumed. Previously we allowed bedrock spans
to not be active, but if other downstream operations happen in the
bedrock span then they would not correctly be child spans of the bedrock
spans.

## Checklist

- [x] Change(s) are motivated and described in the PR description
- [x] Testing strategy is described if automated tests are not included
in the PR
- [x] Risks are described (performance impact, potential for breakage,
maintainability)
- [x] Change is maintainable (easy to change, telemetry, documentation)
- [x] [Library release note
guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html)
are followed or label `changelog/no-changelog` is set
- [x] Documentation is included (in-code, generated user docs, [public
corp docs](https://github.com/DataDog/documentation/))
- [x] Backport labels are set (if
[applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting))
- [x] If this PR changes the public interface, I've notified
`@DataDog/apm-tees`.
- [x] If change touches code that signs or publishes builds or packages,
or handles credentials of any kind, I've requested a review from
`@DataDog/security-design-and-guidance`.

## Reviewer Checklist

- [x] Title is accurate
- [x] All changes are related to the pull request's stated goal
- [x] Description motivates each change
- [x] Avoids breaking
[API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces)
changes
- [x] Testing strategy adequately addresses listed risks
- [X] Change is maintainable (easy to change, telemetry, documentation)
- [x] Release note makes sense to a user of the library
- [x] Author has acknowledged and discussed the performance implications
of this PR as reported in the benchmarks PR comment
- [x] Backport labels are set in a manner that is consistent with the
[release branch maintenance
policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)
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