Synthetic Monitoring
Browser monitors, HTTP monitors, synthetic locations.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to access Dynatrace platform API from a synthetic browser test

gilgi
DynaMight Champion
DynaMight Champion

Hi, 

We're trying to build asynthetic browser test against a site that requires OTP.
As there is no direct API to get the OTP data from the provider we need to bypass it so we've created a "back door" workflow to extract it and generate a business event that will store the result. we now in the stage that we need to query it using DQL from the script but facing CORS error as the Dynatrace domain is different than the tested site.

we already know the great article from @HannahM however the current issue is how to avoid the CORS error when accessing the platform without signing in to the platform itself (as accessing the domain itself directly goes to the login page).

Any ideas? 
Gil.

6 REPLIES 6

HannahM
Dynatrace Guru
Dynatrace Guru

Does it matter that you only go to the login page? You could ignore the 401 error, if that's causing a failure, or is it that the login page is another domain so doesn't help?

Synthetic SME and community advocate.

gilgi
DynaMight Champion
DynaMight Champion

Hi @HannahM 

It seemed like it was not enough but found out there was another issue. we're testing it right now. will update.


Gil.

gilgi
DynaMight Champion
DynaMight Champion

Hi @HannahM ,

So I have the following browser test js node:

api.startAsyncSyntheticEvent();

const url = 'https://TENANTURL.apps.dynatrace.com/platform/storage/query/v1/query:execute';
const payload = {
    "query": "fetch logs, from:now()-10m",
    "requestTimeoutMilliseconds": 10000
};

fetch(url, {
        method: 'POST',
        headers: {
            'accept': 'application/json',
            'Content-Type': 'application/json',
            'Authorization': 'Bearer TOKEN'
        },
        body: JSON.stringify(payload)
    })
    .then(response => {
        if (!response.ok) {
            throw new Error(`HTTP ${response.status}`);
        }
        return response.json();
    })
    .then(data => {
        if (data.state && data.state !== 'SUCCEEDED') {
            api.fail("Query not complete inline, state: " + data.state);
            return;
        }
        api.info("GIL: records = " + (data.result ? data.result.records.length : 0));
        api.finish();
    })
    .catch(error => {
        api.fail("GIL: fetch failed: " + error.message);
    });

It runs after I navigate to my tenant url and being redirected to the sso page.
The fetch itself fails at the end and the message is plain "fetch failed". we've even changed the original website to another one. any thoughts? (I think this discussion is important to many use cases hence this is not directly also managed in a ticket - let me know if only a summary should be done here)

dannemca
DynaMight Guru
DynaMight Guru

if I understood correctly, you have a Workflow that retrieve the OTP and stores as business events. And now, you are using the synthetic step to query this value to use it as authentication... right?

Why not store the OTP in a credential vault instead, that can be used natively by synthetics?

Site Reliability Engineer @ Kyndryl

gilgi
DynaMight Champion
DynaMight Champion

I  should have thought of it myself!! thanks @dannemca 

That's what community is for!!!

Site Reliability Engineer @ Kyndryl

Featured Posts