Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend JSON file reader to handle array of objects with resourceSpans #2254

Closed
wants to merge 7 commits into from
16 changes: 15 additions & 1 deletion packages/jaeger-ui/src/utils/readJsonFile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,21 @@ export default function readJsonFile(fileList: { file: File }): Promise<string>
}
try {
const traceObj = JSON.parse(reader.result);
if ('resourceSpans' in traceObj) {
if (Array.isArray(traceObj) && traceObj.every(obj => 'resourceSpans' in obj)) {
const mergedResourceSpans = traceObj.reduce((acc, obj) => {
acc.push(...obj.resourceSpans);
return acc;
}, []);

const mergedTraceObj = { resourceSpans: mergedResourceSpans };
JaegerAPI.transformOTLP(mergedTraceObj)
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved
.then((result: string) => {
resolve(result);
})
.catch(() => {
reject(new Error(`Error converting traces to OTLP`));
});
} else if ('resourceSpans' in traceObj) {
JaegerAPI.transformOTLP(traceObj)
.then((result: string) => {
resolve(result);
Expand Down