Skip to content

Commit 63c6cc4

Browse files
authored
feat(python): Clarification regarding start_transaction (#12835)
1 parent fab9e13 commit 63c6cc4

File tree

2 files changed

+9
-3
lines changed
  • docs/platforms/python/tracing/instrumentation/custom-instrumentation
  • platform-includes/distributed-tracing/custom-instrumentation

2 files changed

+9
-3
lines changed

docs/platforms/python/tracing/instrumentation/custom-instrumentation/index.mdx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Custom Instrumentation
33
description: "Learn how to capture performance data on any action in your app."
44
---
55

6-
The Sentry SDK for Python does a very good job of auto instrumenting your application. If you use one of the popular frameworks, we've got you covered because well-known operations like HTTP calls and database queries will be instrumented out of the box. The Sentry SDK will also check your installed Python packages and auto enable the matching SDK integrations. If you want to enable tracing in a piece of code that performs some other operations, add the @sentry_sdk.trace decorator"
6+
The Sentry SDK for Python does a very good job of auto instrumenting your application. If you use one of the popular frameworks, we've got you covered because well-known operations like HTTP calls and database queries will be instrumented out of the box. The Sentry SDK will also check your installed Python packages and auto-enable the matching SDK integrations. If you want to enable tracing in a piece of code that performs some other operations, add the `@sentry_sdk.trace` decorator.
77

88
## Add a Transaction
99

@@ -31,6 +31,12 @@ def eat_pizza(pizza):
3131

3232
The [API reference](https://getsentry.github.io/sentry-python/api.html#sentry_sdk.api.start_transaction) documents `start_transaction` and all its parameters.
3333

34+
<Alert>
35+
36+
Note that `sentry_sdk.start_transaction()` is meant be used as a context manager. This ensures that the transaction will be properly set as active and any spans created within will be attached to it.
37+
38+
</Alert>
39+
3440
## Add Spans to a Transaction
3541

3642
If you want to have more fine-grained performance monitoring, you can add child spans to your transaction, which can be done by either:
@@ -39,7 +45,7 @@ If you want to have more fine-grained performance monitoring, you can add child
3945
- Using a decorator (this works on sync and async functions)
4046
- Manually starting and finishing a span
4147

42-
Calling a `sentry_sdk.start_span()` will find the current active transaction and attach the span to it.
48+
Calling `sentry_sdk.start_span()` will find the current active transaction and attach the span to it.
4349

4450
### Using a Context Manager
4551

platform-includes/distributed-tracing/custom-instrumentation/python.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ headers = get_incoming_headers_as_dict()
2020

2121
transaction = sentry_sdk.continue_trace(headers)
2222
with sentry_sdk.start_transaction(transaction):
23-
...
23+
...
2424
```
2525

2626
In this example, `get_incoming_headers_as_dict()` returns a dictionary that contains tracing information from HTTP headers, environment variables, or any other mechanism your project uses to communicate with the outside world.

0 commit comments

Comments
 (0)