Skip to content

[langchain] flag to enable context propagation (composability) #1544

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

Open
mikeldking opened this issue Apr 21, 2025 · 2 comments · May be fixed by #1546
Open

[langchain] flag to enable context propagation (composability) #1544

mikeldking opened this issue Apr 21, 2025 · 2 comments · May be fixed by #1546
Assignees
Labels
bug Something isn't working instrumentation: langchain language: python Related to Python integration

Comments

@mikeldking
Copy link
Contributor

Right now context propagation is disabled for langchain as it can become troublesome when spans get orphaned (I believe). This is the line in question (https://github.com/Arize-ai/openinference/blob/6f8ec172647c48d9a15218cf248651df37f[…]angchain/src/openinference/instrumentation/langchain/_tracer.py)

This makes langchain not composable however and we need to solve this problem as it seems to come up often. Notably the more recent MCP propagation is impossible.

@mikeldking mikeldking added bug Something isn't working triage Issues that require triage labels Apr 21, 2025
@dosubot dosubot bot added enhancement New feature or request instrumentation: langchain labels Apr 21, 2025
@mikeldking mikeldking added language: python Related to Python integration and removed enhancement New feature or request labels Apr 21, 2025
@cephalization cephalization removed the triage Issues that require triage label Apr 21, 2025
@github-project-automation github-project-automation bot moved this to 📘 Todo in phoenix Apr 21, 2025
@mikeldking mikeldking moved this from 📘 Todo to 👨‍💻 In progress in phoenix Apr 21, 2025
@mikeldking mikeldking moved this from 👨‍💻 In progress to 📘 Todo in phoenix Apr 21, 2025
@mikeldking mikeldking moved this to Todo in Instrumentation Apr 21, 2025
@mikeldking
Copy link
Contributor Author

Going to try to see if it works on conjunction with: https://github.com/langchain-ai/langchain-mcp-adapters

@mikeldking
Copy link
Contributor Author

OTEL context doesn't seem to be able to be attached in a meaningful way:

Traceback (most recent call last):
  File "/Users/mikeldking/anaconda3/envs/langgraph-mcp/lib/python3.13/site-packages/opentelemetry/context/__init__.py", line 155, in detach
    _RUNTIME_CONTEXT.detach(token)
    ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^
  File "/Users/mikeldking/anaconda3/envs/langgraph-mcp/lib/python3.13/site-packages/opentelemetry/context/contextvars_context.py", line 53, in detach
    self._current_context.reset(token)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^
ValueError: <Token var=<ContextVar name='current_context' default={} at 0x104a315d0> at 0x106ba6700> was created in a different Context
Failed to detach context
Traceback (most recent call last):
  File "/Users/mikeldking/anaconda3/envs/langgraph-mcp/lib/python3.13/site-packages/opentelemetry/context/__init__.py", line 155, in detach
    _RUNTIME_CONTEXT.detach(token)
    ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^
  File "/Users/mikeldking/anaconda3/envs/langgraph-mcp/lib/python3.13/site-packages/opentelemetry/context/contextvars_context.py", line 53, in detach
    self._current_context.reset(token)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^
ValueError: <Token var=<ContextVar name='current_context' default={} at 0x104a315d0> at 0x106b929c0> was created in a different Context
Failed to detach context
Traceback (most recent call last):
  File "/Users/mikeldking/anaconda3/envs/langgraph-mcp/lib/python3.13/site-packages/opentelemetry/context/__init__.py", line 155, in detach
    _RUNTIME_CONTEXT.detach(token)
    ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^
  File "/Users/mikeldking/anaconda3/envs/langgraph-mcp/lib/python3.13/site-packages/opentelemetry/context/contextvars_context.py", line 53, in detach
    self._current_context.reset(token)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^
ValueError: <Token var=<ContextVar name='current_context' default={} at 0x104a315d0> at 0x106a87b00> was created in a different Context
attaching otel context
attaching token
Failed to detach context
Traceback (most recent call last):
  File "/Users/mikeldking/anaconda3/envs/langgraph-mcp/lib/python3.13/site-packages/opentelemetry/context/__init__.py", line 155, in detach
    _RUNTIME_CONTEXT.detach(token)
    ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^
  File "/Users/mikeldking/anaconda3/envs/langgraph-mcp/lib/python3.13/site-packages/opentelemetry/context/contextvars_context.py", line 53, in detach
    self._current_context.reset(token)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^
ValueError: <Token var=<ContextVar name='current_context' default={} at 0x104a315d0> at 0x106a29ac0> was created in a different Context
Failed to detach context
Traceback (most recent call last):
  File "/Users/mikeldking/anaconda3/envs/langgraph-mcp/lib/python3.13/site-packages/opentelemetry/context/__init__.py", line 155, in detach
    _RUNTIME_CONTEXT.detach(token)
    ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^
  File "/Users/mikeldking/anaconda3/envs/langgraph-mcp/lib/python3.13/site-packages/opentelemetry/context/contextvars_context.py", line 53, in detach
    self._current_context.reset(token)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^
ValueError: <Token var=<ContextVar name='current_context' default={} at 0x104a315d0> at 0x106a9a640> was created in a different Context
Failed to detach context
Traceback (most recent call last):
  File "/Users/mikeldking/anaconda3/envs/langgraph-mcp/lib/python3.13/site-packages/opentelemetry/context/__init__.py", line 155, in detach
    _RUNTIME_CONTEXT.detach(token)
    ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^
  File "/Users/mikeldking/anaconda3/envs/langgraph-mcp/lib/python3.13/site-packages/opentelemetry/context/contextvars_context.py", line 53, in detach
    self._current_context.reset(token)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working instrumentation: langchain language: python Related to Python integration
Projects
Status: Todo
Status: 📘 Todo
Development

Successfully merging a pull request may close this issue.

2 participants