Skip to content

Commit 4d93f80

Browse files
sabrennerYun-Kim
andauthored
feat(langgraph): enable langgraph integration by default (#12977)
LangGraph patching/instrumentation was previously hidden behind a private environment variable during a beta phase. This PR removes that gate and enables it by default. ## Checklist - [x] 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](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) - The change includes or references documentation updates if necessary - Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] 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](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) 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](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting) --------- Co-authored-by: Yun Kim <[email protected]>
1 parent 32d1e53 commit 4d93f80

File tree

6 files changed

+42
-10
lines changed

6 files changed

+42
-10
lines changed

ddtrace/_monkey.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"grpc": True,
5353
"httpx": True,
5454
"kafka": True,
55-
"langgraph": False,
55+
"langgraph": True,
5656
"litellm": True,
5757
"mongoengine": True,
5858
"mysql": True,

ddtrace/contrib/_langgraph.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,34 @@
11
"""
2-
The LangGraph integration instruments the LangGraph Python library to emit metrics,
3-
traces, and logs.
2+
The LangGraph integration instruments the LangGraph Python library to emit traces for
3+
graph and node invocations.
4+
5+
All traces submitted from the LangGraph integration are tagged by:
6+
- ``service``, ``env``, ``version``: see the `Unified Service Tagging docs <https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging>`_.
7+
8+
Enabling
9+
~~~~~~~~
10+
11+
The LangGraph integration is enabled automatically when you use
12+
:ref:`ddtrace-run<ddtracerun>` or :ref:`import ddtrace.auto<ddtraceauto>`.
13+
Alternatively, use :func:`patch() <ddtrace.patch>` to manually enable the LangGraph integration::
14+
from ddtrace import patch
15+
patch(langgraph=True)
16+
17+
Global Configuration
18+
~~~~~~~~~~~~~~~~~~~~
19+
20+
.. py:data:: ddtrace.config.langgraph["service"]
21+
The service name reported by default for LangGraph requests.
22+
Alternatively, you can set this option with the ``DD_SERVICE`` or ``DD_LANGGRAPH_SERVICE`` environment
23+
variables.
24+
Default: ``DD_SERVICE``
25+
26+
Instance Configuration
27+
~~~~~~~~~~~~~~~~~~~~~~
28+
29+
To configure the LangGraph integration on a per-instance basis use the
30+
``Pin`` API::
31+
import langgraph
32+
from ddtrace.trace import Pin
33+
Pin.override(langgraph, service="my-langgraph-service")
434
"""

ddtrace/contrib/internal/langgraph/patch.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import os
21
import sys
32

43
import langgraph
@@ -208,8 +207,7 @@ def patched_pregel_loop_tick(langgraph, pin, func, instance, args, kwargs):
208207

209208

210209
def patch():
211-
should_patch = os.getenv("_DD_TRACE_LANGGRAPH_ENABLED", "false").lower() in ("true", "1")
212-
if not should_patch or getattr(langgraph, "_datadog_patch", False):
210+
if getattr(langgraph, "_datadog_patch", False):
213211
return
214212

215213
langgraph._datadog_patch = True
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
features:
3+
- |
4+
langgraph: Introduces tracing support for LangGraph, specifically tracing graph and node executions.
5+
See `the docs <https://ddtrace.readthedocs.io/en/stable/integrations.html#langgraph>`_
6+
for more information.
7+
- |
8+
LLM Observability: Introduces tracing support for LangGraph graph and node invocation.

tests/contrib/langgraph/conftest.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ def mock_tracer():
2727

2828
@pytest.fixture
2929
def langgraph(monkeypatch, mock_tracer):
30-
monkeypatch.setenv("_DD_TRACE_LANGGRAPH_ENABLED", "true")
3130
patch()
3231
import langgraph
3332

tests/contrib/langgraph/test_langgraph_patch.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
from tests.utils import call_program
1010

1111

12-
os.environ["_DD_TRACE_LANGGRAPH_ENABLED"] = "true"
13-
14-
1512
class TestLangGraphPatch(PatchTestCase.Base):
1613
__integration_name__ = "langgraph"
1714
__module_name__ = "langgraph"

0 commit comments

Comments
 (0)