src/vs/platform/otel/node/otlp/otlpJsonDecode.ts

245 LOC · 224 covered · 21 uncovered · 69 ranges · 38 concepts · 16 introducers · 20 tests

File neighbourhood

The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the filesrc/vs/platform/otel/node/otlp/otlpJsonTypes.ts · 148 LOCotlp/otlpJsonTypes.tslocalOtlpReceiver.ts ×1 · 2 introduced LOClocalOtlpReceiver.ts ×1localOtlpReceiver.ts ×2 · 4 introduced LOClocalOtlpReceiver.ts ×2localOtlpReceiver.ts ×1 · 1 introduced LOClocalOtlpReceiver.ts ×1localOtlpReceiver.ts ×1 · 1 introduced LOClocalOtlpReceiver.ts ×1localOtlpReceiver.ts ×2 · 7 introduced LOClocalOtlpReceiver.ts ×2localOtlpReceiver.ts ×1 · 3 introduced LOClocalOtlpReceiver.ts ×1localOtlpReceiver.ts ×3 · 9 introduced LOClocalOtlpReceiver.ts ×3localOtlpReceiver.ts ×4 · 14 introduced LOClocalOtlpReceiver.ts ×4localOtlpReceiver.ts ×5 · 25 introduced LOClocalOtlpReceiver.ts ×5localOtlpReceiver.ts ×1 · 4 introduced LOClocalOtlpReceiver.ts ×1localOtlpReceiver.ts ×1 · 3 introduced LOClocalOtlpReceiver.ts ×1localOtlpReceiver.ts ×1 · 1 introduced LOClocalOtlpReceiver.ts ×1localOtlpReceiver.ts ×1 · 4 introduced LOClocalOtlpReceiver.ts ×1localOtlpReceiver.ts ×1 · 1 introduced LOClocalOtlpReceiver.ts ×1localOtlpReceiver.ts ×1 · 3 introduced LOClocalOtlpReceiver.ts ×1localOtlpReceiver.ts ×1 · 5 introduced LOClocalOtlpReceiver.ts ×1localOtlpReceiver.ts ×1 · 1 introduced LOClocalOtlpReceiver.ts ×1localOtlpReceiver.ts ×6 · 21 introduced LOClocalOtlpReceiver.ts ×6localOtlpReceiver.ts ×6 · 100 introduced LOClocalOtlpReceiver.ts ×6otlpJsonDecode.ts ×8 · 26 introduced LOCotlpJsonDecode.ts ×8otlpJsonDecode.ts ×2 · 11 introduced LOCotlpJsonDecode.ts ×2otlpJsonDecode.ts ×3 · 11 introduced LOCotlpJsonDecode.ts ×3otel - otlpJsonDecode span-level attribute overrides resource attribute on collision|occurrence=1 · 0 introduced LOCotel - otlpJsonDecode sp…otlpJsonDecode.ts ×1 · 5 introduced LOCotlpJsonDecode.ts ×1otlpJsonDecode.ts ×3 · 6 introduced LOCotlpJsonDecode.ts ×3otlpJsonDecode.ts ×7 · 16 introduced LOCotlpJsonDecode.ts ×7 all-zero parent|occurrence=1 · 0 introduced LOC all-zero parent|occurre…otlpJsonDecode.ts ×1 · 1 introduced LOCotlpJsonDecode.ts ×1otel - otlpJsonDecode treats time stringified as decimal nanos and floors to ms|occurrence=1 · 0 introduced LOCotel - otlpJsonDecode tr…otlpJsonDecode.ts ×1 · 1 introduced LOCotlpJsonDecode.ts ×1otlpJsonDecode.ts ×1 · 5 introduced LOCotlpJsonDecode.ts ×1otlpJsonDecode.ts ×12 · 29 introduced LOCotlpJsonDecode.ts ×12otlpJsonDecode.ts ×2 · 5 introduced LOCotlpJsonDecode.ts ×2otlpJsonDecode.ts ×1 · 2 introduced LOCotlpJsonDecode.ts ×1otlpJsonDecode.ts ×14 · 43 introduced LOCotlpJsonDecode.ts ×14otlpJsonDecode.ts ×1 · 2 introduced LOCotlpJsonDecode.ts ×1otlpJsonDecode.ts ×3 · 10 introduced LOCotlpJsonDecode.ts ×3otlpJsonDecode.ts ×9 · 199 introduced LOCotlpJsonDecode.ts ×9otel - localOtlpHttpReceiver accepts a valid OTLP-JSON payload and delivers decoded spans|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/otel/test/node/otlp/localOtlpReceiver.test|title=platform/otel - localOtlpHttpReceiver accepts a valid OTLP-JSON payload and delivers decoded spans|occurrence=1otel - localOtlpHttpRece…otel - localOtlpHttpReceiver binds to 127.0.0.1 on an ephemeral port|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/otel/test/node/otlp/localOtlpReceiver.test|title=platform/otel - localOtlpHttpReceiver binds to 127.0.0.1 on an ephemeral port|occurrence=1otel - localOtlpHttpRece…otel - localOtlpHttpReceiver forwards raw body to onForward callback unchanged|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/otel/test/node/otlp/localOtlpReceiver.test|title=platform/otel - localOtlpHttpReceiver forwards raw body to onForward callback unchanged|occurrence=1otel - localOtlpHttpRece…otel - localOtlpHttpReceiver rejects non-JSON content-type with 415|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/otel/test/node/otlp/localOtlpReceiver.test|title=platform/otel - localOtlpHttpReceiver rejects non-JSON content-type with 415|occurrence=1otel - localOtlpHttpRece…otel - localOtlpHttpReceiver rejects non-identity content-encoding with 415|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/otel/test/node/otlp/localOtlpReceiver.test|title=platform/otel - localOtlpHttpReceiver rejects non-identity content-encoding with 415|occurrence=1otel - localOtlpHttpRece…otel - localOtlpHttpReceiver returns 400 for invalid JSON|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/otel/test/node/otlp/localOtlpReceiver.test|title=platform/otel - localOtlpHttpReceiver returns 400 for invalid JSON|occurrence=1otel - localOtlpHttpRece…otel - localOtlpHttpReceiver returns 404 for unknown paths|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/otel/test/node/otlp/localOtlpReceiver.test|title=platform/otel - localOtlpHttpReceiver returns 404 for unknown paths|occurrence=1otel - localOtlpHttpRece…otel - localOtlpHttpReceiver returns 405 for non-POST|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/otel/test/node/otlp/localOtlpReceiver.test|title=platform/otel - localOtlpHttpReceiver returns 405 for non-POST|occurrence=1otel - localOtlpHttpRece…otel - localOtlpHttpReceiver returns 413 when body exceeds maxBodyBytes|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/otel/test/node/otlp/localOtlpReceiver.test|title=platform/otel - localOtlpHttpReceiver returns 413 when body exceeds maxBodyBytes|occurrence=1otel - localOtlpHttpRece…otel - localOtlpHttpReceiver returns partial_success when some spans are rejected|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/otel/test/node/otlp/localOtlpReceiver.test|title=platform/otel - localOtlpHttpReceiver returns partial_success when some spans are rejected|occurrence=1otel - localOtlpHttpRece…otel - localOtlpHttpReceiver still responds 200 even if onForward throws|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/otel/test/node/otlp/localOtlpReceiver.test|title=platform/otel - localOtlpHttpReceiver still responds 200 even if onForward throws|occurrence=1otel - localOtlpHttpRece…otel - otlpJsonDecode decodes a complete chat span with all attribute types and resource merge|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/otel/test/node/otlp/otlpJsonDecode.test|title=platform/otel - otlpJsonDecode decodes a complete chat span with all attribute types and resource merge|occurrence=1otel - otlpJsonDecode de… nested attribute arrays and kvlistValue|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/otel/test/node/otlp/otlpJsonDecode.test|title=platform/otel - otlpJsonDecode falls back to JSON for mixed-type / nested attribute arrays and kvlistValue|occurrence=1 nested attribute arrays…otel - otlpJsonDecode handles an empty request|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/otel/test/node/otlp/otlpJsonDecode.test|title=platform/otel - otlpJsonDecode handles an empty request|occurrence=1otel - otlpJsonDecode ha…otel - otlpJsonDecode maps status codes: ERROR → ERROR, missing → UNSET|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/otel/test/node/otlp/otlpJsonDecode.test|title=platform/otel - otlpJsonDecode maps status codes: ERROR → ERROR, missing → UNSET|occurrence=1otel - otlpJsonDecode ma… all-zero parent|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/otel/test/node/otlp/otlpJsonDecode.test|title=platform/otel - otlpJsonDecode preserves parent span id; drops empty / all-zero parent|occurrence=1 all-zero parent|occurre… missing times|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/otel/test/node/otlp/otlpJsonDecode.test|title=platform/otel - otlpJsonDecode rejects spans with invalid trace_id / span_id / missing times|occurrence=1 missing times|occurrenc…otel - otlpJsonDecode returns errors[] when an exception is thrown for a span|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/otel/test/node/otlp/otlpJsonDecode.test|title=platform/otel - otlpJsonDecode returns errors[] when an exception is thrown for a span|occurrence=1otel - otlpJsonDecode re…otel - otlpJsonDecode span-level attribute overrides resource attribute on collision|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/otel/test/node/otlp/otlpJsonDecode.test|title=platform/otel - otlpJsonDecode span-level attribute overrides resource attribute on collision|occurrence=1otel - otlpJsonDecode sp…otel - otlpJsonDecode treats time stringified as decimal nanos and floors to ms|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/otel/test/node/otlp/otlpJsonDecode.test|title=platform/otel - otlpJsonDecode treats time stringified as decimal nanos and floors to ms|occurrence=1otel - otlpJsonDecode tr…Focused file · src/vs/platform/otel/node/otlp/otlpJsonDecode.ts · 245 LOCotlp/otlpJsonDecode.ts

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.

1 > /*--------------------------------------------------------------------------------------------- otlpJsonDecode.ts ×9
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 > import { ICompletedSpanData, ISpanEventRecord, SpanStatusCode } from '../../common/spanData.js';
7 > import {
8 > IOtlpAnyValue,
9 > IOtlpEvent,
10 > IOtlpExportTraceServiceRequest,
11 > IOtlpKeyValue,
12 > IOtlpSpan,
13 > OtlpStatusCode,
14 > } from './otlpJsonTypes.js';
15 >
16 > type AttrValue = string | number | boolean | string[];
17 >
18 > const HEX_RE = /^[0-9a-fA-F]+$/;
19 > const ALL_ZERO_TRACE_ID = '00000000000000000000000000000000';
20 > const ALL_ZERO_SPAN_ID = '0000000000000000';
21 >
22 > /**
23 > * Decode an OTLP/HTTP JSON `ExportTraceServiceRequest` into flat
24 > * {@link ICompletedSpanData} records.
25 > *
26 > * The decoder is intentionally lenient: malformed individual spans are skipped
27 > * and reported via `partialFailures`, so the receiver can return a 200 with
28 > * `partial_success` populated (per OTLP/HTTP spec) rather than failing the
29 > * whole batch.
30 > *
31 > * Resource attributes (e.g. `service.name`) are merged into each span's
32 > * attribute map. Span-level attributes win on key collision. This keeps the
33 > * SQLite schema flat and avoids a separate resource table.
34 > *
35 > * Unknown OTLP fields (e.g. `links`, `traceState`) are dropped silently.
36 > */
37 > export interface IDecodeResult {
38 > readonly spans: readonly ICompletedSpanData[];
39 > readonly rejected: number;
40 > readonly errors: readonly string[];
41 > }
42 >
43 > export function decodeExportTraceRequest(request: IOtlpExportTraceServiceRequest | undefined): IDecodeResult {
44 > if (!request || !Array.isArray(request.resourceSpans)) { otlpJsonDecode.ts ×3
45 > return { spans: [], rejected: 0, errors: [] }; otlpJsonDecode.ts ×1
46 > }
48 > const spans: ICompletedSpanData[] = [];
49 > const errors: string[] = [];
50 > let rejected = 0;
51 >
52 > for (const rs of request.resourceSpans) {
53 > if (!rs) { otlpJsonDecode.ts ×14
54 continue;
55 }
56 > const resourceAttrs = decodeAttributes(rs.resource?.attributes); otlpJsonDecode.ts ×14
57 >
58 > for (const ss of rs.scopeSpans ?? []) {
59 > if (!ss) {
60 continue;
61 }
62 > for (const span of ss.spans ?? []) { otlpJsonDecode.ts ×14
63 > try {
64 > const decoded = decodeSpan(span, resourceAttrs);
65 > if (decoded) {
66 > spans.push(decoded); otlpJsonDecode.ts ×12
67 > } else {
68 rejected++;
69 }
70 > } catch (e) { otlpJsonDecode.ts ×14
71 > rejected++; otlpJsonDecode.ts ×2
72 > errors.push(e instanceof Error ? e.message : String(e));
73 > }
75 > }
76 > }
78 > return { spans, rejected, errors };
79 > }
81 > function decodeSpan(span: IOtlpSpan | undefined, resourceAttrs: Record<string, AttrValue>): ICompletedSpanData | undefined { otlpJsonDecode.ts ×14
82 > if (!span) {
83 return undefined;
84 }
86 > const traceId = (span.traceId ?? '').toLowerCase();
87 > const spanId = (span.spanId ?? '').toLowerCase();
88 > if (!isValidHex(traceId, 32) || traceId === ALL_ZERO_TRACE_ID) {
89 > throw new Error(`invalid traceId: ${span.traceId}`); otlpJsonDecode.ts ×2
90 > }
91 > if (!isValidHex(spanId, 16) || spanId === ALL_ZERO_SPAN_ID) { otlpJsonDecode.ts ×14
92 > throw new Error(`invalid spanId: ${span.spanId}`); otlpJsonDecode.ts ×3
93 > }
95 > let parentSpanId: string | undefined;
96 > if (span.parentSpanId) {
97 > const ps = span.parentSpanId.toLowerCase(); otlpJsonDecode.ts ×1
98 > if (isValidHex(ps, 16) && ps !== ALL_ZERO_SPAN_ID) {
99 > parentSpanId = ps;
100 > }
101 > }
103 > const startTime = nanosToMillis(span.startTimeUnixNano);
104 > const endTime = nanosToMillis(span.endTimeUnixNano);
105 > if (startTime === undefined || endTime === undefined) { otlpJsonDecode.ts ×14
106 > throw new Error(`missing span time bounds`); otlpJsonDecode.ts ×3
107 > }
109 > const attributes: Record<string, AttrValue> = { ...resourceAttrs };
110 > for (const kv of span.attributes ?? []) { otlpJsonDecode.ts ×14
111 > setAttribute(attributes, kv); otlpJsonDecode.ts ×7
112 > }
114 > const events: ISpanEventRecord[] = [];
115 > for (const ev of span.events ?? []) { otlpJsonDecode.ts ×14
116 > const decoded = decodeEvent(ev); otlpJsonDecode.ts ×8
117 > if (decoded) {
118 > events.push(decoded);
119 > }
120 > }
122 > const status = decodeStatus(span.status?.code, span.status?.message); otlpJsonDecode.ts ×14
123 >
124 > return {
125 > name: span.name ?? '',
126 > traceId,
127 > spanId,
128 > parentSpanId,
129 > startTime,
130 > endTime,
131 > status,
132 > attributes,
133 > events,
134 > };
135 > }
137 > function decodeEvent(ev: IOtlpEvent | undefined): ISpanEventRecord | undefined { otlpJsonDecode.ts ×8
138 > if (!ev) {
139 return undefined;
140 }
141 > const timestamp = nanosToMillis(ev.timeUnixNano); otlpJsonDecode.ts ×8
142 > if (timestamp === undefined) {
143 return undefined;
144 }
145 > const attributes: Record<string, AttrValue> = {}; otlpJsonDecode.ts ×8
146 > for (const kv of ev.attributes ?? []) {
147 > setAttribute(attributes, kv);
148 > }
149 > return {
150 > name: ev.name ?? '',
151 > timestamp,
152 > attributes: Object.keys(attributes).length > 0 ? attributes : undefined,
153 > };
154 > }
156 > function decodeStatus(code: OtlpStatusCode | undefined, message: string | undefined): ICompletedSpanData['status'] { otlpJsonDecode.ts ×12
157 > switch (code) {
158 > case OtlpStatusCode.OK:
159 > return { code: SpanStatusCode.OK, message }; otlpJsonDecode.ts ×8
160 > case OtlpStatusCode.ERROR: otlpJsonDecode.ts ×12
161 > return { code: SpanStatusCode.ERROR, message }; otlpJsonDecode.ts ×1
162 > case OtlpStatusCode.UNSET: otlpJsonDecode.ts ×12
163 > default:
164 > return { code: SpanStatusCode.UNSET, message }; otlpJsonDecode.ts ×1
166 > }
168 > function decodeAttributes(kvs: readonly IOtlpKeyValue[] | undefined): Record<string, AttrValue> { otlpJsonDecode.ts ×14
169 > const out: Record<string, AttrValue> = {};
170 > if (!kvs) {
171 > return out; otlpJsonDecode.ts ×1
172 > }
173 > for (const kv of kvs) { otlpJsonDecode.ts ×1
174 > setAttribute(out, kv);
175 > }
176 > return out;
177 > }
179 > function setAttribute(target: Record<string, AttrValue>, kv: IOtlpKeyValue | undefined): void { otlpJsonDecode.ts ×7
180 > if (!kv || typeof kv.key !== 'string' || kv.key.length === 0) {
181 return;
182 }
183 > const value = decodeAnyValue(kv.value); otlpJsonDecode.ts ×7
184 > if (value !== undefined) {
185 > target[kv.key] = value;
186 > }
187 > }
189 > function decodeAnyValue(v: IOtlpAnyValue | undefined): AttrValue | undefined { otlpJsonDecode.ts ×7
190 > if (!v) {
191 return undefined;
192 }
193 > if (typeof v.stringValue === 'string') { otlpJsonDecode.ts ×7
194 > return v.stringValue;
195 > }
196 > if (typeof v.boolValue === 'boolean') { otlpJsonDecode.ts ×3
197 > return v.boolValue; otlpJsonDecode.ts ×8
198 > }
199 > if (v.intValue !== undefined) { otlpJsonDecode.ts ×3
200 > // intValue is a stringified int64; precision beyond Number.MAX_SAFE_INTEGER is lost
201 > const n = typeof v.intValue === 'string' ? Number(v.intValue) : v.intValue;
202 > return Number.isFinite(n) ? n : undefined;
203 > }
204 > if (typeof v.doubleValue === 'number') {
205 > return v.doubleValue; otlpJsonDecode.ts ×8
206 > }
207 > if (v.arrayValue?.values) { otlpJsonDecode.ts ×7
208 > // Only flat arrays of strings are first-class in ICompletedSpanData.attributes. otlpJsonDecode.ts ×3
209 > // For mixed/numeric/nested arrays, fall back to JSON for fidelity.
210 > const items = v.arrayValue.values.map(decodeAnyValue);
211 > if (items.every((x): x is string => typeof x === 'string')) {
212 > return items; otlpJsonDecode.ts ×8
213 > }
214 > return JSON.stringify(items); otlpJsonDecode.ts ×2
215 > }
216 > if (v.kvlistValue?.values) { otlpJsonDecode.ts ×7
217 > // Rare; preserve as JSON. otlpJsonDecode.ts ×2
218 > const obj: Record<string, AttrValue | undefined> = {};
219 > for (const kv of v.kvlistValue.values) {
220 > if (kv && typeof kv.key === 'string') {
221 > obj[kv.key] = decodeAnyValue(kv.value);
222 > }
223 > }
224 > return JSON.stringify(obj);
225 > }
226 if (typeof v.bytesValue === 'string') {
227 return v.bytesValue;
228 }
229 return undefined;
230 }
232 > function nanosToMillis(s: string | undefined): number | undefined { otlpJsonDecode.ts ×12
233 > if (s === undefined || s === '' || s === '0') {
234 > return undefined; otlpJsonDecode.ts ×3
235 > }
236 > // Avoid BigInt churn: parse as decimal string, truncate the last 6 digits (ns → ms). otlpJsonDecode.ts ×12
237 > // `s` is a non-negative integer per the spec.
238 > const trimmed = s.length <= 6 ? '0' : s.slice(0, -6);
239 > const n = Number(trimmed);
240 > return Number.isFinite(n) ? n : undefined;
241 > }
243 > function isValidHex(s: string, len: number): boolean { otlpJsonDecode.ts ×14
244 > return s.length === len && HEX_RE.test(s);
245 > }