docs(python): Update stream mode in main tracing files (tracing part 1/3)#18531
docs(python): Update stream mode in main tracing files (tracing part 1/3)#18531inventarSarah wants to merge 4 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
09d3da9 to
1125f9f
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ 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.
| 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({ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
@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
| root_function() | ||
| ``` | ||
|
|
||
| ```python {tabTitle:Stream Mode} | ||
| import sentry_sdk | ||
|
|
||
| @sentry_sdk.traces.trace(name="Paul", attributes={"sentry.op": "my_op", "x": True}) |
There was a problem hiding this comment.
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.

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.
SLA
Thanks in advance for your help!
PRE-MERGE CHECKLIST
Make sure you've checked the following before merging your changes:
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