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: docs/platforms/react-native/tracing/instrumentation/custom-instrumentation.mdx
+23-23Lines changed: 23 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,19 +26,19 @@ There are three key functions for creating spans:
26
26
27
27
## Active vs. Inactive Spans
28
28
29
-
When a new span is started, it will automatically be started as a child of the currently active span, if there is one. This means that if a span is started as an **active span**, any spans that are created inside of the callback where the span is active will be children of that span. Additionally, errors will be tied to the currently active span, if there is one.
29
+
If there's a currently active span when a new span is started, the new span will automatically start as a child span of the currently active one. This means, that if a span is started as an **active span**, it will be the parent span and any spans created inside the callback will be children of that span. Errors will be tied to the parent span, if there is one.
30
30
31
-
In contrast, **inactive spans** will never have children automatically associated with them. This is useful if you do not care about capturing child activity.
31
+
In contrast, **inactive spans** will never have children automatically associated with them. This is useful if you don't care about capturing child activity.
32
32
33
-
A key constraint for active spans is that they can only be made active inside of a callback. This constraint exists because otherwise it becomes impossible to associate spans with the correct parent span when working with asynchronous code.
33
+
A key constraint for active spans is that they can only be made active inside of a callback. This constraint exists because otherwise it would be impossible to associate child spans with the correct parent span when working with asynchronous code.
34
34
35
-
In places where you are not able to wrap executing code in a callback (e.g. when working with hooks or similar) you have to work with inactive spans, and can combine this with [withActiveSpan](#withactivespan) to manually associate child spans with the correct parent span.
35
+
If you're unable to wrap executing code in a callback (for example, when working with hooks or similar) you'll have to work with inactive spans, and can combine this with [withActiveSpan](#withactivespan) to manually associate child spans with the correct parent span.
36
36
37
37
## Span Hierarchy
38
38
39
-
In browser and mobile environments, spans are by default collected in a flat hierarchy where every span is the direct child of the root span.
39
+
In browser and mobile environments, spans are collected in a flat hierarchy where every span is the direct child of the root span by default.
40
40
41
-
The key reason for keeping a flat hierarchy is because it's impossible to reliably keep track of the active span across asynchronous boundaries. This means that if multiple asynchronous operations are started in parallel, it is not possible to determine which span is the parent of which child span. Imagine the following example:
41
+
The key reason for keeping a flat hierarchy is because if multiple asynchronous operations were started in parallel, it wouldn't be possible to determine which span is the parent of which child span. Imagine the following example:
In the browser, there would be no way to know that `span 1` is only active inside of its callback, while `span 2` is active in the other callback. Because of this, in reality, _all_ fetch spans would become children of `span 2`. This is misleading and confusing, which is why by default in the browser, **all spans will become children of the root span** (which is usually the pageload or navigation span). This means that you will always have a flat hierarchy of spans.
57
+
In the browser, there would be no way to know that `span 1` is only active inside of its callback, while `span 2` is active in the other callback. Without a flat hierarchy, _all_ fetch spans would become children of `span 2`. This would be misleading and confusing, which is why we've made it so that in the browser, **all spans become children of the root span** (which is usually the pageload or navigation span) by default. This makes it so that you'll always have a flat hierarchy of spans.
58
58
59
-
This is a tradeoff that we have made to ensure that the data that is captured is accurate and reliable. If you need to capture a more complex hierarchy of spans, you can opt-out of this behavior by setting `parentSpanIsAlwaysRootSpan: false`:
59
+
This is a tradeoff we've made to ensure that the data that's captured is accurate and reliable. If you need to capture a more complex hierarchy of spans, you can optout of this behavior by setting `parentSpanIsAlwaysRootSpan: false`:
60
60
61
61
```javascript
62
62
Sentry.init({
63
63
parentSpanIsAlwaysRootSpan:false,
64
64
});
65
65
```
66
66
67
-
This will revert to use the full hierarchy behavior, where spans are children of the currently active span. However, this may lead to incorrect data in the case of multiple parallel asynchronous operations - it is up to you to ensure there are no multiple parallel asynchronous operations that start spans in this case.
67
+
If you choose to revert to using full hierarchy behavior where spans are children of the currently active span, you'll have to make sure there are no multiple parallel asynchronous operations that start spans. Otherwise, you may get incorrect data.
68
68
69
69
## Span Starting Options
70
70
@@ -76,11 +76,11 @@ The following options can be used for all span starting functions:
76
76
|`op`|`string`| The operation of the span. |
77
77
|`startTime`|`number`| The start time of the span. |
78
78
|`attributes`|`Record<string, Primitive>`| Attributes to attach to the span. |
79
-
|`parentSpan`|`Span`| If set, make the span a child of the specified span. Otherwise, the span will be a child of the currently active span. |
80
-
|`onlyIfParent`|`boolean`| If true, ignore the span if there is no active parent span. |
81
-
|`forceTransaction`|`boolean`| If true, ensure this span shows up as transaction in the Sentry UI. |
79
+
|`parentSpan`|`Span`| If set, makes the span a child of the specified span. Otherwise, the span will be a child of the currently active span. |
80
+
|`onlyIfParent`|`boolean`| If true, ignores the span if there's no active parent span. |
81
+
|`forceTransaction`|`boolean`| If true, ensures this span shows up as a transaction in the Sentry UI. |
82
82
83
-
Only `name` is required, all other options are optional.
83
+
The only option that's required is `name`. All other options are optional.
84
84
85
85
## Starting an Active Span (`startSpan`)
86
86
@@ -90,19 +90,19 @@ For most scenarios, we recommend to start active spans with `Sentry.startSpan()`
90
90
91
91
## Starting an Active Span with Manual End (`startSpanManual`)
92
92
93
-
Sometimes, you do not want the span to be ended automatically when the callback is done. In this case, you can use `Sentry.startSpanManual()`. This will start a new span that is active in the provided callback, but will not be automatically ended when the callback is done. You have to manually end the span by calling `span.end()`.
93
+
There are times when you don't want a span to be ended automatically as soon as the callback is done. In this case, you can use `Sentry.startSpanManual()`. This will start a new active span in the provided callback, but it won't be automatically ended when the callback is done. You'll have to manually end the span by calling `span.end()`.
To add spans that aren't active, you can create independent spans. This is useful when you have work that is grouped together under a single parent span, but is independent from the currently active span. However, in most cases you'll want to create and use the [startSpan](#starting-an-active-span-startspan) API from above.
99
+
To add spans that aren't active, you can create independent spans. This is useful when you have work that's grouped together under a single parent span, but is independent from the currently active span. However, in most cases you'll want to create and use the [startSpan](#starting-an-active-span-startspan) API from above.
By default, any span that is started will be the child of the currently active span. If you want to have a different behavior, you can force spans to be the children of a specific span with the `parentSpan` option:
105
+
By default, any span that's started will be the child of the currently active span. If you want to have a different behavior, you can force spans to be the children of a specific span with the `parentSpan` option:
Suppress the creation of sampled spans for the duration of the callback. This is useful when you want to prevent certain spans from being captured. For example, if you do not want to create spans for a given fetch request, you can do:
176
+
Suppress the creation of sampled spans for the duration of the callback. This is useful when you want to prevent certain spans from being captured. For example, if you don't want to create spans for a given fetch request, you can do:
You can capture span attributes along with your spans. Span attributes can be of type `string`, `number` or `boolean`, as well as (non-mixed) arrays of these types. You can specify attributes when starting a span:
188
+
You can capture span attributes along with your spans. Span attributes can be of type:`string`, `number`, or `boolean`, as well as (non-mixed) arrays of these types. You can specify attributes when starting a span:
189
189
190
190
```javascript
191
191
Sentry.startSpan(
@@ -202,7 +202,7 @@ Sentry.startSpan(
202
202
);
203
203
```
204
204
205
-
Or you can also add attributes to an existing span:
205
+
You can also add attributes to an existing span:
206
206
207
207
```javascript
208
208
constspan=Sentry.getActiveSpan();
@@ -218,7 +218,7 @@ if (span) {
218
218
219
219
### Adding Span Operations ("op")
220
220
221
-
Spans can have an operation associated with them, which help activate Sentry identify additional context about the span. For example databaserelated spans have the `db` span operation associated with them. The Sentry product offers additional controls, visualizations and filters for spans with known operations.
221
+
Spans can have an operation associated with them, which help activate Sentry and identify additional context about the span. For example, database-related spans have the `db` span operation associated with them. The Sentry product offers additional controls, visualizations, and filters for spans with known operations.
222
222
223
223
Sentry maintains a [list of well known span operations](https://develop.sentry.dev/sdk/performance/span-operations/#list-of-operations) and it is recommended that you use one of those operations if it is applicable to your span.
224
224
@@ -235,7 +235,7 @@ if (span) {
235
235
}
236
236
```
237
237
238
-
Please note that in certain scenarios, the span name will be overwritten by the SDK. This is the case for spans with any of the following attribute combinations:
238
+
Please note, that in certain scenarios, the span name will be overwritten by the SDK. This is the case for spans with any of the following attribute combinations:
239
239
240
240
* Spans with `http.method` or `http.request.method` attributes will automatically have their name set to the method + the URL path
241
241
* Spans with `db.system` attributes will automatically have their name set to the system + the statement
0 commit comments