Create an Alert based on Metric and APM

I am trying to figure out how to create an alert based on two different metrics.

  1. A gauge metric, say m1, with a granularity of 10 seconds (It’s possible to make 1 second if that helps)
  2. Transaction count from An APM App say A1.

I want to create an alert, which triggers when the sum of M1 in the last 10 seconds becomes more than the sum of unique Trip IDs from A1. Additionally, I would like to apply some filters to the tripId counts of A1 (e.g. WHERE request.URI is = '/some/path/in/a1')

Is this possible? How should I go about it?