From 1a62d94c550a7730b4f7afd59bd4f5d8991fd6fc Mon Sep 17 00:00:00 2001 From: Andre Pereira Date: Fri, 12 Apr 2024 12:26:27 +0100 Subject: [PATCH] Tempo: Return raw result from traceql query (#86032) Return raw result from traceql query --- .../dataquery/x/TempoDataQuery_types.gen.ts | 1 + .../kinds/dataquery/types_dataquery_gen.go | 1 + .../plugins/datasource/tempo/dataquery.cue | 2 +- .../plugins/datasource/tempo/dataquery.gen.ts | 1 + .../datasource/tempo/resultTransformer.ts | 20 ++++++++++++++++--- 5 files changed, 21 insertions(+), 4 deletions(-) diff --git a/packages/grafana-schema/src/raw/composable/tempo/dataquery/x/TempoDataQuery_types.gen.ts b/packages/grafana-schema/src/raw/composable/tempo/dataquery/x/TempoDataQuery_types.gen.ts index fbb226a11f3..af517e367a2 100644 --- a/packages/grafana-schema/src/raw/composable/tempo/dataquery/x/TempoDataQuery_types.gen.ts +++ b/packages/grafana-schema/src/raw/composable/tempo/dataquery/x/TempoDataQuery_types.gen.ts @@ -85,6 +85,7 @@ export enum SearchStreamingState { * The type of the table that is used to display the search results */ export enum SearchTableType { + Raw = 'raw', Spans = 'spans', Traces = 'traces', } diff --git a/pkg/tsdb/tempo/kinds/dataquery/types_dataquery_gen.go b/pkg/tsdb/tempo/kinds/dataquery/types_dataquery_gen.go index 13a6c6117b9..bfb397b514d 100644 --- a/pkg/tsdb/tempo/kinds/dataquery/types_dataquery_gen.go +++ b/pkg/tsdb/tempo/kinds/dataquery/types_dataquery_gen.go @@ -19,6 +19,7 @@ const ( // Defines values for SearchTableType. const ( + SearchTableTypeRaw SearchTableType = "raw" SearchTableTypeSpans SearchTableType = "spans" SearchTableTypeTraces SearchTableType = "traces" ) diff --git a/public/app/plugins/datasource/tempo/dataquery.cue b/public/app/plugins/datasource/tempo/dataquery.cue index 786f000fef6..b47078559b0 100644 --- a/public/app/plugins/datasource/tempo/dataquery.cue +++ b/public/app/plugins/datasource/tempo/dataquery.cue @@ -59,7 +59,7 @@ composableKinds: DataQuery: { #SearchStreamingState: "pending" | "streaming" | "done" | "error" @cuetsy(kind="enum") // The type of the table that is used to display the search results - #SearchTableType: "traces" | "spans" @cuetsy(kind="enum") + #SearchTableType: "traces" | "spans" | "raw" @cuetsy(kind="enum") // static fields are pre-set in the UI, dynamic fields are added by the user #TraceqlSearchScope: "intrinsic" | "unscoped" | "resource" | "span" @cuetsy(kind="enum") diff --git a/public/app/plugins/datasource/tempo/dataquery.gen.ts b/public/app/plugins/datasource/tempo/dataquery.gen.ts index 17cce1c50d0..5e0bb9543ee 100644 --- a/public/app/plugins/datasource/tempo/dataquery.gen.ts +++ b/public/app/plugins/datasource/tempo/dataquery.gen.ts @@ -83,6 +83,7 @@ export enum SearchStreamingState { * The type of the table that is used to display the search results */ export enum SearchTableType { + Raw = 'raw', Spans = 'spans', Traces = 'traces', } diff --git a/public/app/plugins/datasource/tempo/resultTransformer.ts b/public/app/plugins/datasource/tempo/resultTransformer.ts index c32c0f203e5..44fc703ef04 100644 --- a/public/app/plugins/datasource/tempo/resultTransformer.ts +++ b/public/app/plugins/datasource/tempo/resultTransformer.ts @@ -529,10 +529,24 @@ export function formatTraceQLResponse( instanceSettings: DataSourceInstanceSettings, tableType?: SearchTableType ) { - if (tableType === SearchTableType.Spans) { - return createTableFrameFromTraceQlQueryAsSpans(data, instanceSettings); + switch (tableType) { + case SearchTableType.Spans: + return createTableFrameFromTraceQlQueryAsSpans(data, instanceSettings); + case SearchTableType.Raw: + return createDataFrameFromTraceQlQuery(data); + default: + return createTableFrameFromTraceQlQuery(data, instanceSettings); } - return createTableFrameFromTraceQlQuery(data, instanceSettings); +} + +function createDataFrameFromTraceQlQuery(data: TraceSearchMetadata[]) { + return [ + createDataFrame({ + name: 'Raw response', + refId: 'raw', + fields: [{ name: 'response', type: FieldType.string, values: [JSON.stringify(data, null, 2)] }], + }), + ]; } /**