Skip to content

Commit 1f88b70

Browse files
ericapisaniclaude
andcommitted
ref(langchain): Simplify _get_ai_system to pass through _type value as-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>
1 parent 561688e commit 1f88b70

File tree

2 files changed

+16
-32
lines changed

2 files changed

+16
-32
lines changed

sentry_sdk/integrations/langchain.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -108,29 +108,13 @@
108108
OllamaEmbeddings = None
109109

110110

111-
_NON_PROVIDER_PARTS = frozenset({"azure", "aws", "gcp", "vertex", "chat", "llm"})
112-
113-
114111
def _get_ai_system(all_params: "Dict[str, Any]") -> "Optional[str]":
115-
"""Extract the AI provider from the ``_type`` field in LangChain params.
116-
117-
Splits on ``-`` and skips generic segments (cloud prefixes and model-type
118-
descriptors like ``chat`` / ``llm``) to return the actual provider name.
119-
"""
120112
ai_type = all_params.get("_type")
121113

122114
if not ai_type or not isinstance(ai_type, str):
123115
return None
124116

125-
parts = [p.strip().lower() for p in ai_type.split("-") if p.strip()]
126-
if not parts:
127-
return None
128-
129-
for part in parts:
130-
if part not in _NON_PROVIDER_PARTS:
131-
return part
132-
133-
return parts[0]
117+
return ai_type
134118

135119

136120
DATA_FIELDS = {

tests/integrations/langchain/test_langchain.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2005,40 +2005,40 @@ def test_transform_google_file_data(self):
20052005
[
20062006
# Real LangChain _type values (from _llm_type properties)
20072007
# OpenAI
2008-
("openai-chat", "openai"),
2008+
("openai-chat", "openai-chat"),
20092009
("openai", "openai"),
20102010
# Azure OpenAI
2011-
("azure-openai-chat", "openai"),
2011+
("azure-openai-chat", "azure-openai-chat"),
20122012
("azure", "azure"),
20132013
# Anthropic
2014-
("anthropic-chat", "anthropic"),
2014+
("anthropic-chat", "anthropic-chat"),
20152015
# Google
20162016
("vertexai", "vertexai"),
2017-
("chat-google-generative-ai", "google"),
2017+
("chat-google-generative-ai", "chat-google-generative-ai"),
20182018
("google_gemini", "google_gemini"),
2019-
# AWS Bedrock (underscore-separated, no split)
2019+
# AWS Bedrock
20202020
("amazon_bedrock_chat", "amazon_bedrock_chat"),
20212021
("amazon_bedrock", "amazon_bedrock"),
20222022
# Cohere
2023-
("cohere-chat", "cohere"),
2023+
("cohere-chat", "cohere-chat"),
20242024
# Ollama
2025-
("chat-ollama", "ollama"),
2026-
("ollama-llm", "ollama"),
2025+
("chat-ollama", "chat-ollama"),
2026+
("ollama-llm", "ollama-llm"),
20272027
# Mistral
2028-
("mistralai-chat", "mistralai"),
2028+
("mistralai-chat", "mistralai-chat"),
20292029
# Fireworks
2030-
("fireworks-chat", "fireworks"),
2030+
("fireworks-chat", "fireworks-chat"),
20312031
("fireworks", "fireworks"),
20322032
# HuggingFace
2033-
("huggingface-chat-wrapper", "huggingface"),
2033+
("huggingface-chat-wrapper", "huggingface-chat-wrapper"),
20342034
# Groq
2035-
("groq-chat", "groq"),
2035+
("groq-chat", "groq-chat"),
20362036
# NVIDIA
2037-
("chat-nvidia-ai-playground", "nvidia"),
2037+
("chat-nvidia-ai-playground", "chat-nvidia-ai-playground"),
20382038
# xAI
2039-
("xai-chat", "xai"),
2039+
("xai-chat", "xai-chat"),
20402040
# DeepSeek
2041-
("chat-deepseek", "deepseek"),
2041+
("chat-deepseek", "chat-deepseek"),
20422042
# Edge cases
20432043
("", None),
20442044
(None, None),

0 commit comments

Comments
 (0)