Skip to content

Commit ff40973

Browse files
committed
Merge branch 'master' of github.com:getsentry/sentry-javascript
2 parents 2722542 + 36d5cc6 commit ff40973

File tree

10 files changed

+111
-105
lines changed

10 files changed

+111
-105
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- "You miss 100 percent of the chances you don't take. — Wayne Gretzky" — Michael Scott
66

77
- [apm] fix: Use proper type name for op #2584
8+
- [apm] fix: Improve bundle size by moving span status to @sentry/apm #2589
89

910
## 5.16.0
1011

packages/apm/src/hubextensions.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ function traceHeaders(): { [key: string]: string } {
2020
}
2121

2222
/**
23-
* This functions starts a span. If argument passed is of type `Span`, it'll run sampling on it if configured
24-
* and attach a `SpanRecorder`. If it's of type `SpanContext` and there is already a `Span` on the Scope,
25-
* the created Span will have a reference to it and become it's child. Otherwise it'll crete a new `Span`.
23+
* This functions starts a span. If there is already a `Span` on the Scope,
24+
* the created Span with the SpanContext will have a reference to it and become it's child.
25+
* Otherwise it'll crete a new `Span`.
2626
*
27-
* @param spanContext Already constructed span or properties with which the span should be created
27+
* @param spanContext Properties with which the span should be created
2828
*/
2929
function startSpan(spanContext?: SpanContext): Span {
3030
// @ts-ignore

packages/apm/src/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@ import * as ApmIntegrations from './integrations';
44
export { ApmIntegrations as Integrations };
55
export { Span, TRACEPARENT_REGEXP } from './span';
66

7+
export { SpanStatus } from './spanstatus';
8+
79
// We are patching the global object with our hub extension methods
810
addExtensionMethods();

packages/apm/src/integrations/tracing.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Hub, Scope } from '@sentry/hub';
2-
import { Event, EventProcessor, Integration, Span, SpanContext, SpanStatus } from '@sentry/types';
2+
import { Event, EventProcessor, Integration, Span, SpanContext } from '@sentry/types';
33
import {
44
addInstrumentationHandler,
55
getGlobalObject,
@@ -9,6 +9,7 @@ import {
99
} from '@sentry/utils';
1010

1111
import { Span as SpanClass } from '../span';
12+
import { SpanStatus } from '../spanstatus';
1213

1314
/**
1415
* Options for Tracing integration

packages/apm/src/span.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
// tslint:disable:max-classes-per-file
22

33
import { getCurrentHub, Hub } from '@sentry/hub';
4-
import { Span as SpanInterface, SpanContext, SpanStatus } from '@sentry/types';
4+
import { Span as SpanInterface, SpanContext } from '@sentry/types';
55
import { dropUndefinedKeys, isInstanceOf, logger, timestampWithMs, uuid4 } from '@sentry/utils';
66

7+
import { SpanStatus } from './spanstatus';
8+
79
// TODO: Should this be exported?
810
export const TRACEPARENT_REGEXP = new RegExp(
911
'^[ \\t]*' + // whitespace
@@ -66,7 +68,7 @@ export class Span implements SpanInterface, SpanContext {
6668
/**
6769
* Internal keeper of the status
6870
*/
69-
private _status?: SpanStatus;
71+
private _status?: SpanStatus | string;
7072

7173
/**
7274
* @inheritDoc

packages/apm/src/spanstatus.ts

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/** The status of an Span. */
2+
export enum SpanStatus {
3+
/** The operation completed successfully. */
4+
Ok = 'ok',
5+
/** Deadline expired before operation could complete. */
6+
DeadlineExceeded = 'deadline_exceeded',
7+
/** 401 Unauthorized (actually does mean unauthenticated according to RFC 7235) */
8+
Unauthenticated = 'unauthenticated',
9+
/** 403 Forbidden */
10+
PermissionDenied = 'permission_denied',
11+
/** 404 Not Found. Some requested entity (file or directory) was not found. */
12+
NotFound = 'not_found',
13+
/** 429 Too Many Requests */
14+
ResourceExhausted = 'resource_exhausted',
15+
/** Client specified an invalid argument. 4xx. */
16+
InvalidArgument = 'invalid_argument',
17+
/** 501 Not Implemented */
18+
Unimplemented = 'unimplemented',
19+
/** 503 Service Unavailable */
20+
Unavailable = 'unavailable',
21+
/** Other/generic 5xx. */
22+
InternalError = 'internal_error',
23+
/** Unknown. Any non-standard HTTP status code. */
24+
UnknownError = 'unknown_error',
25+
/** The operation was cancelled (typically by the user). */
26+
Cancelled = 'cancelled',
27+
/** Already exists (409) */
28+
AlreadyExists = 'already_exists',
29+
/** Operation was rejected because the system is not in a state required for the operation's */
30+
FailedPrecondition = 'failed_precondition',
31+
/** The operation was aborted, typically due to a concurrency issue. */
32+
Aborted = 'aborted',
33+
/** Operation was attempted past the valid range. */
34+
OutOfRange = 'out_of_range',
35+
/** Unrecoverable data loss or corruption */
36+
DataLoss = 'data_loss',
37+
}
38+
39+
// tslint:disable:no-unnecessary-qualifier no-namespace
40+
export namespace SpanStatus {
41+
/**
42+
* Converts a HTTP status code into a {@link SpanStatus}.
43+
*
44+
* @param httpStatus The HTTP response status code.
45+
* @returns The span status or {@link SpanStatus.UnknownError}.
46+
*/
47+
// tslint:disable-next-line:completed-docs
48+
export function fromHttpCode(httpStatus: number): SpanStatus {
49+
if (httpStatus < 400) {
50+
return SpanStatus.Ok;
51+
}
52+
53+
if (httpStatus >= 400 && httpStatus < 500) {
54+
switch (httpStatus) {
55+
case 401:
56+
return SpanStatus.Unauthenticated;
57+
case 403:
58+
return SpanStatus.PermissionDenied;
59+
case 404:
60+
return SpanStatus.NotFound;
61+
case 409:
62+
return SpanStatus.AlreadyExists;
63+
case 413:
64+
return SpanStatus.FailedPrecondition;
65+
case 429:
66+
return SpanStatus.ResourceExhausted;
67+
default:
68+
return SpanStatus.InvalidArgument;
69+
}
70+
}
71+
72+
if (httpStatus >= 500 && httpStatus < 600) {
73+
switch (httpStatus) {
74+
case 501:
75+
return SpanStatus.Unimplemented;
76+
case 503:
77+
return SpanStatus.Unavailable;
78+
case 504:
79+
return SpanStatus.DeadlineExceeded;
80+
default:
81+
return SpanStatus.InternalError;
82+
}
83+
}
84+
85+
return SpanStatus.UnknownError;
86+
}
87+
}

packages/apm/test/span.test.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { BrowserClient } from '@sentry/browser';
22
import { Hub, Scope } from '@sentry/hub';
3-
import { SpanStatus } from '@sentry/types';
43

5-
import { Span, TRACEPARENT_REGEXP } from '../src';
4+
import { Span, SpanStatus, TRACEPARENT_REGEXP } from '../src';
65

76
describe('Span', () => {
87
let hub: Hub;

packages/types/src/hub.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,11 @@ export interface Hub {
173173
traceHeaders(): { [key: string]: string };
174174

175175
/**
176-
* This functions starts a span. If argument passed is of type `Span`, it'll run sampling on it if configured
177-
* and attach a `SpanRecorder`. If it's of type `SpanContext` and there is already a `Span` on the Scope,
178-
* the created Span will have a reference to it and become it's child. Otherwise it'll crete a new `Span`.
176+
* This functions starts a span. If there is already a `Span` on the Scope,
177+
* the created Span with the SpanContext will have a reference to it and become it's child.
178+
* Otherwise it'll crete a new `Span`.
179179
*
180-
* @param span Already constructed span which should be started or properties with which the span should be created
180+
* @param spanContext Properties with which the span should be created
181181
*/
182-
startSpan(span?: Span | SpanContext, forceNoChild?: boolean): Span;
182+
startSpan(spanContext?: SpanContext): Span;
183183
}

packages/types/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export { Runtime } from './runtime';
1717
export { Scope } from './scope';
1818
export { SdkInfo } from './sdkinfo';
1919
export { Severity } from './severity';
20-
export { Span, SpanContext, SpanStatus } from './span';
20+
export { Span, SpanContext } from './span';
2121
export { StackFrame } from './stackframe';
2222
export { Stacktrace } from './stacktrace';
2323
export { Status } from './status';

packages/types/src/span.ts

+4-90
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,10 @@ export interface Span {
4646

4747
/**
4848
* Sets the status attribute on the current span
49+
* See: {@sentry/apm SpanStatus} for possible values
4950
* @param status http code used to set the status
5051
*/
51-
setStatus(status: SpanStatus): this;
52+
setStatus(status: string): this;
5253

5354
/**
5455
* Sets the status attribute on the current span based on the http code
@@ -87,8 +88,9 @@ export interface SpanContext {
8788
op?: string;
8889
/**
8990
* Completion status of the Span.
91+
* See: {@sentry/apm SpanStatus} for possible values
9092
*/
91-
status?: SpanStatus;
93+
status?: string;
9294
/**
9395
* Parent Span ID
9496
*/
@@ -119,91 +121,3 @@ export interface SpanContext {
119121
*/
120122
data?: { [key: string]: any };
121123
}
122-
123-
/** The status of an Span. */
124-
export enum SpanStatus {
125-
/** The operation completed successfully. */
126-
Ok = 'ok',
127-
/** Deadline expired before operation could complete. */
128-
DeadlineExceeded = 'deadline_exceeded',
129-
/** 401 Unauthorized (actually does mean unauthenticated according to RFC 7235) */
130-
Unauthenticated = 'unauthenticated',
131-
/** 403 Forbidden */
132-
PermissionDenied = 'permission_denied',
133-
/** 404 Not Found. Some requested entity (file or directory) was not found. */
134-
NotFound = 'not_found',
135-
/** 429 Too Many Requests */
136-
ResourceExhausted = 'resource_exhausted',
137-
/** Client specified an invalid argument. 4xx. */
138-
InvalidArgument = 'invalid_argument',
139-
/** 501 Not Implemented */
140-
Unimplemented = 'unimplemented',
141-
/** 503 Service Unavailable */
142-
Unavailable = 'unavailable',
143-
/** Other/generic 5xx. */
144-
InternalError = 'internal_error',
145-
/** Unknown. Any non-standard HTTP status code. */
146-
UnknownError = 'unknown_error',
147-
/** The operation was cancelled (typically by the user). */
148-
Cancelled = 'cancelled',
149-
/** Already exists (409) */
150-
AlreadyExists = 'already_exists',
151-
/** Operation was rejected because the system is not in a state required for the operation's */
152-
FailedPrecondition = 'failed_precondition',
153-
/** The operation was aborted, typically due to a concurrency issue. */
154-
Aborted = 'aborted',
155-
/** Operation was attempted past the valid range. */
156-
OutOfRange = 'out_of_range',
157-
/** Unrecoverable data loss or corruption */
158-
DataLoss = 'data_loss',
159-
}
160-
161-
// tslint:disable:no-unnecessary-qualifier no-namespace
162-
export namespace SpanStatus {
163-
/**
164-
* Converts a HTTP status code into a {@link SpanStatus}.
165-
*
166-
* @param httpStatus The HTTP response status code.
167-
* @returns The span status or {@link SpanStatus.UnknownError}.
168-
*/
169-
// tslint:disable-next-line:completed-docs
170-
export function fromHttpCode(httpStatus: number): SpanStatus {
171-
if (httpStatus < 400) {
172-
return SpanStatus.Ok;
173-
}
174-
175-
if (httpStatus >= 400 && httpStatus < 500) {
176-
switch (httpStatus) {
177-
case 401:
178-
return SpanStatus.Unauthenticated;
179-
case 403:
180-
return SpanStatus.PermissionDenied;
181-
case 404:
182-
return SpanStatus.NotFound;
183-
case 409:
184-
return SpanStatus.AlreadyExists;
185-
case 413:
186-
return SpanStatus.FailedPrecondition;
187-
case 429:
188-
return SpanStatus.ResourceExhausted;
189-
default:
190-
return SpanStatus.InvalidArgument;
191-
}
192-
}
193-
194-
if (httpStatus >= 500 && httpStatus < 600) {
195-
switch (httpStatus) {
196-
case 501:
197-
return SpanStatus.Unimplemented;
198-
case 503:
199-
return SpanStatus.Unavailable;
200-
case 504:
201-
return SpanStatus.DeadlineExceeded;
202-
default:
203-
return SpanStatus.InternalError;
204-
}
205-
}
206-
207-
return SpanStatus.UnknownError;
208-
}
209-
}

0 commit comments

Comments
 (0)