Fix the duplicate chat spans issues and http spans not propagating in langchain#147
Merged
rads-1996 merged 4 commits intoMay 18, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses LangChain tracing issues by ensuring HTTP/OpenAI child spans inherit the correct parent context (via runtime context attach/detach) and by preventing duplicate OpenAI v2 spans when overlapping GenAI instrumentations are present.
Changes:
- Attach/detach LangChain run spans to the OpenTelemetry runtime context to improve downstream HTTP span parenting, and force LangChain tracer callbacks to run inline.
- Add distro logic to auto-disable
openai(v2) instrumentation when overlapping libraries are detected, while preserving explicit user configuration. - Extend/adjust tests to validate the new behavior (context attach/detach, openai auto-disable rules, and langchain instrumentor no-op behavior).
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_distro.py | Updates end-to-end expectations and adds unit tests for openai v2 auto-disable behavior. |
| tests/langchain/test_tracer.py | Adds tests covering runtime context attach/detach and run_inline behavior. |
| tests/langchain/test_tracer_instrumentor.py | Adjusts expectations for instrumentor behavior when langchain is unavailable. |
| src/microsoft/opentelemetry/_utils.py | Introduces _disable_openai_v2_instrumentation() helper to auto-disable openai v2 when overlaps exist. |
| src/microsoft/opentelemetry/_genai/_langchain/_tracer.py | Attaches LangChain spans to runtime context and detaches on end to fix child-span parenting. |
| src/microsoft/opentelemetry/_distro.py | Calls _disable_openai_v2_instrumentation() during instrumentation setup. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Member
Author
Member
Author
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
src/microsoft/opentelemetry/_utils.py:171
- This auto-disables
openaiwheneverlangchain_core/agent_frameworkis importable, even if the user has explicitly disabled the conflicting instrumentation viainstrumentation_options(e.g.{'langchain': {'enabled': False}}). That can unexpectedly turn off OpenAI tracing in apps that merely have LangChain installed. Consider also checking whetherlangchain/agent_frameworkinstrumentation is enabled before forcingopenai.enabled=False(consistent with_is_instrumentation_enabledin_distro.py).
overlapping_present = any(
find_spec(import_name) is not None for import_name in ("langchain_core", "agent_framework")
)
if not overlapping_present:
return
hectorhdzg
approved these changes
May 18, 2026
4d0f46c to
e63caad
Compare
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



No description provided.