|
1 | 1 | # New Performance APIs in v8
|
2 | 2 |
|
3 |
| -> [!WARNING] This document is WIP. We are working on this while we are preparing v8. |
4 |
| -
|
5 | 3 | In v8.0.0, we moved to new performance APIs. These APIs have been introduced in v7, so they can already be used there.
|
6 | 4 | However, in v8 we have removed the old performance APIs, so you have to update your manual instrumentation usage to the
|
7 | 5 | new APIs before updating to v8 of the JavaScript SDKs.
|
@@ -36,72 +34,6 @@ In the new model, transactions are conceptually gone. Instead, you will _always_
|
36 | 34 | the tree you are. Note that in the background, spans _may_ still be grouped into a transaction for the Sentry UI.
|
37 | 35 | However, this happens transparently, and from an SDK perspective, all you have to think about are spans.
|
38 | 36 |
|
39 |
| -## The Span schema |
40 |
| - |
41 |
| -Previously, spans & transactions had a bunch of properties and methods to be used. Most of these have been removed in |
42 |
| -favor of a slimmer, more straightforward API, which is also aligned with OpenTelemetry Spans. You can refer to the table |
43 |
| -below to see which things used to exist, and how they can/should be mapped going forward: |
44 |
| - |
45 |
| -| Old name | Replace with | |
46 |
| -| --------------------- | ---------------------------------------------------- | |
47 |
| -| `traceId` | `spanContext().traceId` | |
48 |
| -| `spanId` | `spanContext().spanId` | |
49 |
| -| `parentSpanId` | `spanToJSON(span).parent_span_id` | |
50 |
| -| `status` | use utility method TODO | |
51 |
| -| `sampled` | `spanIsSampled(span)` | |
52 |
| -| `startTimestamp` | `startTime` - note that this has a different format! | |
53 |
| -| `tags` | use attributes, or set tags on the scope | |
54 |
| -| `data` | `spanToJSON(span).data` | |
55 |
| -| `transaction` | ??? Removed | |
56 |
| -| `instrumenter` | Removed | |
57 |
| -| `finish()` | `end()` | |
58 |
| -| `end()` | Same | |
59 |
| -| `setTag()` | `setAttribute()`, or set tags on the scope | |
60 |
| -| `setData()` | `setAttribute()` | |
61 |
| -| `setStatus()` | TODO: new signature | |
62 |
| -| `setHttpStatus()` | ??? TODO | |
63 |
| -| `setName()` | `updateName()` | |
64 |
| -| `startChild()` | Call `Sentry.startSpan()` independently | |
65 |
| -| `isSuccess()` | `spanToJSON(span).status === 'ok'` | |
66 |
| -| `toTraceparent()` | `spanToTraceHeader(span)` | |
67 |
| -| `toContext()` | Removed | |
68 |
| -| `updateWithContext()` | Removed | |
69 |
| -| `getTraceContext()` | `spanToTraceContext(span)` | |
70 |
| - |
71 |
| -In addition, a transaction has this API: |
72 |
| - |
73 |
| -| Old name | Replace with | |
74 |
| -| --------------------------- | ------------------------------------------------ | |
75 |
| -| `name` | `spanToJSON(span).description` | |
76 |
| -| `trimEnd` | Removed | |
77 |
| -| `parentSampled` | `spanIsSampled(span)` & `spanContext().isRemote` | |
78 |
| -| `metadata` | Use attributes instead or set on scope | |
79 |
| -| `setContext()` | Set context on scope instead | |
80 |
| -| `setMeasurement()` | ??? TODO | |
81 |
| -| `setMetadata()` | Use attributes instead or set on scope | |
82 |
| -| `getDynamicSamplingContext` | ??? TODO | |
83 |
| - |
84 |
| -### Attributes vs. Data vs. Tags vs. Context |
85 |
| - |
86 |
| -In the old model, you had the concepts of **Data**, **Tags** and **Context** which could be used for different things. |
87 |
| -However, this has two main downsides: One, it is not always clear which of these should be used when. And two, not all |
88 |
| -of these are displayed the same way for transactions or spans. |
89 |
| - |
90 |
| -Because of this, in the new model, there are only **Attributes** to be set on spans anymore. Broadly speaking, they map |
91 |
| -to what Data used to be. |
92 |
| - |
93 |
| -If you still really _need_ to set tags or context, you can do so on the scope before starting a span: |
94 |
| - |
95 |
| -```js |
96 |
| -Sentry.withScope(scope => { |
97 |
| - scope.setTag('my-tag', 'tag-value'); |
98 |
| - Sentry.startSpan({ name: 'my-span' }, span => { |
99 |
| - // do something here |
100 |
| - // span will have the tags from the containing scope |
101 |
| - }); |
102 |
| -}); |
103 |
| -``` |
104 |
| - |
105 | 37 | ## Creating Spans
|
106 | 38 |
|
107 | 39 | Instead of manually starting & ending transactions and spans, the new model does not differentiate between these two.
|
@@ -220,6 +152,95 @@ Sentry.startSpan({ name: 'outer' }, () => {
|
220 | 152 |
|
221 | 153 | No span will ever be created as a child span of an inactive span.
|
222 | 154 |
|
| 155 | +### Creating a child span of a specific span |
| 156 | + |
| 157 | +You can use the `withActiveSpan` helper to create a span as a child of a specific span: |
| 158 | + |
| 159 | +```js |
| 160 | +Sentry.withActiveSpan(parentSpan, () => { |
| 161 | + Sentry.startSpan({ name: 'my-span' }, span => { |
| 162 | + // span will be a direct child of parentSpan |
| 163 | + }); |
| 164 | +}); |
| 165 | +``` |
| 166 | + |
| 167 | +### Creating a transaction |
| 168 | + |
| 169 | +While in most cases, you shouldn't have to think about creating a span vs. a transaction (just call `startSpan()` and |
| 170 | +we'll do the appropriate thing under the hood), there may still be times where you _need_ to ensure you create a |
| 171 | +transaction (for example, if you need to see it as a transaction in the Sentry UI). For these cases, you can pass |
| 172 | +`forceTransaction: true` to the start-span APIs, e.g.: |
| 173 | + |
| 174 | +```js |
| 175 | +const transaction = Sentry.startInactiveSpan({ name: 'transaction', forceTransaction: true }); |
| 176 | +``` |
| 177 | + |
| 178 | +## The Span schema |
| 179 | + |
| 180 | +Previously, spans & transactions had a bunch of properties and methods to be used. Most of these have been removed in |
| 181 | +favor of a slimmer, more straightforward API, which is also aligned with OpenTelemetry Spans. You can refer to the table |
| 182 | +below to see which things used to exist, and how they can/should be mapped going forward: |
| 183 | + |
| 184 | +| Old name | Replace with | |
| 185 | +| --------------------- | ----------------------------------------------------------- | |
| 186 | +| `traceId` | `spanContext().traceId` | |
| 187 | +| `spanId` | `spanContext().spanId` | |
| 188 | +| `parentSpanId` | `spanToJSON(span).parent_span_id` | |
| 189 | +| `status` | `spanToJSON(span).status` | |
| 190 | +| `sampled` | `spanIsSampled(span)` | |
| 191 | +| `startTimestamp` | `startTime` - note that this has a different format! | |
| 192 | +| `tags` | use attributes, or set tags on the scope | |
| 193 | +| `data` | `spanToJSON(span).data` | |
| 194 | +| `transaction` | `getRootSpan(span)` | |
| 195 | +| `instrumenter` | Removed | |
| 196 | +| `finish()` | `end()` | |
| 197 | +| `end()` | Same | |
| 198 | +| `setTag()` | `setAttribute()`, or set tags on the scope | |
| 199 | +| `setData()` | `setAttribute()` | |
| 200 | +| `setStatus()` | The signature of this will change in a coming alpha release | |
| 201 | +| `setHttpStatus()` | `setHttpStatus(span, status)` | |
| 202 | +| `setName()` | `updateName()` | |
| 203 | +| `startChild()` | Call `Sentry.startSpan()` independently | |
| 204 | +| `isSuccess()` | `spanToJSON(span).status === 'ok'` | |
| 205 | +| `toTraceparent()` | `spanToTraceHeader(span)` | |
| 206 | +| `toContext()` | Removed | |
| 207 | +| `updateWithContext()` | Removed | |
| 208 | +| `getTraceContext()` | `spanToTraceContext(span)` | |
| 209 | + |
| 210 | +In addition, a transaction has this API: |
| 211 | + |
| 212 | +| Old name | Replace with | |
| 213 | +| --------------------------- | ------------------------------------------------ | |
| 214 | +| `name` | `spanToJSON(span).description` | |
| 215 | +| `trimEnd` | Removed | |
| 216 | +| `parentSampled` | `spanIsSampled(span)` & `spanContext().isRemote` | |
| 217 | +| `metadata` | Use attributes instead or set on scope | |
| 218 | +| `setContext()` | Set context on scope instead | |
| 219 | +| `setMeasurement()` | `Sentry.setMeasurement()` | |
| 220 | +| `setMetadata()` | Use attributes instead or set on scope | |
| 221 | +| `getDynamicSamplingContext` | `getDynamicSamplingContextFromSpan(span)` | |
| 222 | + |
| 223 | +### Attributes vs. Data vs. Tags vs. Context |
| 224 | + |
| 225 | +In the old model, you had the concepts of **Data**, **Tags** and **Context** which could be used for different things. |
| 226 | +However, this has two main downsides: One, it is not always clear which of these should be used when. And two, not all |
| 227 | +of these are displayed the same way for transactions or spans. |
| 228 | + |
| 229 | +Because of this, in the new model, there are only **Attributes** to be set on spans anymore. Broadly speaking, they map |
| 230 | +to what Data used to be. |
| 231 | + |
| 232 | +If you still really _need_ to set tags or context, you can do so on the scope before starting a span: |
| 233 | + |
| 234 | +```js |
| 235 | +Sentry.withScope(scope => { |
| 236 | + scope.setTag('my-tag', 'tag-value'); |
| 237 | + Sentry.startSpan({ name: 'my-span' }, span => { |
| 238 | + // do something here |
| 239 | + // span will have the tags from the containing scope |
| 240 | + }); |
| 241 | +}); |
| 242 | +``` |
| 243 | + |
223 | 244 | ## Other Notable Changes
|
224 | 245 |
|
225 | 246 | In addition to generally changing the performance APIs, there are also some smaller changes that this brings with it.
|
|
0 commit comments