Skip to content

fix(core): ensure tracing context is checked when callbacks=None#36951

Closed
Mateus Scheuer Macedo (MestreY0d4-Uninter) wants to merge 1 commit intolangchain-ai:masterfrom
MestreY0d4-Uninter:fix/30870-ainvoke-tracing
Closed

fix(core): ensure tracing context is checked when callbacks=None#36951
Mateus Scheuer Macedo (MestreY0d4-Uninter) wants to merge 1 commit intolangchain-ai:masterfrom
MestreY0d4-Uninter:fix/30870-ainvoke-tracing

Conversation

@MestreY0d4-Uninter
Copy link
Copy Markdown

Fixes #30870

What changed

Added explicit check for global tracing context when both inheritable_callbacks and local_callbacks are None in the _configure function.

Why

When llm.ainvoke() is called without explicit callbacks, the tracing context was not being consulted in async contexts where contextvars may not propagate automatically. This caused tracing to silently fail.

How to test

  1. Set LANGCHAIN_TRACING_V2=true
  2. Call llm.ainvoke() without passing explicit callbacks
  3. Verify tracing data appears in LangSmith

Changes

  • libs/core/langchain_core/callbacks/manager.py: Add check for global tracing context when callbacks=None

AI-assisted contribution.

- Add explicit check for global tracing context when both inheritable_callbacks
  and local_callbacks are None
- This fixes issue langchain-ai#30870 where llm.ainvoke() tracing was not working
  in async contexts where contextvars may not propagate automatically
- The fix ensures tracing_tags and tracing_metadata are always consulted
  even when callbacks=None is passed explicitly

Fixes: langchain-ai#30870
@github-actions
Copy link
Copy Markdown

This PR has been automatically closed because you are not assigned to the linked issue.

External contributors must be assigned to an issue before opening a PR for it. Please:

  1. Comment on the linked issue to request assignment from a maintainer
  2. Once assigned, your PR will be reopened automatically

Maintainers: reopen this PR or remove the missing-issue-link label to bypass this check.

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

Labels

core `langchain-core` package issues & PRs external fix For PRs that implement a fix missing-issue-link new-contributor size: XS < 50 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

llm.ainvoke is traced differently than llm.invoke (won't be traced)

1 participant