1
>
/*---------------------------------------------------------------------------------------------
otlpJsonTypes.ts
2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
/**
7
>
* Minimal OTLP/HTTP JSON wire types for the trace export request body.
8
>
*
9
>
* Reference:
10
>
* - opentelemetry-proto/opentelemetry/proto/trace/v1/trace.proto
11
>
* - opentelemetry-proto/opentelemetry/proto/common/v1/common.proto
12
>
* - opentelemetry-proto/opentelemetry/proto/resource/v1/resource.proto
13
>
* - opentelemetry-proto/docs/specification.md#json-protobuf-encoding
14
>
*
15
>
* JSON encoding rules used here:
16
>
* - field names are camelCase (NOT snake_case)
17
>
* - `traceId`/`spanId`/`parentSpanId` are lower-hex strings
18
>
* (32 hex chars / 16 hex chars; parentSpanId may be empty)
19
>
* - `startTimeUnixNano`/`endTimeUnixNano`/`timeUnixNano` are stringified
20
>
* unsigned 64-bit decimal integers (string fits int64 without precision loss)
21
>
* - `intValue` on AnyValue is a stringified int64; other numeric fields are JSON numbers
22
>
* - bytesValue is base64-encoded
23
>
* - all fields are technically optional in proto3; producers MAY omit defaults
24
>
*
25
>
* Only the subset of fields we currently consume is modeled here. Unknown
26
>
* fields are ignored by the decoder (forwards-compatible).
27
>
*/
28
>
29
>
30
>
/** Status code as defined by the OTLP trace status enum. */
31
>
export const enum OtlpStatusCode {
32
>
UNSET = 0,
33
>
OK = 1,
34
>
ERROR = 2,
35
>
}
36
>
37
>
/** Span kind as defined by the OTLP trace span_kind enum. */
38
>
export const enum OtlpSpanKind {
39
>
UNSPECIFIED = 0,
40
>
INTERNAL = 1,
41
>
SERVER = 2,
42
>
CLIENT = 3,
43
>
PRODUCER = 4,
44
>
CONSUMER = 5,
45
>
}
46
>
47
>
/**
48
>
* A single attribute value. Exactly one of the optional fields is set, except
49
>
* for empty values which may be entirely absent (proto3 defaults).
50
>
*/
51
>
export interface IOtlpAnyValue {
52
>
readonly stringValue?: string;
53
>
readonly boolValue?: boolean;
54
>
/** Stringified int64. */
55
>
readonly intValue?: string | number;
56
>
readonly doubleValue?: number;
57
>
readonly arrayValue?: { readonly values?: readonly IOtlpAnyValue[] };
58
>
readonly kvlistValue?: { readonly values?: readonly IOtlpKeyValue[] };
59
>
/** Base64-encoded bytes. */
60
>
readonly bytesValue?: string;
61
>
}
62
>
63
>
export interface IOtlpKeyValue {
64
>
readonly key: string;
65
>
readonly value?: IOtlpAnyValue;
66
>
}
67
>
68
>
export interface IOtlpStatus {
69
>
readonly code?: OtlpStatusCode;
70
>
readonly message?: string;
71
>
}
72
>
73
>
export interface IOtlpEvent {
74
>
readonly timeUnixNano?: string;
75
>
readonly name?: string;
76
>
readonly attributes?: readonly IOtlpKeyValue[];
77
>
readonly droppedAttributesCount?: number;
78
>
}
79
>
80
>
export interface IOtlpLink {
81
>
readonly traceId?: string;
82
>
readonly spanId?: string;
83
>
readonly traceState?: string;
84
>
readonly attributes?: readonly IOtlpKeyValue[];
85
>
readonly droppedAttributesCount?: number;
86
>
readonly flags?: number;
87
>
}
88
>
89
>
export interface IOtlpSpan {
90
>
readonly traceId: string;
91
>
readonly spanId: string;
92
>
readonly traceState?: string;
93
>
readonly parentSpanId?: string;
94
>
readonly flags?: number;
95
>
readonly name?: string;
96
>
readonly kind?: OtlpSpanKind;
97
>
readonly startTimeUnixNano?: string;
98
>
readonly endTimeUnixNano?: string;
99
>
readonly attributes?: readonly IOtlpKeyValue[];
100
>
readonly droppedAttributesCount?: number;
101
>
readonly events?: readonly IOtlpEvent[];
102
>
readonly droppedEventsCount?: number;
103
>
readonly links?: readonly IOtlpLink[];
104
>
readonly droppedLinksCount?: number;
105
>
readonly status?: IOtlpStatus;
106
>
}
107
>
108
>
export interface IOtlpInstrumentationScope {
109
>
readonly name?: string;
110
>
readonly version?: string;
111
>
readonly attributes?: readonly IOtlpKeyValue[];
112
>
readonly droppedAttributesCount?: number;
113
>
}
114
>
115
>
export interface IOtlpScopeSpans {
116
>
readonly scope?: IOtlpInstrumentationScope;
117
>
readonly spans?: readonly IOtlpSpan[];
118
>
readonly schemaUrl?: string;
119
>
}
120
>
121
>
export interface IOtlpResource {
122
>
readonly attributes?: readonly IOtlpKeyValue[];
123
>
readonly droppedAttributesCount?: number;
124
>
}
125
>
126
>
export interface IOtlpResourceSpans {
127
>
readonly resource?: IOtlpResource;
128
>
readonly scopeSpans?: readonly IOtlpScopeSpans[];
129
>
readonly schemaUrl?: string;
130
>
}
131
>
132
>
/** The body shape of `POST /v1/traces`. */
133
>
export interface IOtlpExportTraceServiceRequest {
134
>
readonly resourceSpans?: readonly IOtlpResourceSpans[];
135
>
}
136
>
137
>
/**
138
>
* The response shape from `POST /v1/traces`.
139
>
*
140
>
* On full success: `{}` is acceptable (per spec).
141
>
* On partial success: `partialSuccess` is set; the request is NOT retried.
142
>
*/
143
>
export interface IOtlpExportTraceServiceResponse {
144
>
readonly partialSuccess?: {
145
>
readonly rejectedSpans?: number;
146
>
readonly errorMessage?: string;
147
>
};
148
>
}