Commit d867724
fix(openai): Extract cached and reasoning tokens in Completions token usage
The refactor that split _calculate_token_usage into separate Completions
and Responses functions dropped extraction of prompt_tokens_details.cached_tokens
and completion_tokens_details.reasoning_tokens from the Completions path.
This restores those fields so spans for cached prompts and reasoning models
(e.g. o1/o3) report complete token usage metrics.
Also fixes streaming usage priority: streaming_message_token_usage now
correctly takes precedence over response.usage via elif.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent d1ae0b2 commit d867724
File tree
2 files changed
+65
-2
lines changed- sentry_sdk/integrations
- tests/integrations/openai
2 files changed
+65
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
158 | 158 | | |
159 | 159 | | |
160 | 160 | | |
| 161 | + | |
161 | 162 | | |
| 163 | + | |
162 | 164 | | |
163 | 165 | | |
164 | 166 | | |
165 | 167 | | |
166 | 168 | | |
167 | | - | |
168 | | - | |
| 169 | + | |
169 | 170 | | |
170 | 171 | | |
171 | 172 | | |
172 | 173 | | |
173 | 174 | | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
174 | 179 | | |
175 | 180 | | |
176 | 181 | | |
177 | 182 | | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
178 | 189 | | |
179 | 190 | | |
180 | 191 | | |
| |||
204 | 215 | | |
205 | 216 | | |
206 | 217 | | |
| 218 | + | |
207 | 219 | | |
| 220 | + | |
208 | 221 | | |
209 | 222 | | |
210 | 223 | | |
211 | 224 | | |
212 | 225 | | |
| 226 | + | |
213 | 227 | | |
| 228 | + | |
214 | 229 | | |
215 | 230 | | |
216 | 231 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1970 | 1970 | | |
1971 | 1971 | | |
1972 | 1972 | | |
| 1973 | + | |
| 1974 | + | |
| 1975 | + | |
| 1976 | + | |
| 1977 | + | |
| 1978 | + | |
| 1979 | + | |
| 1980 | + | |
| 1981 | + | |
| 1982 | + | |
| 1983 | + | |
| 1984 | + | |
| 1985 | + | |
| 1986 | + | |
| 1987 | + | |
| 1988 | + | |
| 1989 | + | |
| 1990 | + | |
| 1991 | + | |
| 1992 | + | |
| 1993 | + | |
| 1994 | + | |
| 1995 | + | |
| 1996 | + | |
| 1997 | + | |
| 1998 | + | |
| 1999 | + | |
| 2000 | + | |
| 2001 | + | |
| 2002 | + | |
| 2003 | + | |
| 2004 | + | |
| 2005 | + | |
| 2006 | + | |
| 2007 | + | |
| 2008 | + | |
| 2009 | + | |
| 2010 | + | |
| 2011 | + | |
1973 | 2012 | | |
| 2013 | + | |
1974 | 2014 | | |
1975 | 2015 | | |
1976 | 2016 | | |
| |||
2007 | 2047 | | |
2008 | 2048 | | |
2009 | 2049 | | |
| 2050 | + | |
2010 | 2051 | | |
| 2052 | + | |
2011 | 2053 | | |
2012 | 2054 | | |
2013 | 2055 | | |
| |||
2044 | 2086 | | |
2045 | 2087 | | |
2046 | 2088 | | |
| 2089 | + | |
2047 | 2090 | | |
| 2091 | + | |
2048 | 2092 | | |
2049 | 2093 | | |
2050 | 2094 | | |
| |||
2082 | 2126 | | |
2083 | 2127 | | |
2084 | 2128 | | |
| 2129 | + | |
2085 | 2130 | | |
| 2131 | + | |
2086 | 2132 | | |
2087 | 2133 | | |
2088 | 2134 | | |
| |||
2112 | 2158 | | |
2113 | 2159 | | |
2114 | 2160 | | |
| 2161 | + | |
2115 | 2162 | | |
| 2163 | + | |
2116 | 2164 | | |
2117 | 2165 | | |
2118 | 2166 | | |
| |||
0 commit comments