The Langchain and Langgraph integrations only record input_tokens, output_tokens, and total_tokens on spans. They don't populate gen_ai.usage.input_tokens.cached or gen_ai.usage.output_tokens.reasoning, even though SPANDATA already defines both and the OpenAI, OpenAI Agents, and Google GenAI integrations already set them from equivalent provider fields (e.g. prompt_tokens_details.cached_tokens, completion_tokens_details.reasoning_tokens).
Without these, cost calculations that rely on cache discounts and reasoning-token pricing are inaccurate for Langchain/Langgraph-instrumented apps.
sentry_sdk/integrations/langchain.py: _extract_tokens, _extract_tokens_from_generations, and _record_token_usage only read prompt_tokens/input_tokens, completion_tokens/output_tokens, and total_tokens from the token usage dict.
sentry_sdk/integrations/langgraph.py: token accumulation loop only reads prompt_tokens, completion_tokens, total_tokens from response_metadata["token_usage"].
Both should also extract cached input tokens and reasoning output tokens where the underlying LLM provider surfaces them (e.g. via usage_metadata.input_token_details.cache_read / output_token_details.reasoning in LangChain's newer usage metadata shape) and set SPANDATA.GEN_AI_USAGE_INPUT_TOKENS_CACHED / SPANDATA.GEN_AI_USAGE_OUTPUT_TOKENS_REASONING accordingly.
Related: #5455 (same gap for the LiteLLM integration).
Requested by Connor via Junior.
--
View Junior Session in Sentry
The Langchain and Langgraph integrations only record
input_tokens,output_tokens, andtotal_tokenson spans. They don't populategen_ai.usage.input_tokens.cachedorgen_ai.usage.output_tokens.reasoning, even thoughSPANDATAalready defines both and the OpenAI, OpenAI Agents, and Google GenAI integrations already set them from equivalent provider fields (e.g.prompt_tokens_details.cached_tokens,completion_tokens_details.reasoning_tokens).Without these, cost calculations that rely on cache discounts and reasoning-token pricing are inaccurate for Langchain/Langgraph-instrumented apps.
sentry_sdk/integrations/langchain.py:_extract_tokens,_extract_tokens_from_generations, and_record_token_usageonly readprompt_tokens/input_tokens,completion_tokens/output_tokens, andtotal_tokensfrom the token usage dict.sentry_sdk/integrations/langgraph.py: token accumulation loop only readsprompt_tokens,completion_tokens,total_tokensfromresponse_metadata["token_usage"].Both should also extract cached input tokens and reasoning output tokens where the underlying LLM provider surfaces them (e.g. via
usage_metadata.input_token_details.cache_read/output_token_details.reasoningin LangChain's newer usage metadata shape) and setSPANDATA.GEN_AI_USAGE_INPUT_TOKENS_CACHED/SPANDATA.GEN_AI_USAGE_OUTPUT_TOKENS_REASONINGaccordingly.Related: #5455 (same gap for the LiteLLM integration).
Requested by Connor via Junior.
--
View Junior Session in Sentry