Skip to content

Commit 40f08d0

Browse files
authored
fix: only include trace columns in query when configured (#9)
* fix: only include trace columns in query when configured Tags, serviceTags, statusCode, statusMessage, and kind columns are now only added to the trace detail SQL when the user has configured them in datasource settings, preventing errors on tables missing those columns. * chore: bump version to 1.4.1
1 parent 6d6231c commit 40f08d0

3 files changed

Lines changed: 6 additions & 14 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "datasource-databend",
3-
"version": "1.4.0",
3+
"version": "1.4.1",
44
"description": "Grafana datasource plugin for Databend",
55
"scripts": {
66
"build": "webpack -c ./.config/webpack/webpack.config.ts --env production",

src/data/sqlGenerator.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -270,23 +270,15 @@ function generateTraceIdSql(options: QueryBuilderOptions): string {
270270
}
271271
if (tagsCol) {
272272
selectParts.push(`${tagsCol.name} AS tags`);
273-
} else {
274-
selectParts.push(`'[]' AS tags`);
275273
}
276274
if (serviceTagsCol) {
277275
selectParts.push(`${serviceTagsCol.name} AS serviceTags`);
278-
} else {
279-
selectParts.push(`'[]' AS serviceTags`);
280276
}
281277
if (statusCodeCol) {
282278
selectParts.push(`CASE WHEN ${statusCodeCol.name} IN ('Error', 'STATUS_CODE_ERROR') THEN 2 ELSE 0 END AS statusCode`);
283-
} else {
284-
selectParts.push(`0 AS statusCode`);
285279
}
286280
if (statusMessageCol) {
287281
selectParts.push(`${statusMessageCol.name} AS statusMessage`);
288-
} else {
289-
selectParts.push(`'' AS statusMessage`);
290282
}
291283
if (kindCol) {
292284
selectParts.push(`${kindCol.name} AS kind`);

src/data/utils.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,11 @@ export const transformQueryResponseWithTraceAndLogLinks = (
126126
{ name: settings.tracesServiceNameColumn || 'service_name', hint: ColumnHint.TraceServiceName },
127127
{ name: settings.tracesDurationColumn || 'duration', hint: ColumnHint.TraceDurationTime },
128128
{ name: settings.tracesStartTimeColumn || 'timestamp', hint: ColumnHint.Time },
129-
{ name: settings.tracesTagsColumn || 'span_attributes', hint: ColumnHint.TraceTags },
130-
{ name: settings.tracesServiceTagsColumn || 'resource_attributes', hint: ColumnHint.TraceServiceTags },
131-
{ name: settings.tracesStatusCodeColumn || 'status_code', hint: ColumnHint.TraceStatusCode },
132-
{ name: settings.tracesStatusMessageColumn || 'status_message', hint: ColumnHint.TraceStatusMessage },
133-
{ name: settings.tracesKindColumn || 'span_kind', hint: ColumnHint.TraceKind },
129+
...(settings.tracesTagsColumn ? [{ name: settings.tracesTagsColumn, hint: ColumnHint.TraceTags }] : []),
130+
...(settings.tracesServiceTagsColumn ? [{ name: settings.tracesServiceTagsColumn, hint: ColumnHint.TraceServiceTags }] : []),
131+
...(settings.tracesStatusCodeColumn ? [{ name: settings.tracesStatusCodeColumn, hint: ColumnHint.TraceStatusCode }] : []),
132+
...(settings.tracesStatusMessageColumn ? [{ name: settings.tracesStatusMessageColumn, hint: ColumnHint.TraceStatusMessage }] : []),
133+
...(settings.tracesKindColumn ? [{ name: settings.tracesKindColumn, hint: ColumnHint.TraceKind }] : []),
134134
],
135135
filters: [],
136136
orderBy: [],

0 commit comments

Comments
 (0)