We are building a Postman solution to monitor API request performance for our organization by charting the latency over time of a collections of requests. Our application can have an arbitrary number of user generated projects. The latency of requests can vary depending on how a user configures each project. To profile this, we would like to first pull a list of available projects from our application, and run the collection of requests on each of them.
We currently accomplish this with a setNextRequest loop, which iterates through all available projects. I’ve added a few code snippets below to help explain:
// the start of the loop. we get number of projects and data from the current project:
const projectList = JSON.parse(responseBody);
const pidx = pm.environment.get("projectIndex");
pm.environment.set("numProjects", projectList.length);
pm.environment.set("projectId", projectList[pidx].resourceId);
pm.environment.set("projectTitle", projectList[pidx].name);
// we can now use {{projectId}} in a few requests we want to test.
// and in the last request we either go back to the start of the loop or break:
pm.environment.set("projectIndex", pm.environment.get("projectIndex") + 1);
pidx = pm.environment.get("projectIndex");
pnum = pm.environment.get("numProjects");
if (pidx < pnum) {
postman.setNextRequest("beginning");
}
else {
postman.setNextRequest(null);
}
This issue with this solution is that there is not a good way to associate each request to the current project name. At the moment, we output the project name as a conditionless test on each request:
pm.test(`Project: ${pm.environment.get("projectTitle")}`);
However, this feels a bit hacky, and this test data does not persist through to our datadog integration. Additionally, in the monitor UI, all requests with the same request names have their latencies summed, even if each individual request tests different projects. We would like our monitor results, either in Postman or Datadog, to chart the results for each request separately if the variables used to call the request are different even though the request name is the same. If we could dynamically change the request name that would be one solution but we have yet to find a way to do this.
Is there a better way of doing what we are trying to do?