Title: OpenAI and Anthropic integrations record no output or usage for `with_raw_response` and `with_streaming_response` calls · Issue #7948 · getsentry/sentry-python · GitHub
Open Graph Title: OpenAI and Anthropic integrations record no output or usage for `with_raw_response` and `with_streaming_response` calls · Issue #7948 · getsentry/sentry-python
X Title: OpenAI and Anthropic integrations record no output or usage for `with_raw_response` and `with_streaming_response` calls · Issue #7948 · getsentry/sentry-python
Description: How do you use Sentry? Sentry Saas (sentry.io) Version 2.71.0 (master 7cb8094) Steps to Reproduce client.messages.with_raw_response.create(...) and client.messages.with_streaming_response.create(...) get a gen_ai.chat span with no respon...
Open Graph Description: How do you use Sentry? Sentry Saas (sentry.io) Version 2.71.0 (master 7cb8094) Steps to Reproduce client.messages.with_raw_response.create(...) and client.messages.with_streaming_response.create(.....
X Description: How do you use Sentry? Sentry Saas (sentry.io) Version 2.71.0 (master 7cb8094) Steps to Reproduce client.messages.with_raw_response.create(...) and client.messages.with_streaming_response.create(.....
Opengraph URL: https://github.com/getsentry/sentry-python/issues/7948
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"OpenAI and Anthropic integrations record no output or usage for `with_raw_response` and `with_streaming_response` calls","articleBody":"### How do you use Sentry?\n\nSentry Saas (sentry.io)\n\n### Version\n\n2.71.0 (master 7cb8094)\n\n### Steps to Reproduce\n\n`client.messages.with_raw_response.create(...)` and `client.messages.with_streaming_response.create(...)` get a `gen_ai.chat` span with no response id, finish reason, token usage or response text. Both return an `APIResponse` and not a `Message`, so the `hasattr(result, \"content\")` check in [anthropic.py#L794](https://github.com/getsentry/sentry-python/blob/7cb80948cbdefb10831740c23b49e56e348532a5/sentry_sdk/integrations/anthropic.py#L794) fails and the span gets `unknown_response`. The OpenAI integration loses the same data on both calls.\n\n```python\nimport httpx2, anthropic, sentry_sdk\nfrom sentry_sdk.integrations.anthropic import AnthropicIntegration\n\nBODY = {\"id\": \"msg_01\", \"type\": \"message\", \"role\": \"assistant\", \"model\": \"claude-sonnet-4-5\",\n \"content\": [{\"type\": \"text\", \"text\": \"hi there\"}], \"stop_reason\": \"end_turn\",\n \"stop_sequence\": None, \"usage\": {\"input_tokens\": 7, \"output_tokens\": 3}}\nevents = []\nsentry_sdk.init(dsn=\"https://k@o0.ingest.sentry.io/0\", traces_sample_rate=1.0, send_default_pii=True,\n integrations=[AnthropicIntegration(include_prompts=True)],\n before_send_transaction=lambda e, h: (events.append(e), None)[1])\nclient = anthropic.Anthropic(api_key=\"x\", http_client=httpx2.Client(transport=httpx2.MockTransport(lambda r: httpx2.Response(200, json=BODY))))\nkw = dict(model=\"claude-sonnet-4-5\", max_tokens=10, messages=[{\"role\": \"user\", \"content\": \"hello\"}])\n\nfor label in (\"create\", \"with_raw_response\", \"with_streaming_response\"):\n with sentry_sdk.start_transaction(name=label):\n if label == \"create\":\n client.messages.create(**kw)\n elif label == \"with_raw_response\":\n client.messages.with_raw_response.create(**kw).parse()\n else:\n with client.messages.with_streaming_response.create(**kw) as r:\n r.parse()\n\nKEYS = (\"gen_ai.response.id\", \"gen_ai.response.finish_reasons\", \"gen_ai.usage.input_tokens\", \"gen_ai.usage.output_tokens\", \"gen_ai.response.text\")\nfor e in events:\n for s in e[\"spans\"]:\n if s[\"op\"] == \"gen_ai.chat\":\n d = s.get(\"data\", {})\n print(f\"{e['transaction']:24}\", {k: k in d for k in KEYS}, \"unknown_response\" if d.get(\"unknown_response\") else \"\")\n```\n\n### Expected Result\n\nThe raw and streaming calls carry the same `gen_ai.*` data as `create`.\n\n### Actual Result\n\n```\n$ python -W ignore repro.py # master 7cb8094, anthropic 1.13.0\ncreate {'gen_ai.response.id': True, 'gen_ai.response.finish_reasons': True, 'gen_ai.usage.input_tokens': True, 'gen_ai.usage.output_tokens': True, 'gen_ai.response.text': True}\nwith_raw_response {'gen_ai.response.id': False, 'gen_ai.response.finish_reasons': False, 'gen_ai.usage.input_tokens': False, 'gen_ai.usage.output_tokens': False, 'gen_ai.response.text': False} unknown_response\nwith_streaming_response {'gen_ai.response.id': False, 'gen_ai.response.finish_reasons': False, 'gen_ai.usage.input_tokens': False, 'gen_ai.usage.output_tokens': False, 'gen_ai.response.text': False} unknown_response\n\n# the same loop on client.chat.completions with OpenAIIntegration and three keys, openai 3.29.0\ncreate {'gen_ai.usage.input_tokens': True, 'gen_ai.usage.output_tokens': True, 'gen_ai.response.text': True}\nwith_raw_response {'gen_ai.usage.input_tokens': False, 'gen_ai.usage.output_tokens': False, 'gen_ai.response.text': False}\nwith_streaming_response {'gen_ai.usage.input_tokens': False, 'gen_ai.usage.output_tokens': False, 'gen_ai.response.text': False}\n# not run: the async clients, or a real endpoint\n```\n\nFor `with_raw_response` the body is already read when `create` returns, so I'd parse it there and end the span the way `create` does. `parse()` caches its result, so the caller pays nothing for it. Only `with_streaming_response` needs the `Stream` treatment from `_sentry_patched_create_sync`: wrap `parse()` to set the output and `close()` to end the span, since parsing at return would buffer a body the caller asked to stream.\n\nRelated: #5939 would still route these to `unknown_response`, because an `APIResponse` has no `type`, and #7891 is the `parse()` gap next to it.\n\n@alexander-alderman-webb this is the span-lifetime question from #7847 again, for `APIResponse`. I'd fix both in one change, since both touch `openai.py`. Is that already in the work you have planned for #7891?\n","author":{"url":"https://github.com/chrikrah","@type":"Person","name":"chrikrah"},"datePublished":"2026-10-12T07:12:34Z","url":"https://github.com/getsentry/sentry-python/issues/7948"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:5e561355-2ba5-695e-e929-a2380014772a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9A14:14ECB:6DFC1:8F640:6B00C523 |
| html-safe-nonce | 003ae647016703d8e30513757ecfcf9a1a844e8a58258bbf0f94e75a8178cda8 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5QTE0OjE0RUNCOjZERkMxOjhGNjQwOjZCMDBDNTIzIiwidmlzaXRvcl9pZCI6IjM0NjE4MTczMzU0MjAwNzczNDciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | e8a11ba37b13d710badb7c480f1bd1e995f2cf93026b44eb0ee541011b4eba1d |
| hovercard-subject-tag | issue:5809808550 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/getsentry/sentry-python/7948/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f317bf9613f50dbd2d462510d80011dcae24ac66f71a4d8706dc0bbc8c8bd747/getsentry/sentry-python/issues/7948 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f317bf9613f50dbd2d462510d80011dcae24ac66f71a4d8706dc0bbc8c8bd747/getsentry/sentry-python/issues/7948 |
| og:image:alt | How do you use Sentry? Sentry Saas (sentry.io) Version 2.71.0 (master 7cb8094) Steps to Reproduce client.messages.with_raw_response.create(...) and client.messages.with_streaming_response.create(..... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | chrikrah |
| hostname | github.com |
| expected-hostname | github.com |
| None | 93edd3bebc4afb7ce711ee74cb5d2a95927850b082a4d43e212222389cb1c415 |
| turbo-cache-control | no-preview |
| go-import | github.com/getsentry/sentry-python git https://github.com/getsentry/sentry-python.git |
| octolytics-dimension-user_id | 1396951 |
| octolytics-dimension-user_login | getsentry |
| octolytics-dimension-repository_id | 137814779 |
| octolytics-dimension-repository_nwo | getsentry/sentry-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 137814779 |
| octolytics-dimension-repository_network_root_nwo | getsentry/sentry-python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 1fee81a280ea86312b69448e261b418189bfd5b5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width