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(llmobs): submit span events for chains from langchain #8920

Merged
merged 24 commits into from
Apr 18, 2024

Conversation

sabrenner
Copy link
Contributor

@sabrenner sabrenner commented Apr 9, 2024

Summary

Follow-up to #8695

This PR adds support for submitting LLMObs span events from the LangChain integration automatically if LLMObs is enabled, and if the LLMObs span is sampled. This is accomplished by:

  • Setting the span type SpanTypes.LLM on langchain chain APM spans so they are properly processed by the trace processor service in the LLMObs service
  • Tagging each chain span with additional _ml_obs.* tags, which get popped from the trace when submitting the data they represent to LLMObs intake through the LLMObs writer

For Reviewers

Most of the LOC are test changes to account for the change in test structure when dealing with variable amounts of expected calls to the LLMObs writer. Additionally, many of the files changed are snapshot files, to account for the change in the span type. Otherwise, the important files changed are:

  1. ddtrace/contrib/langchain/patch.py
  2. ddtrace/llmobs/_integrations/langchain.py

Additionally, no release notes/changelog, as this is an internal change for submitting span events to LLMObs intake.

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.

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

@sabrenner sabrenner added changelog/no-changelog A changelog entry is not required for this PR. MLObs ML Observability (LLMObs) labels Apr 9, 2024
@datadog-dd-trace-py-rkomorn
Copy link

datadog-dd-trace-py-rkomorn bot commented Apr 9, 2024

Datadog Report

Branch report: sabrenner/langchain-span-events-chains
Commit report: 54f0661
Test service: dd-trace-py

✅ 0 Failed, 2852 Passed, 288 Skipped, 1h 18m 42.98s Total duration (6m 11.54s time saved)

@pr-commenter
Copy link

pr-commenter bot commented Apr 9, 2024

Benchmarks

Benchmark execution time: 2024-04-17 19:55:51

Comparing candidate commit 2af0e25 in PR branch sabrenner/langchain-span-events-chains with baseline commit b1dab58 in branch main.

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

scenario:flasksimple-appsec-get

  • 🟩 execution_time [-247.557µs; -183.475µs] or [-3.806%; -2.821%]

scenario:httppropagationextract-all_styles_all_headers

  • 🟩 max_rss_usage [-755.572KB; -438.412KB] or [-3.473%; -2.015%]

scenario:httppropagationextract-medium_header_no_matches

  • 🟩 max_rss_usage [-759.079KB; -557.785KB] or [-3.462%; -2.544%]

@sabrenner sabrenner marked this pull request as ready for review April 10, 2024 16:54
@sabrenner sabrenner requested review from a team as code owners April 10, 2024 16:54
Copy link
Contributor

@Yun-Kim Yun-Kim left a comment

Choose a reason for hiding this comment

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

Awesome work! Other than a couple of style points, I had a couple suggestions on how we should tag chain inputs and outputs.

ddtrace/contrib/langchain/patch.py Outdated Show resolved Hide resolved
ddtrace/contrib/langchain/patch.py Outdated Show resolved Hide resolved
ddtrace/contrib/langchain/patch.py Outdated Show resolved Hide resolved
ddtrace/contrib/langchain/patch.py Outdated Show resolved Hide resolved
ddtrace/contrib/langchain/patch.py Outdated Show resolved Hide resolved
ddtrace/llmobs/_integrations/langchain.py Outdated Show resolved Hide resolved
ddtrace/llmobs/_integrations/langchain.py Outdated Show resolved Hide resolved
ddtrace/llmobs/_integrations/langchain.py Outdated Show resolved Hide resolved
ddtrace/llmobs/_integrations/langchain.py Outdated Show resolved Hide resolved
tests/contrib/langchain/test_langchain.py Outdated Show resolved Hide resolved
ddtrace/contrib/langchain/patch.py Outdated Show resolved Hide resolved
ddtrace/contrib/langchain/patch.py Outdated Show resolved Hide resolved
ddtrace/llmobs/_integrations/langchain.py Outdated Show resolved Hide resolved
ddtrace/llmobs/_integrations/langchain.py Outdated Show resolved Hide resolved
tests/contrib/langchain/test_langchain.py Outdated Show resolved Hide resolved
tests/contrib/langchain/test_langchain.py Outdated Show resolved Hide resolved
tests/contrib/langchain/test_langchain_community.py Outdated Show resolved Hide resolved
tests/contrib/langchain/test_langchain_community.py Outdated Show resolved Hide resolved
tests/contrib/langchain/test_langchain_community.py Outdated Show resolved Hide resolved
tests/contrib/langchain/test_langchain_community.py Outdated Show resolved Hide resolved
tests/llmobs/_utils.py Show resolved Hide resolved
tests/llmobs/_utils.py Outdated Show resolved Hide resolved
ddtrace/contrib/langchain/patch.py Outdated Show resolved Hide resolved
ddtrace/contrib/langchain/patch.py Outdated Show resolved Hide resolved
ddtrace/contrib/langchain/patch.py Outdated Show resolved Hide resolved
ddtrace/contrib/langchain/patch.py Outdated Show resolved Hide resolved
ddtrace/llmobs/_integrations/langchain.py Outdated Show resolved Hide resolved
tests/contrib/langchain/test_langchain.py Outdated Show resolved Hide resolved
@sabrenner
Copy link
Contributor Author

Since CI is a bit funky with skipping tests it shouldn't, here are the results from a local run of the test suite (with Python 3.10)

test_langchain:
Screenshot 2024-04-17 at 1 18 46 PM

test_langchain_community:
Screenshot 2024-04-17 at 1 18 24 PM

where, in each case, the majority of the skipped count is the other test suite that was skipped

Copy link
Contributor

@Yun-Kim Yun-Kim left a comment

Choose a reason for hiding this comment

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

Awesome work!

@Yun-Kim Yun-Kim enabled auto-merge (squash) April 18, 2024 13:25
@Yun-Kim Yun-Kim merged commit 7904d56 into main Apr 18, 2024
71 checks passed
@Yun-Kim Yun-Kim deleted the sabrenner/langchain-span-events-chains branch April 18, 2024 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog/no-changelog A changelog entry is not required for this PR. MLObs ML Observability (LLMObs)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants