feat(langchain): Broaden AI provider detection beyond OpenAI and Anthropic#5707
feat(langchain): Broaden AI provider detection beyond OpenAI and Anthropic#5707ericapisani wants to merge 3 commits intomasterfrom
Conversation
…ropic Extract _get_ai_system() to generically detect AI providers from LangChain's _type field instead of hardcoding only "anthropic" and "openai". The function splits on "-" and skips non-provider segments (cloud prefixes like "azure" and descriptors like "chat"/"llm") to return the actual provider name. This adds support for Cohere, Ollama, Mistral, Fireworks, HuggingFace, Groq, NVIDIA, xAI, DeepSeek, Google, and any future LangChain providers. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
@cursoragent please review this |
|
Please finish setting up background agents. Go to Cursor |
Codecov Results 📊✅ 13 passed | Total: 13 | Pass Rate: 100% | Execution Time: 8.60s All tests are passing successfully. ❌ Patch coverage is 0.00%. Project has 14382 uncovered lines. Files with missing lines (1)
Generated by Codecov Action |
Codecov Results 📊✅ 9 passed | ⏭️ 1 skipped | Total: 10 | Pass Rate: 90% | Execution Time: 3.63s All tests are passing successfully. ❌ Patch coverage is 0.00%. Project has 14771 uncovered lines. Files with missing lines (1)
Generated by Codecov Action |
|
bugbot run |
…s-is Remove string splitting and filtering logic from _get_ai_system. The function now returns the LangChain _type value directly without attempting to extract a provider name from it. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Semver Impact of This PR🟡 Minor (new features) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨
Bug Fixes 🐛Anthropic
Other
Documentation 📚
Internal Changes 🔧
Other
🤖 This preview updates automatically when you update the PR. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Raw
_typevalues breakgen_ai.systemconsistency with other integrations- Restored normalization of LangChain _type values to return 'openai' and 'anthropic' instead of raw values like 'openai-chat' and 'anthropic-chat', matching the dedicated integrations and maintaining backward compatibility.
Or push these changes by commenting:
@cursor push 98e51d01de
Preview (98e51d01de)
diff --git a/sentry_sdk/integrations/langchain.py b/sentry_sdk/integrations/langchain.py
--- a/sentry_sdk/integrations/langchain.py
+++ b/sentry_sdk/integrations/langchain.py
@@ -114,6 +114,11 @@
if not ai_type or not isinstance(ai_type, str):
return None
+ if "anthropic" in ai_type:
+ return "anthropic"
+ elif "openai" in ai_type:
+ return "openai"
+
return ai_type
diff --git a/tests/integrations/langchain/test_langchain.py b/tests/integrations/langchain/test_langchain.py
--- a/tests/integrations/langchain/test_langchain.py
+++ b/tests/integrations/langchain/test_langchain.py
@@ -2005,13 +2005,13 @@
[
# Real LangChain _type values (from _llm_type properties)
# OpenAI
- ("openai-chat", "openai-chat"),
+ ("openai-chat", "openai"),
("openai", "openai"),
# Azure OpenAI
- ("azure-openai-chat", "azure-openai-chat"),
+ ("azure-openai-chat", "openai"),
("azure", "azure"),
# Anthropic
- ("anthropic-chat", "anthropic-chat"),
+ ("anthropic-chat", "anthropic"),
# Google
("vertexai", "vertexai"),
("chat-google-generative-ai", "chat-google-generative-ai"),This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.
| if not ai_type or not isinstance(ai_type, str): | ||
| return None | ||
|
|
||
| return ai_type |
There was a problem hiding this comment.
Raw _type values break gen_ai.system consistency with other integrations
Medium Severity
_get_ai_system returns the raw LangChain _type value (e.g. "anthropic-chat", "openai-chat") instead of a normalized provider name. The Anthropic integration sets gen_ai.system to "anthropic" and the OpenAI integration uses "openai", matching OTel semantic conventions. The old code also normalized to these values. Now the same provider gets different gen_ai.system values depending on whether it's called directly or through LangChain, breaking filtering/grouping in the Sentry UI for existing users.
Additional Locations (1)
| } | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( |
There was a problem hiding this comment.
could you add an assertation that gen_ai.system is correctly set in one of the tests that use langchain organically, i.e., like a user would interact with it. In one or all of these 🙏 .
test_langchain_text_completion()test_langchain_create_agent()test_tool_execution_span()



Summary
_get_ai_system()helper that generically detects AI providers from LangChain's_typefield, replacing hardcoded"anthropic"/"openai"checks.Test plan
_llm_typevalues from various providers🤖 Generated with Claude Code