feat(huggingface_hub): Migrate to span first#6124
Open
ericapisani wants to merge 1 commit intomasterfrom
Open
Conversation
Migrates the huggingface_hub integration to the span-first (streaming
span) architecture.
When `_experiments={"trace_lifecycle": "stream"}` is enabled, the
integration now uses `StreamedSpan` via `sentry_sdk.traces.start_span`
instead of the legacy `Span`-based (transactions) path. The legacy path
remains unchanged for backwards compatibility.
To support both span types from shared AI monitoring utilities,
`record_token_usage` and `set_data_normalized` now accept
`Union[Span, StreamedSpan]` and route attribute writes through a new
private `_set_span_data_attribute` helper in `sentry_sdk.ai.utils`
(calling `set_attribute` on `StreamedSpan` and `set_data` on `Span`).
Part of the broader span-first integration migration.
Fixes PY-2332
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Contributor
Codecov Results 📊✅ 13 passed | Total: 13 | Pass Rate: 100% | Execution Time: 7.23s All tests are passing successfully. ❌ Patch coverage is 23.08%. Project has 14783 uncovered lines. Files with missing lines (3)
Generated by Codecov Action |
alexander-alderman-webb
approved these changes
Apr 22, 2026
Contributor
alexander-alderman-webb
left a comment
There was a problem hiding this comment.
Looks good to me.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Migrates the huggingface_hub integration to the span-first (streaming span) architecture.
When
_experiments={"trace_lifecycle": "stream"}is enabled, the integration now usesStreamedSpanviasentry_sdk.traces.start_spaninstead of the legacySpan-based (transactions) path. The legacy path remains unchanged for backwards compatibility.This is the first AI integration to emit
StreamedSpans, so the shared AI monitoring utilities needed to accept both span types.record_token_usage(sentry_sdk/ai/monitoring.py) andset_data_normalized(sentry_sdk/ai/utils.py) now acceptUnion[Span, StreamedSpan]and route attribute writes through a new private_set_span_data_attributehelper insentry_sdk.ai.utils— callingset_attributeonStreamedSpanandset_dataonSpan. Existing AI integrations (anthropic, openai, cohere, langchain, langgraph, litellm, google_genai, openai_agents, pydantic_ai) are unaffected at runtime: they continue to passSpaninstances, which route toset_datavia the isinstance check.Test coverage mirrors the existing non-streaming suite under streaming mode (text_generation / chat_completion, sync and streaming, with and without tools, plus an error-path test) parametrized over
send_default_piiandinclude_prompts.Part of the broader span-first integration migration.
Fixes PY-2332