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(langgraph): submit spans from langgraph to APM and LLMObs #11730

Merged
merged 44 commits into from
Jan 17, 2025

Conversation

sabrenner
Copy link
Contributor

@sabrenner sabrenner commented Dec 13, 2024

This PR adds a simple integration and corresponding LLMObs plugin for the LangGraph framework.

Enablement

For both APM and LLMObs, this integration is disabled by default, and only enabled with DD_TRACE_LANGGRAPH_ENABLED=true or patch(langgraph=True), along with _DD_TRACE_LANGGRAPH_ENABLED=true, due to its experimental nature.

APM Tracing

The APM integration adds basic tracing for LangGraph Pregel graph invocations, as well as the execution of each node/step in the graph (traced as RunnableSeq).

LLM Observability Plugin

The LLMObs plugin submits the traces to LLM Observability.

Graph Invocation/Streaming Output Tagging

Because we patch the (a)stream method for both streams and (a)invoke, since they rely on (a)stream under the hood, we are bound to the yields from the stream. The object shape and value depend on the stream_mode passed in to the stream function. For invoke, it defaults to "values", which is perfect for our use case. However, if one were to call stream directly, and either pass in nothing or something like stream_mode=["updates", "debug"], the output we would have for the graph span would appear as:

{
  "type": "task_result",
  "timestamp": "2025-01-03T14:45:26.087608+00:00",
  "step": "3",
  "payload": {
    "id": "399cfe0a-aefd-f67c-6909-fcea80ef508b",
    "name": "e",
    "error": "None",
    "result": [
      "('a_list', ['e'])"
    ],
    "interrupts": []
  }
}

This is a known limitation for now, and a more thought-out solution for either adding on "values" to stream_mode and omitting their yields if it wasn't already present, or having some kind of clever joining, can be added in a later PR or by feature request.

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 Dec 13, 2024

CODEOWNERS have been resolved as:

.riot/requirements/115283d.txt                                          @DataDog/apm-python
.riot/requirements/18551a1.txt                                          @DataDog/apm-python
.riot/requirements/2bd0151.txt                                          @DataDog/apm-python
.riot/requirements/2e4fbd3.txt                                          @DataDog/apm-python
.riot/requirements/7dd4bcd.txt                                          @DataDog/apm-python
ddtrace/contrib/internal/langgraph/patch.py                             @DataDog/ml-observability
ddtrace/contrib/langgraph/__init__.py                                   @DataDog/ml-observability
ddtrace/llmobs/_integrations/langgraph.py                               @DataDog/ml-observability
tests/contrib/langgraph/__init__.py                                     @DataDog/ml-observability
tests/contrib/langgraph/conftest.py                                     @DataDog/ml-observability
tests/contrib/langgraph/test_langgraph.py                               @DataDog/ml-observability
tests/contrib/langgraph/test_langgraph_llmobs.py                        @DataDog/ml-observability
tests/contrib/langgraph/test_langgraph_patch.py                         @DataDog/ml-observability
.github/CODEOWNERS                                                      @DataDog/python-guild @DataDog/apm-core-python
ddtrace/_monkey.py                                                      @DataDog/apm-core-python
ddtrace/llmobs/_constants.py                                            @DataDog/ml-observability
ddtrace/llmobs/_integrations/base.py                                    @DataDog/ml-observability
ddtrace/llmobs/_integrations/langchain.py                               @DataDog/ml-observability
ddtrace/llmobs/_integrations/utils.py                                   @DataDog/ml-observability
ddtrace/llmobs/_llmobs.py                                               @DataDog/ml-observability
ddtrace/llmobs/_utils.py                                                @DataDog/ml-observability
riotfile.py                                                             @DataDog/apm-python
tests/llmobs/suitespec.yml                                              @DataDog/ml-observability

@pr-commenter
Copy link

pr-commenter bot commented Dec 13, 2024

Benchmarks

Benchmark execution time: 2025-01-17 16:43:15

Comparing candidate commit 1a2dab7 in PR branch sabrenner/langgraph with baseline commit f67a358 in branch main.

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

scenario:iast_aspects-lower_aspect

  • 🟥 execution_time [+253.973ns; +297.848ns] or [+9.423%; +11.050%]

scenario:iast_aspects-ospathdirname_aspect

  • 🟥 execution_time [+321.279ns; +390.856ns] or [+8.648%; +10.521%]

scenario:iast_aspects-ospathsplit_aspect

  • 🟥 execution_time [+351.346ns; +414.758ns] or [+9.132%; +10.780%]

scenario:iast_aspects-translate_aspect

  • 🟥 execution_time [+274.107ns; +325.343ns] or [+7.194%; +8.539%]

ddtrace/contrib/internal/langgraph/patch.py Outdated Show resolved Hide resolved
ddtrace/contrib/internal/langgraph/patch.py Outdated Show resolved Hide resolved
ddtrace/contrib/internal/langgraph/patch.py Outdated Show resolved Hide resolved
ddtrace/contrib/internal/langgraph/patch.py Outdated Show resolved Hide resolved
ddtrace/contrib/internal/langgraph/patch.py Outdated Show resolved Hide resolved
ddtrace/llmobs/_integrations/langgraph.py Outdated Show resolved Hide resolved
ddtrace/llmobs/_integrations/langgraph.py Outdated Show resolved Hide resolved
ddtrace/llmobs/_integrations/langgraph.py Outdated Show resolved Hide resolved
ddtrace/llmobs/_integrations/langgraph.py Outdated Show resolved Hide resolved
ddtrace/llmobs/_integrations/langgraph.py Show resolved Hide resolved
ddtrace/_monkey.py Outdated Show resolved Hide resolved
@Yun-Kim Yun-Kim changed the title wip llmobs langgraph poc feat(langgraph): submit spans from langgraph to APM and LLMObs Dec 27, 2024
@datadog-dd-trace-py-rkomorn
Copy link

datadog-dd-trace-py-rkomorn bot commented Dec 30, 2024

Datadog Report

Branch report: sabrenner/langgraph
Commit report: 1a2dab7
Test service: dd-trace-py

✅ 0 Failed, 130 Passed, 1468 Skipped, 4m 12.31s Total duration (35m 22.88s time saved)

tests/llmobs/suitespec.yml Outdated Show resolved Hide resolved
@sabrenner sabrenner marked this pull request as ready for review January 10, 2025 16:10
@sabrenner sabrenner requested review from a team as code owners January 10, 2025 16:10
Copy link
Contributor

@erikayasuda erikayasuda left a comment

Choose a reason for hiding this comment

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

LGTM for guild/core files 👍

ddtrace/_monkey.py Show resolved Hide resolved
ddtrace/contrib/internal/langgraph/patch.py Outdated Show resolved Hide resolved
ddtrace/contrib/internal/langgraph/patch.py Outdated Show resolved Hide resolved
ddtrace/contrib/internal/langgraph/patch.py Outdated Show resolved Hide resolved
ddtrace/contrib/internal/langgraph/patch.py Outdated Show resolved Hide resolved
ddtrace/contrib/langgraph/__init__.py Outdated Show resolved Hide resolved
ddtrace/contrib/langgraph/__init__.py Outdated Show resolved Hide resolved
docs/index.rst Outdated Show resolved Hide resolved
tests/contrib/langgraph/conftest.py Outdated Show resolved Hide resolved
tests/contrib/langgraph/test_langgraph_llmobs.py Outdated Show resolved Hide resolved
@sabrenner sabrenner added the changelog/no-changelog A changelog entry is not required for this PR. label Jan 14, 2025
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.

Final review for me, everything looks good except for a couple small comments!

ddtrace/llmobs/_integrations/langgraph.py Show resolved Hide resolved
ddtrace/llmobs/_integrations/langgraph.py Show resolved Hide resolved
ddtrace/llmobs/_integrations/utils.py Show resolved Hide resolved
tests/contrib/langgraph/conftest.py Outdated Show resolved Hide resolved
tests/contrib/langgraph/test_langgraph_patch.py Outdated Show resolved Hide resolved
@sabrenner sabrenner enabled auto-merge (squash) January 17, 2025 21:43
@sabrenner sabrenner merged commit b614655 into main Jan 17, 2025
710 of 711 checks passed
@sabrenner sabrenner deleted the sabrenner/langgraph branch January 17, 2025 21:43
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants