Skip to content

Conversation

@lievan
Copy link
Contributor

@lievan lievan commented May 20, 2025

https://datadoghq.atlassian.net/browse/MLOB-2839

Add a check that we already do for chat / llm messages for ai message type to avoid potential attribute errors when usage is None or not a dictionary

This issue is potentially related langchain-ai/langgraph#3936

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

@github-actions
Copy link
Contributor

github-actions bot commented May 20, 2025

CODEOWNERS have been resolved as:

releasenotes/notes/fix-ai-tokens-df16a9c7acd23805.yaml                  @DataDog/apm-python
ddtrace/llmobs/_integrations/langchain.py                               @DataDog/ml-observability

@lievan lievan marked this pull request as ready for review May 20, 2025 15:27
@lievan lievan requested review from a team as code owners May 20, 2025 15:28
@lievan lievan requested review from Yun-Kim and gnufede May 20, 2025 15:28
@github-actions
Copy link
Contributor

github-actions bot commented May 20, 2025

Bootstrap import analysis

Comparison of import times between this PR and base.

Summary

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

The average import time from base is: 246 ± 4 ms.

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

Import time breakdown

The following import paths have shrunk:

ddtrace.auto 2.210 ms (0.92%)
ddtrace.bootstrap.sitecustomize 1.520 ms (0.63%)
ddtrace.bootstrap.preload 1.520 ms (0.63%)
ddtrace.internal.remoteconfig.client 0.736 ms (0.31%)
ddtrace 0.690 ms (0.29%)
ddtrace.internal._unpatched 0.026 ms (0.01%)

@pr-commenter
Copy link

pr-commenter bot commented May 20, 2025

Benchmarks

Benchmark execution time: 2025-05-29 15:42:43

Comparing candidate commit 8092ea0 in PR branch evan.li/token-usage-fix with baseline commit 074b3be in branch main.

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

scenario:iastdjangostartup-appsec

  • 🟩 execution_time [-1.114s; -1.042s] or [-56.585%; -52.921%]

scenario:iastdjangostartup-iast

  • 🟩 execution_time [-1047.259ms; -809.329ms] or [-43.916%; -33.939%]

scenario:iastdjangostartup-tracer

  • 🟩 execution_time [-852.278ms; -745.710ms] or [-48.468%; -42.407%]

Co-authored-by: Yun Kim <35776586+Yun-Kim@users.noreply.github.com>
@lievan lievan enabled auto-merge (squash) May 28, 2025 15:04
@lievan lievan merged commit 9e058b0 into main May 29, 2025
352 of 353 checks passed
@lievan lievan deleted the evan.li/token-usage-fix branch May 29, 2025 15:44
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.

4 participants