Skip to content

fix(llmobs): fix parsing errors for bedrock converse stream #13238

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 6 commits into
base: main
Choose a base branch
from

Conversation

lievan
Copy link
Contributor

@lievan lievan commented Apr 21, 2025

Fixing a noop test discovered a couple bugs for parsing out the response from converse stream

  1. We were adding a [{"role": "assistant"}] message that didn't contain any content blocks to be parsed out - the fix is to only try to extract a message if it contains associated content block indices
  2. toolName -> name

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 Apr 21, 2025

CODEOWNERS have been resolved as:

releasenotes/notes/converse-parsing-cd9ebb9506f8bbe1.yaml               @DataDog/apm-python
ddtrace/llmobs/_integrations/bedrock.py                                 @DataDog/ml-observability
ddtrace/llmobs/_integrations/utils.py                                   @DataDog/ml-observability
tests/contrib/botocore/test_bedrock_llmobs.py                           @DataDog/ml-observability

Copy link
Contributor

github-actions bot commented Apr 21, 2025

Bootstrap import analysis

Comparison of import times between this PR and base.

Summary

The average import time from this PR is: 236 ± 4 ms.

The average import time from base is: 244 ± 5 ms.

The import time difference between this PR and base is: -7.4 ± 0.2 ms.

Import time breakdown

The following import paths have shrunk:

ddtrace.auto 2.535 ms (1.07%)
ddtrace.bootstrap.sitecustomize 1.687 ms (0.71%)
ddtrace.bootstrap.preload 1.687 ms (0.71%)
ddtrace.internal.products 1.687 ms (0.71%)
ddtrace.internal.remoteconfig.client 0.744 ms (0.31%)
ddtrace.internal.symbol_db.remoteconfig 0.036 ms (0.02%)
ddtrace.internal.symbol_db.symbols 0.036 ms (0.02%)
gzip 0.036 ms (0.02%)
ddtrace 0.848 ms (0.36%)
ddtrace._logger 0.158 ms (0.07%)
logging 0.118 ms (0.05%)
traceback 0.118 ms (0.05%)
contextlib 0.118 ms (0.05%)
ddtrace.internal.telemetry 0.040 ms (0.02%)
ddtrace.internal.telemetry.writer 0.040 ms (0.02%)
ddtrace.internal.telemetry.metrics_namespaces 0.040 ms (0.02%)

@pr-commenter
Copy link

pr-commenter bot commented Apr 21, 2025

Benchmarks

Benchmark execution time: 2025-04-22 12:36:51

Comparing candidate commit 21d3ed8 in PR branch evan.li/fix-parsing-stream with baseline commit 1e1626a in branch main.

Found 0 performance improvements and 2 performance regressions! Performance is the same for 498 metrics, 8 unstable metrics.

scenario:iast_aspects-ospathsplit_aspect

  • 🟥 execution_time [+385.352ns; +635.775ns] or [+8.153%; +13.451%]

scenario:iast_aspects-ospathsplitext_aspect

  • 🟥 execution_time [+369.503ns; +538.846ns] or [+8.110%; +11.826%]

@@ -186,18 +186,18 @@ def _extract_output_message_for_converse_stream(

if "messageStart" in chunk:
message_data = chunk["messageStart"]
current_message = {"role": message_data.get("role", "assistant"), "context_block_indices": []}
current_message = {"role": message_data.get("role", "assistant"), "content_block_indicies": []}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

rename context -> content to be consistent with what we are actually parsing from bedrock

@lievan lievan marked this pull request as ready for review April 22, 2025 11:46
@lievan lievan requested review from a team as code owners April 22, 2025 11:46
@lievan lievan requested review from gnufede and ZStriker19 April 22, 2025 11:46
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.

2 participants