51
52
for (const rs of request.resourceSpans) {
54
continue;
55
}
56
>
const resourceAttrs = decodeAttributes(rs.resource?.attributes);
otlpJsonDecode.ts
57
>
58
>
for (const ss of rs.scopeSpans ?? []) {
59
>
if (!ss) {
60
continue;
61
}
63
>
try {
64
>
const decoded = decodeSpan(span, resourceAttrs);
65
>
if (decoded) {
66
spans.push(decoded);
67
} else {
68
rejected++;
69
}
71
rejected++;
72
errors.push(e instanceof Error ? e.message : String(e));
73
}
75
>
}
76
>
}
77
78
return { spans, rejected, errors };
79
}
80
81
>
function decodeSpan(span: IOtlpSpan | undefined, resourceAttrs: Record<string, AttrValue>): ICompletedSpanData | undefined {
otlpJsonDecode.ts
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}`);
90
}
92
throw new Error(`invalid spanId: ${span.spanId}`);
93
}