Skip to content

Commit 9a2f1a6

Browse files
authored
Add new_trace to Python migration guide (#14492)
We're [adding new API](getsentry/sentry-python#4642) in 3.x, documenting it in the migration guide.
1 parent d7fd2a1 commit 9a2f1a6

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

docs/platforms/python/migration/2.x-to-3.x.mdx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ The `profiles_sample_rate` and `profiler_mode` options previously nested under `
7171

7272
Using `sentry_sdk.add_attachment()` directly also makes sure the attachment is added to the correct scope internally.
7373

74-
### Custom Tracing API
74+
### Tracing
7575

7676
Tracing in the Sentry Python SDK `3.x` is powered by [OpenTelemetry](https://opentelemetry.io/) in the background, which also means we're moving away from the Sentry-specific concept of transactions and towards a span-only future. `sentry_sdk.start_transaction()` is now deprecated in favor of `sentry_sdk.start_span()`.
7777

@@ -81,6 +81,19 @@ Tracing in the Sentry Python SDK `3.x` is powered by [OpenTelemetry](https://ope
8181
...
8282
```
8383

84+
If you start a span, it will automatically become the child of the currently active span. If you want to create a span that should instead start its own trace, use the `new_trace()` context manager.
85+
86+
```python
87+
with sentry_sdk.start_span(name="parent"):
88+
with sentry_sdk.start_span(name="child-of-parent"):
89+
with sentry_sdk.new_trace():
90+
# The first span started in this context manager will become
91+
# a new transaction (root span) with its own trace
92+
with sentry_sdk.start_span(name="new-parent"):
93+
with sentry_sdk.start_span(name="child-of-new-parent"):
94+
...
95+
```
96+
8497
Any spans without a parent span will become transactions by default. If you want to avoid promoting a span without a parent to a transaction, you can pass the `only_if_parent=True` keyword argument to `sentry_sdk.start_span()`.
8598

8699
`sentry_sdk.start_transaction()` and `sentry_sdk.start_span()` no longer take the following arguments: `trace_id`, `baggage`, `span_id`, `parent_span_id`, `custom_sampling_context` (see below). Use `sentry_sdk.continue_trace()` for propagating trace data.

0 commit comments

Comments
 (0)