UNPKG

5.21 kBTypeScriptView Raw
1import type { Instrumenter, Primitive, Span as SpanInterface, SpanContext, SpanOrigin, TraceContext, Transaction } from '@sentry/types';
2/**
3 * Keeps track of finished spans for a given transaction
4 * @internal
5 * @hideconstructor
6 * @hidden
7 */
8export declare class SpanRecorder {
9 spans: Span[];
10 private readonly _maxlen;
11 constructor(maxlen?: number);
12 /**
13 * This is just so that we don't run out of memory while recording a lot
14 * of spans. At some point we just stop and flush out the start of the
15 * trace tree (i.e.the first n spans with the smallest
16 * start_timestamp).
17 */
18 add(span: Span): void;
19}
20/**
21 * Span contains all data about a span
22 */
23export declare class Span implements SpanInterface {
24 /**
25 * @inheritDoc
26 */
27 traceId: string;
28 /**
29 * @inheritDoc
30 */
31 spanId: string;
32 /**
33 * @inheritDoc
34 */
35 parentSpanId?: string;
36 /**
37 * Internal keeper of the status
38 */
39 status?: SpanStatusType | string;
40 /**
41 * @inheritDoc
42 */
43 sampled?: boolean;
44 /**
45 * Timestamp in seconds when the span was created.
46 */
47 startTimestamp: number;
48 /**
49 * Timestamp in seconds when the span ended.
50 */
51 endTimestamp?: number;
52 /**
53 * @inheritDoc
54 */
55 op?: string;
56 /**
57 * @inheritDoc
58 */
59 description?: string;
60 /**
61 * @inheritDoc
62 */
63 tags: {
64 [key: string]: Primitive;
65 };
66 /**
67 * @inheritDoc
68 */
69 data: {
70 [key: string]: any;
71 };
72 /**
73 * List of spans that were finalized
74 */
75 spanRecorder?: SpanRecorder;
76 /**
77 * @inheritDoc
78 */
79 transaction?: Transaction;
80 /**
81 * The instrumenter that created this span.
82 */
83 instrumenter: Instrumenter;
84 /**
85 * The origin of the span, giving context about what created the span.
86 */
87 origin?: SpanOrigin;
88 /**
89 * You should never call the constructor manually, always use `Sentry.startTransaction()`
90 * or call `startChild()` on an existing span.
91 * @internal
92 * @hideconstructor
93 * @hidden
94 */
95 constructor(spanContext?: SpanContext);
96 /** An alias for `description` of the Span. */
97 get name(): string;
98 /** Update the name of the span. */
99 set name(name: string);
100 /**
101 * @inheritDoc
102 */
103 startChild(spanContext?: Pick<SpanContext, Exclude<keyof SpanContext, 'sampled' | 'traceId' | 'parentSpanId'>>): Span;
104 /**
105 * @inheritDoc
106 */
107 setTag(key: string, value: Primitive): this;
108 /**
109 * @inheritDoc
110 */
111 setData(key: string, value: any): this;
112 /**
113 * @inheritDoc
114 */
115 setStatus(value: SpanStatusType): this;
116 /**
117 * @inheritDoc
118 */
119 setHttpStatus(httpStatus: number): this;
120 /**
121 * @inheritDoc
122 */
123 setName(name: string): void;
124 /**
125 * @inheritDoc
126 */
127 isSuccess(): boolean;
128 /**
129 * @inheritDoc
130 */
131 finish(endTimestamp?: number): void;
132 /**
133 * @inheritDoc
134 */
135 toTraceparent(): string;
136 /**
137 * @inheritDoc
138 */
139 toContext(): SpanContext;
140 /**
141 * @inheritDoc
142 */
143 updateWithContext(spanContext: SpanContext): this;
144 /**
145 * @inheritDoc
146 */
147 getTraceContext(): TraceContext;
148 /**
149 * @inheritDoc
150 */
151 toJSON(): {
152 data?: {
153 [key: string]: any;
154 };
155 description?: string;
156 op?: string;
157 parent_span_id?: string;
158 span_id: string;
159 start_timestamp: number;
160 status?: string;
161 tags?: {
162 [key: string]: Primitive;
163 };
164 timestamp?: number;
165 trace_id: string;
166 origin?: SpanOrigin;
167 };
168}
169export type SpanStatusType =
170/** The operation completed successfully. */
171'ok'
172/** Deadline expired before operation could complete. */
173 | 'deadline_exceeded'
174/** 401 Unauthorized (actually does mean unauthenticated according to RFC 7235) */
175 | 'unauthenticated'
176/** 403 Forbidden */
177 | 'permission_denied'
178/** 404 Not Found. Some requested entity (file or directory) was not found. */
179 | 'not_found'
180/** 429 Too Many Requests */
181 | 'resource_exhausted'
182/** Client specified an invalid argument. 4xx. */
183 | 'invalid_argument'
184/** 501 Not Implemented */
185 | 'unimplemented'
186/** 503 Service Unavailable */
187 | 'unavailable'
188/** Other/generic 5xx. */
189 | 'internal_error'
190/** Unknown. Any non-standard HTTP status code. */
191 | 'unknown_error'
192/** The operation was cancelled (typically by the user). */
193 | 'cancelled'
194/** Already exists (409) */
195 | 'already_exists'
196/** Operation was rejected because the system is not in a state required for the operation's */
197 | 'failed_precondition'
198/** The operation was aborted, typically due to a concurrency issue. */
199 | 'aborted'
200/** Operation was attempted past the valid range. */
201 | 'out_of_range'
202/** Unrecoverable data loss or corruption */
203 | 'data_loss';
204/**
205 * Converts a HTTP status code into a {@link SpanStatusType}.
206 *
207 * @param httpStatus The HTTP response status code.
208 * @returns The span status or unknown_error.
209 */
210export declare function spanStatusfromHttpCode(httpStatus: number): SpanStatusType;
211//# sourceMappingURL=span.d.ts.map
\No newline at end of file