Skip to content

feat: Add Python span streaming migration skill#156

Open
sentrivana wants to merge 21 commits into
mainfrom
ivana/python-migration-skill
Open

feat: Add Python span streaming migration skill#156
sentrivana wants to merge 21 commits into
mainfrom
ivana/python-migration-skill

Conversation

@sentrivana
Copy link
Copy Markdown

@sentrivana sentrivana commented Jun 3, 2026

  • Reorg so that each SDK is its own skill
  • Add Python skill

chargome and others added 6 commits May 15, 2026 14:36
String matching in ignoreSpans uses substring includes, not glob
patterns. The `*` was treated as a literal character.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Reorganize the skill so each SDK (JavaScript, Python) has its own
self-contained top-level section with the full detect-migrate-verify
flow, instead of mixing SDK-specific content under shared phase headings.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Covers the full migration flow: enabling span streaming, migrating
start_span/start_transaction/start_child/@trace/get_current_span,
span data (set_data/set_tag/set_context to set_attribute), trace
propagation (continue_trace, new_trace), sampling, ignore_spans,
before_send_span, verification, and quick reference checklist.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@sentrivana sentrivana marked this pull request as ready for review June 3, 2026 10:28
Comment thread skills/sentry-span-streaming-python/SKILL.md
Comment thread skills/sentry-span-streaming/SKILL.md Outdated
Comment thread skills/sentry-span-streaming-python/SKILL.md
@sentrivana sentrivana marked this pull request as draft June 3, 2026 10:35
Comment thread skills/sentry-span-streaming-python/SKILL.md
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 494c651. Configure here.

Comment thread skills/sentry-span-streaming-python/SKILL.md
@sentrivana sentrivana marked this pull request as ready for review June 3, 2026 13:50
Comment thread skills/sentry-span-streaming/SKILL.md Outdated
Comment thread skills/sentry-span-streaming-python/SKILL.md
@sentrivana sentrivana marked this pull request as draft June 3, 2026 14:32
Each skill is now self-contained with its own intro, detection,
migration steps, verification, and checklist. The old combined
sentry-span-streaming skill is removed; the parent router and
skill tree now point to both new skills directly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Users importing Span or Transaction directly from sentry_sdk.tracing
need to replace both with StreamedSpan from sentry_sdk.traces.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Base automatically changed from cg/span-streaming-skill to main June 5, 2026 09:04
sentrivana and others added 8 commits June 5, 2026 11:43
Encourage agents to launch subagents for independent migration tasks
when the codebase has many files to migrate.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…butes in span streaming

In streaming mode, ignore_spans and before_send_span can only access
attributes set at span start. Logic depending on late-set attributes
(e.g. HTTP status codes) cannot be replicated and must be removed.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…igration patterns

Add migration guidance for uncommon patterns: scope-based span/transaction
access and get_trace_context. Includes detection greps, before/after
examples, common issues, and checklist items.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…et_attributes

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@sentrivana sentrivana marked this pull request as ready for review June 5, 2026 11:36
@sentrivana sentrivana linked an issue Jun 5, 2026 that may be closed by this pull request

def traces_sampler(sampling_context):
if sampling_context["asgi_scope"].method not in ("GET", "POST"):
return 0.0
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The example code for traces_sampler incorrectly uses attribute access (.method) on the asgi_scope dictionary, which will cause a runtime AttributeError.
Severity: HIGH

Suggested Fix

Update the example code to use dictionary key access to retrieve the method from the asgi_scope. Change sampling_context["asgi_scope"].method to sampling_context["asgi_scope"]["method"].

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: skills/sentry-span-streaming-python/SKILL.md#L463

Potential issue: The example code for `traces_sampler` in the documentation demonstrates
accessing the `method` from `sampling_context["asgi_scope"]` using attribute notation
(`.method`). According to the ASGI specification, the scope is a dictionary, not an
object. Attempting to access a dictionary key with attribute notation will result in an
`AttributeError: 'dict' object has no attribute 'method'` at runtime. This will crash
the sampling logic for any developer who copies this example code into their
application.

...

# After
sentry_sdk.scope.Scope.set_custom_sampling_context({"asgi_scope": asgi_scope})
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The migration example calls sentry_sdk.scope.Scope.set_custom_sampling_context, which appears to be a non-existent class method, leading to a runtime error.
Severity: HIGH

Suggested Fix

Verify if the set_custom_sampling_context method exists and what its correct usage is. If it's an instance method, the example should show how to get a scope instance and call it. If it doesn't exist, the example should be corrected to use the proper API for setting custom sampling context, such as passing it to start_transaction.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: skills/sentry-span-streaming-python/SKILL.md#L474

Potential issue: The documentation provides a migration example that uses
`sentry_sdk.scope.Scope.set_custom_sampling_context(...)`. This method does not appear
to exist in the Sentry Python SDK's documented API. Furthermore, it is called as a class
method on `Scope`, whereas scope modifications are typically instance-level operations.
Developers following this migration guide will encounter a runtime `AttributeError`
because the method is not defined on the `Scope` class.

sentrivana and others added 2 commits June 5, 2026 14:40
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…bute

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

headers = {
"sentry-trace": "4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-1",
"baggage": "sentry-trace_id=...",
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The baggage header example is incomplete, showing only sentry-trace_id. This can break distributed tracing and sampling as it omits other required fields.
Severity: MEDIUM

Suggested Fix

Update the baggage header example to be more representative of a real-world header. Include other common fields to show that it's a multi-part value, for example: "baggage": "sentry-trace_id=...,sentry-environment=production,...". This provides a more accurate and less misleading example for users implementing trace propagation.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: skills/sentry-span-streaming-python/SKILL.md#L433

Potential issue: The code example for the `baggage` header in the `continue_trace`
section is incomplete. It only shows `"baggage": "sentry-trace_id=..."`. A real-world
`baggage` header contains multiple comma-separated key-value pairs (e.g.,
`sentry-environment`, `sentry-public_key`, `sentry-release`) which are essential for the
Dynamic Sampling Context (DSC). Users or AI agents copying this example would generate
incomplete headers, leading to broken trace continuity and incorrect sampling decisions
across distributed services. This is particularly problematic in a section meant to
guide users on migrating trace propagation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create migration skill

2 participants