cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to query for spans that has an exception event?

bren
Newcomer

Hi,

When I do a simple DQL query on the spans, I can see some spans have exceptions like below. The exceptions are wrapped as records in an array under "span.events" field.

How do I write a DQL query to pick out spans with certain exceptions, for example "java.sql.BatchUpdateException"?
It looks like I should use "iAny". However the example from https://docs.dynatrace.com/docs/platform/grail/dynatrace-query-language/operators#iAny is only for simple type, not records.

Thanks!

 

    {
      "trace.id": "674367267460f48738534bff81e3718f",
      "span.id": "f0a1bfa933cad913",
      "start_time": "2024-09-16T09:13:09.991600000+10:00",
      "end_time": "2024-09-16T09:13:59.999816000+10:00",
      "span.parent_id": "f68ff88792574c09",
      "duration": "50008216000",
      ... ...
      "span.events": [
        {
          "span_event.name": "exception",
          "exception.message": "Lock wait timeout exceeded; try restarting transaction",
          "exception.type": "java.sql.BatchUpdateException",
          "exception.id": "9d6064b5304e83f1",
          "exception.escaped": true,
          "exception.is_caused_by_root": true,
          "exception.file.full": "SQLError.java",
          "exception.line_number": "223",
          "exception.stack_trace": "... ..."
          "exception.caused_by_id": "50fe50882eeef674"
        },
        {
          "span_event.name": "exception",
          "exception.message": "Lock wait timeout exceeded; try restarting transaction",
          "exception.type": "com.mysql.cj.jdbc.exceptions.MySQLTransactionRollbackException",
          "exception.id": "50fe50882eeef674",
          "exception.escaped": false,
          "exception.is_caused_by_root": false,
          "exception.file.full": "SQLError.java",
          "exception.line_number": "124",
          "exception.stack_trace": "... ..."
        }
      ],
      "dt.retain.size": "22598"
    }

 

1 REPLY 1

bren
Newcomer

Ah I found the answer myself. Do something like below.

fetch spans
| filter 
  like( lower(db.query.text), "%update%") and
  iAny(span.events[][span_event.name] == "exception") and
  iAny(like(span.events[][exception.type], "%BatchUpdateException")) 

 

Featured Posts