11 Jan 2024 05:05 PM
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"
}
Solved! Go to Solution.
11 Jan 2024 05:55 PM
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
11 Jan 2024 06:39 PM
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.
11 Jan 2024 06:43 PM
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>"}}
12 Jan 2024 12:50 PM - edited 12 Jan 2024 12:53 PM
@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.
14 Jan 2024 07:45 PM
OK, that wasn't clear. I tried to use it in a workflow.