Skip to content

docs(python): Update stream mode in main tracing files (tracing part 1/3)#18531

Open
inventarSarah wants to merge 4 commits into
masterfrom
smi/span-first/python-tracing-1
Open

docs(python): Update stream mode in main tracing files (tracing part 1/3)#18531
inventarSarah wants to merge 4 commits into
masterfrom
smi/span-first/python-tracing-1

Conversation

@inventarSarah

Copy link
Copy Markdown
Collaborator

DESCRIBE YOUR PR

This PR updates pages under Tracing with information about the new stream mode and the new Span APIs.

Part 1 out of 3
(result of splitting up PR #18511 into smaller parts)

Important

Broken links: I added links to the New Spans guide on these pages, but since this guide does not exist in this branch, we get a linting error.
Should only be merged after #18456

IS YOUR CHANGE URGENT?

Help us prioritize incoming PRs by letting us know when the change needs to go live.

  • Urgent deadline (GA date, etc.):
  • Other deadline:
  • None: Not urgent, can wait up to 1 week+

SLA

  • Teamwork makes the dream work, so please add a reviewer to your PRs.
  • Please give the docs team up to 1 week to review your PR unless you've added an urgent due date to it.
    Thanks in advance for your help!

PRE-MERGE CHECKLIST

Make sure you've checked the following before merging your changes:

  • Checked Vercel preview for correctness, including links
  • PR was reviewed and approved by any necessary SMEs (subject matter experts)
  • PR was reviewed and approved by a member of the Sentry docs team

LEGAL BOILERPLATE

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.

EXTRA RESOURCES

@vercel

vercel Bot commented Jun 24, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
sentry-docs Ready Ready Preview, Comment Jun 24, 2026 1:18pm
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
develop-docs Ignored Ignored Preview Jun 24, 2026 1:18pm

Request Review

@inventarSarah inventarSarah force-pushed the smi/span-first/python-tracing-1 branch from 09d3da9 to 1125f9f Compare June 24, 2026 11:50
@inventarSarah inventarSarah marked this pull request as ready for review June 24, 2026 11:50
Comment thread docs/platforms/python/tracing/span-lifecycle/index.mdx Outdated
Comment thread docs/platforms/python/tracing/span-lifecycle/index.mdx Outdated
Comment thread docs/platforms/python/tracing/instrumentation/custom-instrumentation/index.mdx Outdated

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

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.

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 01ddcd6. Configure here.

Comment thread docs/platforms/python/tracing/span-metrics/index.mdx
Comment thread docs/platforms/python/tracing/instrumentation/custom-instrumentation/index.mdx Outdated
Comment thread docs/platforms/python/tracing/instrumentation/custom-instrumentation/index.mdx Outdated
def before_send_span(span, hint):
# Runs once per span, as it's flushed.
# Only attributes set at span-creation time are available here.
span["attributes"].update({

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bug: The before_send_span example accesses span["attributes"] without checking if the key exists, which could cause a KeyError at runtime.
Severity: MEDIUM

Suggested Fix

Update the code example to be more defensive. Before accessing span["attributes"], check if the key exists. If it does not, initialize it as an empty dictionary. For example: if "attributes" not in span: span["attributes"] = {}.

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: platform-includes/tracing/span-metrics/add-all-spans/python.mdx#L45

Potential issue: The Python code example for the `before_send_span` callback directly
accesses `span["attributes"]` to update it. However, the span protocol specifies that
the `attributes` field is optional. If a span is processed that does not have an
`attributes` key, this code will raise a `KeyError`, crashing the callback. The example
code does not defensively check for the existence of the `attributes` key before
attempting to access it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@alexander-alderman-webb @ericapisani
is attributes always present on the span object here or can it be missing? This also affects one example on the New Spans page

Comment on lines 337 to +343
root_function()
```

```python {tabTitle:Stream Mode}
import sentry_sdk

@sentry_sdk.traces.trace(name="Paul", attributes={"sentry.op": "my_op", "x": True})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bug: The Python code examples for custom instrumentation have incorrect leading spaces, which will cause an IndentationError when copied and run.
Severity: MEDIUM

Suggested Fix

Remove the extra leading spaces from the lines within the Python code blocks in the index.mdx file. Ensure that the indentation level is correct for all lines of code in both the 'Transaction Mode' and 'Stream Mode' examples.

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:
docs/platforms/python/tracing/instrumentation/custom-instrumentation/index.mdx#L337-L343

Potential issue: The Python code examples for custom instrumentation using the
`@sentry_sdk.trace` decorator have incorrect indentation. In the 'Transaction Mode'
example, most lines have an extra leading space. In the 'Stream Mode' example, lines
after the `import` statement also have an extra leading space. This will cause a Python
`IndentationError: unexpected indent` for users who copy and paste the code, preventing
them from running the examples successfully.

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.

2 participants