Skip to content

Commit

Permalink
feat: populate span links
Browse files Browse the repository at this point in the history
  • Loading branch information
taj-p committed Mar 8, 2023
1 parent 5ed7c77 commit 93ea6f5
Showing 1 changed file with 52 additions and 1 deletion.
53 changes: 52 additions & 1 deletion packages/jaeger-ui/src/api/jaeger.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,40 @@ function getJSON(url, options = {}) {
});
}

function populateSpanReference(reference, traceUrl) {
if (reference.span) {
return Promise.resolve();
}

return (
getJSON(traceUrl)
.then(refTraceData => {
const referenceTrace = refTraceData && refTraceData.data && refTraceData.data[0];
if (
!referenceTrace ||
!Array.isArray(referenceTrace.spans) ||
typeof referenceTrace.processes !== 'object'
) {
return;
}

// We need to reassign `reference.span`, hence ignore no-param-reassign linting rule.
// eslint-disable-next-line
reference.span = referenceTrace.spans.find(
candidateSpan => candidateSpan.spanID === reference.spanID
);
if (reference.span && typeof reference.span.processID === 'string') {
// We need to reassign `reference.span`, hence ignore no-param-reassign linting rule.
// eslint-disable-next-line
reference.span.process = referenceTrace.processes[reference.span.processID];
}
})
// Catch and swallow error. If we can't parse the reference, Jaeger UI should continue to function
// `reference.span` population.
.catch(e => console.error(e))
);
}

export const DEFAULT_API_ROOT = prefixUrl('/api/');
export const ANALYTICS_ROOT = prefixUrl('/analytics/');
export const DEFAULT_DEPENDENCY_LOOKBACK = moment.duration(1, 'weeks').asMilliseconds();
Expand Down Expand Up @@ -112,7 +146,24 @@ const JaegerAPI = {
return getJSON(`${this.apiRoot}services`);
},
fetchTrace(id) {
return getJSON(`${this.apiRoot}traces/${id}`);
return getJSON(`${this.apiRoot}traces/${id}`).then(async traceData => {
const trace = traceData.data && traceData.data[0];
const populateSpanReferences = [];
if (trace && trace.spans) {
trace.spans.map(span => {
span.references.map(reference => {
populateSpanReferences.push(
populateSpanReference(reference, `${this.apiRoot}traces/${reference.traceID}`)
);

return null;
});
return null;
});
}

return Promise.all(populateSpanReferences).then(() => traceData);
});
},
searchTraces(query) {
return getJSON(`${this.apiRoot}traces`, { query });
Expand Down

0 comments on commit 93ea6f5

Please sign in to comment.