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

How do you get the result from queryExecutionClient.queryExecute()?

r_weber
DynaMight Champion
DynaMight Champion

What is wrong with this code? It's async, but shouldn't there be something in result (I verfified that the executed query returns data)

async function getEntityName(entityId) {
  console.log(entityId)
  const eType = entityId.split('-')[0];
  console.log(eType);

  const query = 'fetch dt.entity.'+eType+' | filter id=="'+entityId+'"';
  console.log(query)
  const result = await queryExecutionClient.queryExecute({
    body: {
      query,
    }
  });
  console.log(result)
}

 

"result" just shows:

{
  result: undefined,
  ttlSeconds: 399,
  progress: undefined,
  requestToken: "jghsd2LVTPmQDTkWIl4QlQ==",
  state: "RUNNING"
}

 

Certified Dynatrace Master, Dynatrace Partner - 360Performance.net
5 REPLIES 5

sinisa_zubic
Dynatrace Champion
Dynatrace Champion

Hi @r_weber 

If you don't add further props to the body, then this is expected behavior. you start a query and get as a result a request token you can use to poll for the result.

But as part of body, you can add another property requestTimeoutMilliseconds , where you would wait x milliseconds for the query to be executed. That should do the trick in your case

const result = await queryExecutionClient.queryExecute({
    body: {
      query,
      requestTimeoutMilliseconds: 30000
    }
  });

 

An easier way to query data is ou use the useDqlQuery hook, https://developer.dynatrace.com/develop/data/query-and-visualize/

 

Best,
Sini

 

Thanks @sinisa_zubic ,

the explicit addition of the requestTimeout should be documented and used in the examples!
This seems to work, now...

Btw. I started with useDqlQuery hook, but since I saw the same behavior I gave the executionClient a try. I will try the hook again...lets see what happens.

Certified Dynatrace Master, Dynatrace Partner - 360Performance.net

r_weber
DynaMight Champion
DynaMight Champion

The version with useDqlQuery crashes on me:


async function getEntityName(entityId) {
  console.log(entityId)
  const eType = entityId.split('-')[0];
  console.log(eType);

  const query = 'fetch dt.entity.'+eType+' | filter id=="'+entityId+'"';
  console.log(query)
  /*const result = await queryExecutionClient.queryExecute({
    body: {
      query,
      requestTimeoutMilliseconds: 30000
    }
  });
*/
  const result = useDqlQuery({
    body: {
      query,
    },
  });
  console.log(result)
}
An error occurred: {"code": 541, "message": "Execution crashed.", "details": {"type": "BAD_REQUEST", "message": "<stripped secret anyhow::Error>"}}

 

Certified Dynatrace Master, Dynatrace Partner - 360Performance.net

imsingh
Dynatrace Helper
Dynatrace Helper

@r_weber are you using the hooks in app functions? Hooks can only be used in your react code. For all other places besides your react code, I'd suggest using `queryExecutionClient` instead.

r_weber
DynaMight Champion
DynaMight Champion

OK, that wasn't clear. I tried to use it in a workflow.

Certified Dynatrace Master, Dynatrace Partner - 360Performance.net

Featured Posts