Skip to content

Commit 7745ac2

Browse files
committed
ref(span): avoid reexporting the enum
1 parent e3b92d0 commit 7745ac2

File tree

5 files changed

+85
-88
lines changed

5 files changed

+85
-88
lines changed

Diff for: packages/tracing/src/browser/backgroundtab.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { getGlobalObject, logger } from '@sentry/utils';
22

33
import { FINISH_REASON_TAG, IDLE_TRANSACTION_FINISH_REASONS } from '../constants';
44
import { IdleTransaction } from '../idletransaction';
5-
import { SpanStatusType } from '../spanstatus';
5+
import { SpanStatusType } from '../span';
66
import { getActiveTransaction } from '../utils';
77

88
const global = getGlobalObject<Window>();

Diff for: packages/tracing/src/errors.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { addInstrumentationHandler, logger } from '@sentry/utils';
22

3-
import { SpanStatusType } from './spanstatus';
3+
import { SpanStatusType } from './span';
44
import { getActiveTransaction } from './utils';
55

66
/**

Diff for: packages/tracing/src/index.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@ export { Integrations };
2121
// For an example of of the new usage of BrowserTracing, see @sentry/nextjs index.client.ts
2222
export { BrowserTracing } from './browser';
2323

24-
export { Span } from './span';
24+
export { Span, SpanStatusType, spanStatusfromHttpCode } from './span';
2525
export { Transaction } from './transaction';
2626
export {
2727
// TODO deprecate old name in v7
2828
instrumentOutgoingRequests as registerRequestInstrumentation,
2929
RequestInstrumentationOptions,
3030
defaultRequestInstrumentationOptions,
3131
} from './browser';
32-
export { SpanStatus, spanStatusfromHttpCode } from './spanstatus';
3332
export { IdleTransaction } from './idletransaction';
3433
export { startIdleTransaction } from './hubextensions';
3534

Diff for: packages/tracing/src/span.ts

+82-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
import { Primitive, Span as SpanInterface, SpanContext, Transaction } from '@sentry/types';
33
import { dropUndefinedKeys, timestampWithMs, uuid4 } from '@sentry/utils';
44

5-
import { spanStatusfromHttpCode, SpanStatusType } from './spanstatus';
6-
75
/**
86
* Keeps track of finished spans for a given transaction
97
* @internal
@@ -340,3 +338,85 @@ export class Span implements SpanInterface {
340338
});
341339
}
342340
}
341+
342+
export type SpanStatusType =
343+
/** The operation completed successfully. */
344+
| 'ok'
345+
/** Deadline expired before operation could complete. */
346+
| 'deadline_exceeded'
347+
/** 401 Unauthorized (actually does mean unauthenticated according to RFC 7235) */
348+
| 'unauthenticated'
349+
/** 403 Forbidden */
350+
| 'permission_denied'
351+
/** 404 Not Found. Some requested entity (file or directory) was not found. */
352+
| 'not_found'
353+
/** 429 Too Many Requests */
354+
| 'resource_exhausted'
355+
/** Client specified an invalid argument. 4xx. */
356+
| 'invalid_argument'
357+
/** 501 Not Implemented */
358+
| 'unimplemented'
359+
/** 503 Service Unavailable */
360+
| 'unavailable'
361+
/** Other/generic 5xx. */
362+
| 'internal_error'
363+
/** Unknown. Any non-standard HTTP status code. */
364+
| 'unknown_error'
365+
/** The operation was cancelled (typically by the user). */
366+
| 'cancelled'
367+
/** Already exists (409) */
368+
| 'already_exists'
369+
/** Operation was rejected because the system is not in a state required for the operation's */
370+
| 'failed_precondition'
371+
/** The operation was aborted, typically due to a concurrency issue. */
372+
| 'aborted'
373+
/** Operation was attempted past the valid range. */
374+
| 'out_of_range'
375+
/** Unrecoverable data loss or corruption */
376+
| 'data_loss';
377+
378+
/**
379+
* Converts a HTTP status code into a {@link SpanStatusType}.
380+
*
381+
* @param httpStatus The HTTP response status code.
382+
* @returns The span status or unknown_error.
383+
*/
384+
export function spanStatusfromHttpCode(httpStatus: number): SpanStatusType {
385+
if (httpStatus < 400 && httpStatus >= 100) {
386+
return 'ok';
387+
}
388+
389+
if (httpStatus >= 400 && httpStatus < 500) {
390+
switch (httpStatus) {
391+
case 401:
392+
return 'unauthenticated';
393+
case 403:
394+
return 'permission_denied';
395+
case 404:
396+
return 'not_found';
397+
case 409:
398+
return 'already_exists';
399+
case 413:
400+
return 'failed_precondition';
401+
case 429:
402+
return 'resource_exhausted';
403+
default:
404+
return 'invalid_argument';
405+
}
406+
}
407+
408+
if (httpStatus >= 500 && httpStatus < 600) {
409+
switch (httpStatus) {
410+
case 501:
411+
return 'unimplemented';
412+
case 503:
413+
return 'unavailable';
414+
case 504:
415+
return 'deadline_exceeded';
416+
default:
417+
return 'internal_error';
418+
}
419+
}
420+
421+
return 'unknown_error';
422+
}

Diff for: packages/tracing/src/spanstatus.ts

-82
Original file line numberDiff line numberDiff line change
@@ -36,85 +36,3 @@ export enum SpanStatus {
3636
/** Unrecoverable data loss or corruption */
3737
DataLoss = 'data_loss',
3838
}
39-
40-
export type SpanStatusType =
41-
/** The operation completed successfully. */
42-
| 'ok'
43-
/** Deadline expired before operation could complete. */
44-
| 'deadline_exceeded'
45-
/** 401 Unauthorized (actually does mean unauthenticated according to RFC 7235) */
46-
| 'unauthenticated'
47-
/** 403 Forbidden */
48-
| 'permission_denied'
49-
/** 404 Not Found. Some requested entity (file or directory) was not found. */
50-
| 'not_found'
51-
/** 429 Too Many Requests */
52-
| 'resource_exhausted'
53-
/** Client specified an invalid argument. 4xx. */
54-
| 'invalid_argument'
55-
/** 501 Not Implemented */
56-
| 'unimplemented'
57-
/** 503 Service Unavailable */
58-
| 'unavailable'
59-
/** Other/generic 5xx. */
60-
| 'internal_error'
61-
/** Unknown. Any non-standard HTTP status code. */
62-
| 'unknown_error'
63-
/** The operation was cancelled (typically by the user). */
64-
| 'cancelled'
65-
/** Already exists (409) */
66-
| 'already_exists'
67-
/** Operation was rejected because the system is not in a state required for the operation's */
68-
| 'failed_precondition'
69-
/** The operation was aborted, typically due to a concurrency issue. */
70-
| 'aborted'
71-
/** Operation was attempted past the valid range. */
72-
| 'out_of_range'
73-
/** Unrecoverable data loss or corruption */
74-
| 'data_loss';
75-
76-
/**
77-
* Converts a HTTP status code into a {@link SpanStatusType}.
78-
*
79-
* @param httpStatus The HTTP response status code.
80-
* @returns The span status or unknown_error.
81-
*/
82-
export function spanStatusfromHttpCode(httpStatus: number): SpanStatusType {
83-
if (httpStatus < 400 && httpStatus >= 100) {
84-
return 'ok';
85-
}
86-
87-
if (httpStatus >= 400 && httpStatus < 500) {
88-
switch (httpStatus) {
89-
case 401:
90-
return 'unauthenticated';
91-
case 403:
92-
return 'permission_denied';
93-
case 404:
94-
return 'not_found';
95-
case 409:
96-
return 'already_exists';
97-
case 413:
98-
return 'failed_precondition';
99-
case 429:
100-
return 'resource_exhausted';
101-
default:
102-
return 'invalid_argument';
103-
}
104-
}
105-
106-
if (httpStatus >= 500 && httpStatus < 600) {
107-
switch (httpStatus) {
108-
case 501:
109-
return 'unimplemented';
110-
case 503:
111-
return 'unavailable';
112-
case 504:
113-
return 'deadline_exceeded';
114-
default:
115-
return 'internal_error';
116-
}
117-
}
118-
119-
return 'unknown_error';
120-
}

0 commit comments

Comments
 (0)