You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/collections/_documentation/performance-monitoring/configuration/javascript.md
+18-1Lines changed: 18 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -214,6 +214,24 @@ Sentry.init({
214
214
});
215
215
```
216
216
217
+
**Retrieving a Transaction**
218
+
219
+
In cases where you want to attach Spans to an already ongoing Transaction you can use `Sentry.getCurrentHub().getScope().getTransaction()`. This function will return a `Transaction` in case there is a running Transaction otherwise it returns `undefined`. If you are using our Tracing integration by default we attach the Transaction to the Scope. So you could do something like this:
**Adding Query Information and Parameters to Spans**
218
236
219
237
Currently, every tag has a maximum character limit of 200 characters. Tags over the 200 character limit will become truncated, losing potentially important information. To retain this data, you can split data over several tags instead.
In cases where you want to attach Spans to an already ongoing Transaction you can use `Sentry.getCurrentHub().getScope().getTransaction()`. This function will return a `Transaction` in case there is a running Transaction otherwise it returns `undefined`. If you are using our Express integration by default we attach the Transaction to the Scope. So you could do something like this:
Copy file name to clipboardExpand all lines: src/collections/_documentation/performance-monitoring/configuration/python.md
+68-13Lines changed: 68 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -70,36 +70,91 @@ To manually instrument certain regions of your code, you can create a transactio
70
70
The following example creates a transaction for a scope that contains an expensive operation (for example, `process_item`), and sends the result to Sentry:
with start_transaction(op="task", name=item.get_transaction_name()):
79
79
# process_item may create more spans internally (see next examples)
80
80
process_item(item)
81
81
```
82
82
83
83
**Adding More Spans to the Transaction**
84
84
85
-
The next example contains the implementation of the hypothetical `process_item` function called from the code snippet in the previous section. Our SDK can determine if there is currently an open transaction and add all newly created spans as child operations to that transaction. Keep in mind that each individual span also needs to be manually finished; otherwise, spans will not show up in the transaction.
85
+
The next example contains the implementation of the hypothetical `process_item` function called from the code snippet in the previous section. Our SDK can determine if there is currently an open transaction and add all newly created spans as child operations to that transaction. Keep in mind that each individual span also needs to be manually finished; otherwise, spans will not show up in the transaction. When using spans and transactions as context managers, they are automatically finished at the end of the `with` block.
86
+
87
+
In cases where you want to attach Spans to an already ongoing Transaction you can use `Hub.current.scope.transaction`. This property will return a `Transaction` in case there is a running Transaction otherwise it returns `None`.
88
+
89
+
Alternatively, instead of adding to the top-level transaction, you can make a child span of the current span, if there is one. Use ``Hub.current.scope.span` in that case.
86
90
87
91
You can choose the value of `op` and `description`.
88
92
89
93
```python
90
-
import sentry_sdk
94
+
from sentry_sdkimport Hub
91
95
92
96
defprocess_item(item):
97
+
transaction = Hub.current.scope.transaction
98
+
# omitted code...
99
+
with transaction.start_child(op="http", description="GET /") as span:
In cases where you want to attach Spans to an already ongoing Transaction you can use `Hub.current.scope.transaction`. This property will return a `Transaction` in case there is a running Transaction otherwise it returns `None`.
124
+
125
+
```python
126
+
from sentry_sdk import Hub
127
+
128
+
transaction = Hub.current.scope.transaction
129
+
130
+
if transaction isNone:
131
+
with start_transaction(name="task"):
132
+
do_task()
133
+
else:
134
+
transaction.name ="new name"
135
+
with transaction.start_child(op="task"):
136
+
do_task()
137
+
```
138
+
139
+
#### Retrieving the current Span
140
+
141
+
Started spans are stored in the scope, and can be fetched off the scope:
142
+
143
+
```python
144
+
from sentry_sdk import Hub
145
+
146
+
span = Hub.current.scope.span
147
+
148
+
if span isNone:
149
+
# no span in progress, create new transaction
150
+
with start_transaction(name="task"):
151
+
do_task()
152
+
else:
153
+
# new task span as child of current span
154
+
with span.start_child(op="task"):
155
+
do_task()
156
+
```
157
+
103
158
**Adding Query Information and Parameters to Spans**
104
159
105
160
Currently, every tag has a maximum character limit of 200 characters. Tags over the 200 character limit will become truncated, losing potentially important information. To retain this data, you can split data over several tags instead.
@@ -116,10 +171,10 @@ Instead, using `span.set_tag` splits the details of this query over several tags
116
171
```python
117
172
import sentry_sdk
118
173
...
119
-
with sentry_sdk.start_span(op="request", transaction="setup form") asspan:
120
-
span.set_tag("base_url", base_url)
121
-
span.set_tag("endpoint", endpoint)
122
-
span.set_tag("parameters", parameters)
174
+
with sentry_sdk.start_transaction(op="request", name="setup form") astransaction:
0 commit comments