Tempo: Only get span_names when they are in the response (#72663)

* Only get span names when they are in the response

* Find span_name field/labels
This commit is contained in:
Joey
2023-08-03 07:55:32 +01:00
committed by GitHub
parent 7431c0ddb1
commit b4c55765fe

View File

@@ -11,6 +11,7 @@ import {
DataSourceApi,
DataSourceInstanceSettings,
dateTime,
Field,
FieldType,
isValidGoDuration,
LoadingState,
@@ -650,14 +651,16 @@ function errorAndDurationQuery(
let durationsBySpanName: string[] = [];
let labels = [];
if (request.app === CoreApp.Explore) {
if (rateResponse.data[0][0]?.fields[1]?.values) {
labels = rateResponse.data[0][0]?.fields[1]?.values;
if (rateResponse.data[0][0] && request.app === CoreApp.Explore) {
const spanNameField = rateResponse.data[0][0].fields.find((field: Field) => field.name === 'span_name');
if (spanNameField && spanNameField.values) {
labels = spanNameField.values;
}
} else if (rateResponse.data[0]) {
rateResponse.data[0].map((df: DataFrame) => {
if (df.fields[1]?.labels && df.fields[1]?.labels['span_name']) {
labels.push(df.fields[1]?.labels['span_name']);
const spanNameLabels = df.fields.find((field: Field) => field.labels?.['span_name']);
if (spanNameLabels) {
labels.push(spanNameLabels.labels?.['span_name']);
}
});
}