Skip to content

🐛 Bug Report: LangGraph traces not emitted unless langchain package is installed #2973

Closed

Description

@ronensc

Which component is this bug for?

Langchain Instrumentation

📜 Description

When using traceloop-sdk with langgraph (which depends only on langchain-core), no traces are emitted unless the langchain package is also installed. This breaks tracing for LangGraph-only projects.

👟 Reproduction steps

  1. Create a fresh virtual environment and install the following packages:
pip install traceloop-sdk==0.40.7 langgraph==0.4.8
  1. Run this minimal LangGraph script:
from typing import TypedDict
from langgraph.graph import StateGraph, END, START

from opentelemetry.sdk.trace.export.in_memory_span_exporter import InMemorySpanExporter
from traceloop.sdk import Traceloop

exporter = InMemorySpanExporter()
Traceloop.init(
	exporter=exporter,
    disable_batch=True,
)

class DummyGraphState(TypedDict):
    result: str


def mynode_func(state: DummyGraphState) -> DummyGraphState:
    return state


def build_graph():
    workflow = StateGraph(DummyGraphState)
    workflow.add_node("mynode", mynode_func)
    workflow.add_edge(START, "mynode")
    workflow.add_edge("mynode", END)
    langgraph = workflow.compile()
    return langgraph


graph = build_graph()
graph.invoke({"result": "init"})


spans = exporter.get_finished_spans()
assert ['mynode.task', 'LangGraph.workflow'] == [s.name for s in spans], f"Actual: {[s.name for s in spans]=}"
  1. This will fail with:
Traceback (most recent call last):
  File "/home/ronen/traceloop/openllmetry/packages/opentelemetry-instrumentation-langchain/tests/bug.py", line 35, in <module>
    assert ['mynode.task', 'LangGraph.workflow'] == [s.name for s in spans], f"Actual: {[s.name for s in spans]=}"
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: Actual: [s.name for s in spans]=[]
  1. Installing these additional packages resolves the issue:
pip install langchain langchain_community langchain_openai

👍 Expected behavior

LangGraph spans should be emitted without requiring unrelated LangChain packages like langchain, langchain_community, or langchain_openai.

👎 Actual Behavior with Screenshots

No spans are emitted unless the langchain package (and others) are installed, even though langgraph does not depend on them.

🤖 Python Version

No response

📃 Provide any additional context for the Bug.

Suggestion:
Remove the hard dependency on the langchain package and adjust the logic to instrument langchain_community, and langchain_openai only if they are installed.

👀 Have you spent some time to check if this bug has been raised before?

  • I checked and didn't find similar issue

Are you willing to submit PR?

Yes I am willing to submit a PR!

Activity

  1. nirga commented on Jun 9, 2025

    @nirga
    Member

    Interesting @ronensc - luckily seems like an easy fix! Are you creating a PR?

  2. ronensc commented on Jun 9, 2025

    @ronensc
    CollaboratorAuthor

    @nirga Yes I am willing to submit a PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions