Skip to content

Conversation

ncybul
Copy link
Contributor

@ncybul ncybul commented Aug 26, 2025

TODO:

  • add tests
  • check that this works for other model providers (e.g. OpenAI)

This PR adds LLM --> Tool --> LLM span linking for the bedrock agents framework using the ToolCallTracker . This works by:

  1. extracting tool calls from LLM output messages (messages with type="tool_use").
  2. recording tool invocations to link the LLM to the Tool span
  3. extracting tool usage by looking for tool_use_id instances in an LLM's input message content to link the Tool to the LLM span

Here is an example trace where you can see the span links that have been added.
image

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

CODEOWNERS have been resolved as:

ddtrace/llmobs/_integrations/bedrock_agents.py                          @DataDog/ml-observability
ddtrace/llmobs/_utils.py                                                @DataDog/ml-observability

Copy link
Contributor

github-actions bot commented Aug 26, 2025

Bootstrap import analysis

Comparison of import times between this PR and base.

Summary

The average import time from this PR is: 273 ± 3 ms.

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

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

Import time breakdown

The following import paths have grown:

ddtrace.auto 0.663 ms (0.24%)
ddtrace 0.364 ms (0.13%)
ddtrace._logger 0.319 ms (0.12%)
ddtrace.internal.telemetry 0.319 ms (0.12%)
ddtrace.internal.telemetry.writer 0.262 ms (0.10%)
http.client 0.164 ms (0.06%)
ssl 0.164 ms (0.06%)
_ssl 0.051 ms (0.02%)
ddtrace.internal.endpoints 0.050 ms (0.02%)
ddtrace.internal.periodic 0.048 ms (0.02%)
ddtrace.internal._threads 0.048 ms (0.02%)
ddtrace.settings._agent 0.020 ms (0.01%)
socket 0.020 ms (0.01%)
array 0.020 ms (0.01%)
ddtrace.trace 0.045 ms (0.02%)
ddtrace._trace.filters 0.045 ms (0.02%)
ddtrace._trace.processor 0.045 ms (0.02%)
ddtrace._trace.sampler 0.045 ms (0.02%)
ddtrace._trace.span 0.045 ms (0.02%)
ddtrace._trace._span_pointer 0.045 ms (0.02%)
hashlib 0.045 ms (0.02%)
_hashlib 0.045 ms (0.02%)
ddtrace.bootstrap.sitecustomize 0.299 ms (0.11%)
ddtrace.bootstrap.preload 0.085 ms (0.03%)
multiprocessing 0.045 ms (0.02%)
multiprocessing.context 0.045 ms (0.02%)
multiprocessing.reduction 0.045 ms (0.02%)
pickle 0.045 ms (0.02%)
ddtrace.settings.profiling 0.040 ms (0.01%)
ddtrace.internal.datadog.profiling.ddup 0.040 ms (0.01%)
ddtrace.internal.datadog.profiling.ddup._ddup 0.040 ms (0.01%)
ddtrace._trace.trace_handlers 0.039 ms (0.01%)
ddtrace._trace._inferred_proxy 0.039 ms (0.01%)
ddtrace.propagation.http 0.039 ms (0.01%)
ddtrace.internal._tagset 0.039 ms (0.01%)

The following import paths have shrunk:

ddtrace.auto 1.548 ms (0.57%)
ddtrace.bootstrap.sitecustomize 0.886 ms (0.32%)
ddtrace.bootstrap.preload 0.886 ms (0.32%)
ddtrace.internal.remoteconfig.client 0.541 ms (0.20%)
ddtrace 0.662 ms (0.24%)
ddtrace.internal._unpatched 0.027 ms (0.01%)
json 0.027 ms (0.01%)
json.decoder 0.027 ms (0.01%)
re 0.027 ms (0.01%)
enum 0.027 ms (0.01%)
types 0.027 ms (0.01%)

@ncybul ncybul changed the title support llm to tool span linking for bedrock agents chore(llmobs): [MLOB-3622] support llm to tool span linking for bedrock agents Aug 27, 2025
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.

1 participant