Title: LiteLLMIntegration stores a non-JSON-serializable Span in request metadata, breaking outbound LLM requests · Issue #6596 · getsentry/sentry-python · GitHub
Open Graph Title: LiteLLMIntegration stores a non-JSON-serializable Span in request metadata, breaking outbound LLM requests · Issue #6596 · getsentry/sentry-python
X Title: LiteLLMIntegration stores a non-JSON-serializable Span in request metadata, breaking outbound LLM requests · Issue #6596 · getsentry/sentry-python
Description: How do you use Sentry? Sentry SaaS (sentry.io) Version sentry-sdk 2.52.0 (also present on current master); litellm 1.81.9; Python 3.13 Steps to Reproduce With the LiteLLM integration enabled, any call that passes caller metadata crashes ...
Open Graph Description: How do you use Sentry? Sentry SaaS (sentry.io) Version sentry-sdk 2.52.0 (also present on current master); litellm 1.81.9; Python 3.13 Steps to Reproduce With the LiteLLM integration enabled, any c...
X Description: How do you use Sentry? Sentry SaaS (sentry.io) Version sentry-sdk 2.52.0 (also present on current master); litellm 1.81.9; Python 3.13 Steps to Reproduce With the LiteLLM integration enabled, any c...
Opengraph URL: https://github.com/getsentry/sentry-python/issues/6596
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"LiteLLMIntegration stores a non-JSON-serializable Span in request metadata, breaking outbound LLM requests","articleBody":"### How do you use Sentry?\n\nSentry SaaS (sentry.io)\n\n### Version\n\n`sentry-sdk` 2.52.0 (also present on current `master`); `litellm` 1.81.9; Python 3.13\n\n### Steps to Reproduce\n\nWith the LiteLLM integration enabled, any call that passes caller `metadata` crashes during request serialization:\n\n```python\nimport asyncio, litellm, sentry_sdk\nfrom sentry_sdk.integrations.litellm import LiteLLMIntegration\n\nsentry_sdk.init(\n dsn=\"\u003cyour-dsn\u003e\", traces_sample_rate=1.0,\n send_default_pii=True, integrations=[LiteLLMIntegration()],\n)\n\nasync def main():\n await litellm.anthropic.messages.acreate(\n model=\"anthropic/claude-3-5-sonnet-latest\",\n messages=[{\"role\": \"user\", \"content\": \"hi\"}],\n max_tokens=16, stream=True, api_key=\"sk-ant-...\",\n metadata={\"user_id\": \"my-org\"}, # Anthropic abuse-isolation id\n )\n\nasyncio.run(main())\n```\n\n**Root cause:** `_input_callback` stores the live span via `_get_metadata_dict(kwargs)[\"_sentry_span\"] = span` (`sentry_sdk/integrations/litellm.py`). litellm's Anthropic `/v1/messages` passthrough forwards `metadata` into the request body, so the live `Span` lands at `request_body['metadata']['_sentry_span']` and `json.dumps(request_body)` fails — before the request is sent.\n\n### Expected Result\n\nEnabling the integration must not make outbound provider requests unserializable. The integration's bookkeeping span should be stashed off-band (e.g. a `WeakKeyDictionary` keyed on the logging object) rather than written into the caller's request `metadata` dict, which several providers (Anthropic here) forward into the wire payload.\n\n### Actual Result\n\n```\nTypeError: Object of type Span is not JSON serializable\n```\n\n(a `Transaction` when there is no active parent span). Separately, with `send_default_pii=True` + `include_prompts=True` (the default), that span's `gen_ai.request.messages` holds the **verbatim prompt** — so any sink that serializes this span object can leak prompt content.\n\n---\n\nRelated (defense-in-depth, downstream): litellm forwards/serializes this injected metadata into the provider body. Companion issue filed at BerriAI/litellm — see comment below. litellm has stripped such span objects in other logging paths: BerriAI/litellm#15728, BerriAI/litellm#12354.\n","author":{"url":"https://github.com/jgreer013","@type":"Person","name":"jgreer013"},"datePublished":"2026-06-17T16:41:36.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/6596/sentry-python/issues/6596"}
| 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:9334b812-f26f-d7b1-db28-fe67c7e6aaff |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A454:633B1:494BB2:682D84:6A4E6F43 |
| html-safe-nonce | afec865bdf5525679c165eb74c034e923b8be2c8bcae57ff5ee57adc72b468d0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNDU0OjYzM0IxOjQ5NEJCMjo2ODJEODQ6NkE0RTZGNDMiLCJ2aXNpdG9yX2lkIjoiNDEyOTA2ODkyODkzNTU1NDg4MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | daf0dbedb77e28b847c711b00b560af229824f1daadf2f3a3fc4b3e5985c08ab |
| hovercard-subject-tag | issue:4685241714 |
| 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/6596/issue_layout |
| twitter:image | https://opengraph.githubassets.com/fbb23c05d75e642e59b4cdbc1a69ced37484756a162f2c7f209e320f44559e4e/getsentry/sentry-python/issues/6596 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/fbb23c05d75e642e59b4cdbc1a69ced37484756a162f2c7f209e320f44559e4e/getsentry/sentry-python/issues/6596 |
| og:image:alt | How do you use Sentry? Sentry SaaS (sentry.io) Version sentry-sdk 2.52.0 (also present on current master); litellm 1.81.9; Python 3.13 Steps to Reproduce With the LiteLLM integration enabled, any c... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jgreer013 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 41b6ab3ba6d20a71766ac245b5a4a94c6fc672a9cd4da7d44c1b33ab8bf6a21c |
| 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 | e6a744804e8e70f97b4d5a18a94dcc63db22f97a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width