8000 feat(core): Deprecate `Span.isSuccess()` in favor of reading span sta… · GingerAdonis/sentry-javascript@f9ed885 · GitHub
[go: up one dir, main page]

Skip to content

Commit f9ed885

Browse files
authored
feat(core): Deprecate Span.isSuccess() in favor of reading span status (getsentry#10213)
Deprecate `Span.isSuccess()` in favor of directly reading the span status via `spanToJSON(span).status === 'ok'` instead. There's no need for this API as it's just syntactic sugar around the status.
1 parent 14bf0a0 commit f9ed885

File tree

5 files changed

+14
-1
lines changed

5 files changed

+14
-1
lines changed

MIGRATION.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ In v8, the Span class is heavily reworked. The following properties & methods ar
206206
- `span.spanRecorder`: Span recording will be handled internally by the SDK.
207207
- `span.status`: Use `.setStatus` to set or update and `spanToJSON()` to read the span status.
208208
- `span.op`: Use `startSpan` functions to set, `setAttribute()` to update and `spanToJSON` to read the span operation.
209+
- `span.isSuccess`: Use `spanToJSON(span).status === 'ok'` instead.
209210
- `transaction.setMetadata()`: Use attributes instead, or set data on the scope.
210211
- `transaction.metadata`: Use attributes instead, or set data on the scope.
211212
- `transaction.setContext()`: Set context on the surrounding scope instead.

docs/v8-new-performance-apis.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ below to see which things used to exist, and how they can/should be mapped going
6262
| `setHttpStatus()` | ??? TODO |
6363
| `setName()` | `updateName()` |
6464
| `startChild()` | Call `Sentry.startSpan()` independently |
65-
| `isSuccess()` | Removed (TODO) |
65+
| `isSuccess()` | `spanToJSON(span).status === 'ok'` |
6666
| `toTraceparent()` | `spanToTraceHeader(span)` |
6767
| `toContext()` | Removed |
6868
| `updateWithContext()` | Removed |

packages/core/src/tracing/span.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,8 @@ export class Span implements SpanInterface {
472472

473473
/**
474474
* @inheritDoc
475+
*
476+
* @deprecated Use `spanToJSON(span).status === 'ok'` instead.
475477
*/
476478
public isSuccess(): boolean {
477479
return this._status === 'ok';

packages/tracing/test/span.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,21 +106,29 @@ describe('Span', () => {
106106
expect(span.data['http.response.status_code']).toBe(404);
107107
});
108108

109+
// TODO (v8): Remove
109110
test('isSuccess', () => {
110111
const span = new Span({});
111112
expect(span.isSuccess()).toBe(false);
113+
expect(spanToJSON(span).status).not.toBe('ok');
112114
span.setHttpStatus(200);
113115
expect(span.isSuccess()).toBe(true);
116+
expect(spanToJSON(span).status).toBe('ok');
114117
span.setStatus('permission_denied');
115118
expect(span.isSuccess()).toBe(false);
119+
expect(spanToJSON(span).status).not.toBe('ok');
116120
span.setHttpStatus(0);
117121
expect(span.isSuccess()).toBe(false);
122+
expect(spanToJSON(span).status).not.toBe('ok');
118123
span.setHttpStatus(-1);
119124
expect(span.isSuccess()).toBe(false);
125+
expect(spanToJSON(span).status).not.toBe('ok');
120126
span.setHttpStatus(99);
121127
expect(span.isSuccess()).toBe(false);
128+
expect(spanToJSON(span).status).not.toBe('ok');
122129
span.setHttpStatus(100);
123130
expect(span.isSuccess()).toBe(true);
131+
expect(spanToJSON(span).status).toBe('ok');
124132
});
125133
});
126134

packages/types/src/span.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,8 @@ export interface Span extends SpanContext {
329329

330330
/**
331331
* Determines whether span was successful (HTTP200)
332+
*
333+
* @deprecated Use `spanToJSON(span).status === 'ok'` instead.
332334
*/
333335
isSuccess(): boolean;
334336

0 commit comments

Comments
 (0)
0