forked from open-telemetry/opentelemetry-js
/
types.ts
364 lines (324 loc) · 12 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { SpanAttributes, SpanKind, SpanStatusCode } from '@opentelemetry/api';
/* eslint-disable @typescript-eslint/no-namespace */
/* eslint-disable @typescript-eslint/no-unused-vars */
export namespace opentelemetryProto {
export namespace collector {
export namespace trace.v1 {
export interface TraceService {
service: opentelemetryProto.collector.trace.v1.TraceService;
}
export interface ExportTraceServiceRequest {
resourceSpans: opentelemetryProto.trace.v1.ResourceSpans[];
}
}
export namespace metrics.v1 {
export interface ExportMetricsServiceRequest {
resourceMetrics: opentelemetryProto.metrics.v1.ResourceMetrics[];
}
}
}
export namespace resource.v1 {
export interface Resource {
attributes: opentelemetryProto.common.v1.KeyValue[];
droppedAttributesCount: number;
}
}
export namespace metrics.v1 {
export interface Metric {
name: string;
description: string;
unit: string;
// data:
intGauge?: opentelemetryProto.metrics.v1.Gauge;
doubleGauge?: opentelemetryProto.metrics.v1.Gauge;
intSum?: opentelemetryProto.metrics.v1.Sum;
doubleSum?: opentelemetryProto.metrics.v1.Sum;
intHistogram?: opentelemetryProto.metrics.v1.Histogram;
doubleHistogram?: opentelemetryProto.metrics.v1.Histogram;
}
export interface Gauge {
dataPoints: opentelemetryProto.metrics.v1.DataPoint[];
}
export interface Sum {
dataPoints: opentelemetryProto.metrics.v1.DataPoint[];
aggregationTemporality: opentelemetryProto.metrics.v1.AggregationTemporality;
isMonotonic: boolean;
}
export interface Histogram {
dataPoints: opentelemetryProto.metrics.v1.HistogramDataPoint[];
aggregationTemporality: opentelemetryProto.metrics.v1.AggregationTemporality;
}
export interface DataPoint {
labels: opentelemetryProto.common.v1.StringKeyValue[];
startTimeUnixNano: number;
timeUnixNano: number;
value: number;
exemplars?: opentelemetryProto.metrics.v1.Exemplar[];
}
export interface Exemplar {
filteredLabels: opentelemetryProto.common.v1.StringKeyValue[];
timeUnixNano: number;
value: number;
spanId: Uint8Array;
traceId: Uint8Array;
}
export interface HistogramDataPoint {
labels: opentelemetryProto.common.v1.StringKeyValue[];
startTimeUnixNano: number;
timeUnixNano: number;
count: number;
sum: number;
bucketCounts?: number[];
explicitBounds?: number[];
exemplars?: opentelemetryProto.metrics.v1.Exemplar[][];
}
export interface InstrumentationLibraryMetrics {
instrumentationLibrary?: opentelemetryProto.common.v1.InstrumentationLibrary;
metrics: opentelemetryProto.metrics.v1.Metric[];
}
export interface ResourceMetrics {
resource?: opentelemetryProto.resource.v1.Resource;
instrumentationLibraryMetrics: opentelemetryProto.metrics.v1.InstrumentationLibraryMetrics[];
}
export enum AggregationTemporality {
// UNSPECIFIED is the default AggregationTemporality, it MUST not be used.
AGGREGATION_TEMPORALITY_UNSPECIFIED = 0,
// DELTA is an AggregationTemporality for a metric aggregator which reports
// changes since last report time. Successive metrics contain aggregation of
// values from continuous and non-overlapping intervals.
//
// The values for a DELTA metric are based only on the time interval
// associated with one measurement cycle. There is no dependency on
// previous measurements like is the case for CUMULATIVE metrics.
//
// For example, consider a system measuring the number of requests that
// it receives and reports the sum of these requests every second as a
// DELTA metric:
//
// 1. The system starts receiving at time=t_0.
// 2. A request is received, the system measures 1 request.
// 3. A request is received, the system measures 1 request.
// 4. A request is received, the system measures 1 request.
// 5. The 1 second collection cycle ends. A metric is exported for the
// number of requests received over the interval of time t_0 to
// t_0+1 with a value of 3.
// 6. A request is received, the system measures 1 request.
// 7. A request is received, the system measures 1 request.
// 8. The 1 second collection cycle ends. A metric is exported for the
// number of requests received over the interval of time t_0+1 to
// t_0+2 with a value of 2.
AGGREGATION_TEMPORALITY_DELTA = 1,
// CUMULATIVE is an AggregationTemporality for a metric aggregator which
// reports changes since a fixed start time. This means that current values
// of a CUMULATIVE metric depend on all previous measurements since the
// start time. Because of this, the sender is required to retain this state
// in some form. If this state is lost or invalidated, the CUMULATIVE metric
// values MUST be reset and a new fixed start time following the last
// reported measurement time sent MUST be used.
//
// For example, consider a system measuring the number of requests that
// it receives and reports the sum of these requests every second as a
// CUMULATIVE metric:
//
// 1. The system starts receiving at time=t_0.
// 2. A request is received, the system measures 1 request.
// 3. A request is received, the system measures 1 request.
// 4. A request is received, the system measures 1 request.
// 5. The 1 second collection cycle ends. A metric is exported for the
// number of requests received over the interval of time t_0 to
// t_0+1 with a value of 3.
// 6. A request is received, the system measures 1 request.
// 7. A request is received, the system measures 1 request.
// 8. The 1 second collection cycle ends. A metric is exported for the
// number of requests received over the interval of time t_0 to
// t_0+2 with a value of 5.
// 9. The system experiences a fault and loses state.
// 10. The system recovers and resumes receiving at time=t_1.
// 11. A request is received, the system measures 1 request.
// 12. The 1 second collection cycle ends. A metric is exported for the
// number of requests received over the interval of time t_1 to
// t_0+1 with a value of 1.
//
// Note: Even though, when reporting changes since last report time, using
// CUMULATIVE is valid, it is not recommended. This may cause problems for
// systems that do not use start_time to determine when the aggregation
// value was reset (e.g. Prometheus).
AGGREGATION_TEMPORALITY_CUMULATIVE = 2,
}
}
export namespace trace.v1 {
export namespace ConstantSampler {
export enum ConstantDecision {
ALWAYS_OFF = 0,
ALWAYS_ON = 1,
ALWAYS_PARENT = 2,
}
}
export namespace Span {
export interface Event {
timeUnixNano: number;
name: string;
attributes?: opentelemetryProto.common.v1.KeyValue[];
droppedAttributesCount: number;
}
export interface Link {
traceId: string;
spanId: string;
traceState?: opentelemetryProto.trace.v1.Span.TraceState;
attributes?: opentelemetryProto.common.v1.KeyValue[];
droppedAttributesCount: number;
}
// eslint-disable-next-line @typescript-eslint/no-shadow
export enum SpanKind {
SPAN_KIND_UNSPECIFIED,
SPAN_KIND_INTERNAL,
SPAN_KIND_SERVER,
SPAN_KIND_CLIENT,
SPAN_KIND_PRODUCER,
SPAN_KIND_CONSUMER,
}
export type TraceState = string | undefined;
}
export interface ConstantSampler {
decision?: opentelemetryProto.trace.v1.ConstantSampler.ConstantDecision;
}
export interface InstrumentationLibrarySpans {
instrumentationLibrary?: opentelemetryProto.common.v1.InstrumentationLibrary;
spans: opentelemetryProto.trace.v1.Span[];
}
export interface ProbabilitySampler {
samplingProbability?: number | null;
}
export interface RateLimitingSampler {
qps?: number | null;
}
export interface ResourceSpans {
resource?: opentelemetryProto.resource.v1.Resource;
instrumentationLibrarySpans: opentelemetryProto.trace.v1.InstrumentationLibrarySpans[];
}
export interface Span {
traceId: string;
spanId: string;
traceState: opentelemetryProto.trace.v1.Span.TraceState;
parentSpanId?: string;
name?: string;
kind?: opentelemetryProto.trace.v1.Span.SpanKind;
startTimeUnixNano?: number;
endTimeUnixNano?: number;
attributes?: opentelemetryProto.common.v1.KeyValue[];
droppedAttributesCount: number;
events?: opentelemetryProto.trace.v1.Span.Event[];
droppedEventsCount: number;
links?: opentelemetryProto.trace.v1.Span.Link[];
droppedLinksCount: number;
status?: SpanStatus;
}
export interface SpanStatus {
/** The status code of this message. */
code: SpanStatusCode;
/** A developer-facing error message. */
message?: string;
}
export interface TraceConfig {
constantSampler?: ConstantSampler | null;
probabilitySampler?: ProbabilitySampler | null;
rateLimitingSampler?: RateLimitingSampler | null;
}
}
export namespace common.v1 {
export interface KeyValue {
key: string;
value: AnyValue;
}
export type ArrayValue = {
values: AnyValue[];
};
export interface KeyValueList {
values: KeyValue[];
}
export type AnyValue = {
stringValue?: string;
boolValue?: boolean;
intValue?: number;
doubleValue?: number;
arrayValue?: ArrayValue;
kvlistValue?: KeyValueList;
};
export interface InstrumentationLibrary {
name: string;
version?: string;
}
export interface StringKeyValue {
key: string;
value: string;
}
export enum ValueType {
STRING,
INT,
DOUBLE,
BOOL,
}
}
}
/**
* Interface for handling error
*/
export class OTLPExporterError extends Error {
readonly code?: number;
override readonly name: string = 'OTLPExporterError';
readonly data?: string;
constructor(message?: string, code?: number, data?: string) {
super(message);
this.data = data;
this.code = code;
}
}
/**
* Interface for handling export service errors
*/
export interface ExportServiceError {
name: string;
code: number;
details: string;
metadata: { [key: string]: unknown };
message: string;
stack: string;
}
/**
* Collector Exporter base config
*/
export interface OTLPExporterConfigBase {
headers?: Partial<Record<string, unknown>>;
hostname?: string;
attributes?: SpanAttributes;
url?: string;
concurrencyLimit?: number;
}
/**
* Mapping between api SpanKind and proto SpanKind
*/
export const OTLP_SPAN_KIND_MAPPING = {
[SpanKind.INTERNAL]:
opentelemetryProto.trace.v1.Span.SpanKind.SPAN_KIND_INTERNAL,
[SpanKind.SERVER]: opentelemetryProto.trace.v1.Span.SpanKind.SPAN_KIND_SERVER,
[SpanKind.CLIENT]: opentelemetryProto.trace.v1.Span.SpanKind.SPAN_KIND_CLIENT,
[SpanKind.PRODUCER]:
opentelemetryProto.trace.v1.Span.SpanKind.SPAN_KIND_PRODUCER,
[SpanKind.CONSUMER]:
opentelemetryProto.trace.v1.Span.SpanKind.SPAN_KIND_CONSUMER,
};