Skip to content

Span events & links not selected when querying trace from table view #1262

Open
@ValentinLvr

Description

@ValentinLvr

What happened:

When I'm jumping to a TraceId link from a table result, events & links are not in the SELECT clause of the generated SQL.

In more details:

  1. I'm doing a basic query with the table query type
SELECT TraceId 
FROM default.otel_traces
LIMIT 10

Image

  1. Then, I click on the TraceId embedded link to view the trace on a second panel

Image

WITH
  'XXXXXXX' as trace_id,
  (
    SELECT
      min(Start)
    FROM
      "default"."otel_traces_trace_id_ts"
    WHERE
      TraceId = trace_id
  ) as trace_start,
  (
    SELECT
      max(End) + 1
    FROM
      "default"."otel_traces_trace_id_ts"
    WHERE
      TraceId = trace_id
  ) as trace_end
SELECT
  "TraceId" as traceID,
  "SpanId" as spanID,
  "ParentSpanId" as parentSpanID,
  "ServiceName" as serviceName,
  "SpanName" as operationName,
  multiply (toUnixTimestamp64Nano ("Timestamp"), 0.000001) as startTime,
  multiply ("Duration", 0.000001) as duration,
  arrayMap (
    key -> map ('key', key, 'value', "SpanAttributes" [key]),
    mapKeys ("SpanAttributes")
  ) as tags,
  arrayMap (
    key -> map ('key', key, 'value', "ResourceAttributes" [key]),
    mapKeys ("ResourceAttributes")
  ) as serviceTags,
  if (
    "StatusCode" IN ('Error', 'STATUS_CODE_ERROR'),
    2,
    0
  ) as statusCode,
  "SpanKind" as kind,
  "StatusMessage" as statusMessage,
  "TraceState" as traceState
FROM
  "default"."otel_traces"
WHERE
  traceID = trace_id
  AND "Timestamp" >= trace_start
  AND "Timestamp" <= trace_end
LIMIT
  1000

As you can see, events & links are not added by default on the SELECT clause.
I either have to add it myself OR unselect then select again the Use Otel 1.29 button

What you expected to happen:

I was expecting to have the span links & events added to the SELECT clause like we have by default when browsing from the traces query type.

WITH
  'XXXXXXX' as trace_id,
  (
    SELECT
      min(Start)
    FROM
      "default"."otel_traces_trace_id_ts"
    WHERE
      TraceId = trace_id
  ) as trace_start,
  (
    SELECT
      max(End) + 1
    FROM
      "default"."otel_traces_trace_id_ts"
    WHERE
      TraceId = trace_id
  ) as trace_end
SELECT
  "TraceId" as traceID,
  "SpanId" as spanID,
  "ParentSpanId" as parentSpanID,
  "ServiceName" as serviceName,
  "SpanName" as operationName,
  multiply (toUnixTimestamp64Nano ("Timestamp"), 0.000001) as startTime,
  multiply ("Duration", 0.000001) as duration,
  arrayMap (
    key -> map ('key', key, 'value', "SpanAttributes" [key]),
    mapKeys ("SpanAttributes")
  ) as tags,
  arrayMap (
    key -> map ('key', key, 'value', "ResourceAttributes" [key]),
    mapKeys ("ResourceAttributes")
  ) as serviceTags,
  if (
    "StatusCode" IN ('Error', 'STATUS_CODE_ERROR'),
    2,
    0
  ) as statusCode,
-- HERE we have the Events (logs) & links (references)->
  arrayMap (
    (name, timestamp, attributes) -> tuple (
      name,
      toString (toUnixTimestamp64Milli (timestamp)),
      arrayMap (
        key -> map ('key', key, 'value', attributes[key]),
        mapKeys (attributes)
      )
    )::Tuple (
      name String,
      timestamp String,
      fields Array(Map (String, String))
    ),
    "Events".Name,
    "Events".Timestamp,
    "Events".Attributes
  ) AS logs,
  arrayMap (
    (traceID, spanID, attributes) -> tuple (
      traceID,
      spanID,
      arrayMap (
        key -> map ('key', key, 'value', attributes[key]),
        mapKeys (attributes)
      )
    )::Tuple (
      traceID String,
      spanID String,
      tags Array(Map (String, String))
    ),
    "Links".TraceId,
    "Links".SpanId,
    "Links".Attributes
  ) AS references,
  "SpanKind" as kind,
  "StatusMessage" as statusMessage,
  "TraceState" as traceState
FROM
  "default"."otel_traces"
WHERE
  traceID = trace_id
  AND "Timestamp" >= trace_start
  AND "Timestamp" <= trace_end
LIMIT
  1000

Environment:

  • Grafana version: 12.0.0
  • Plugin version: v4.9.0
  • OS Grafana is installed on: Kubernetes (helm chart)
  • User OS & Browser: MacOs & Chrome

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Incoming

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions