Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

How to track analytics per flow in Apigee?

Hello Community,

I have an API proxy with multiple flows, one for each exposed backend service. The GET methods receive path parameters

svargasm_0-1740067276894.png

 

I’m facing an issue when creating a custom report in Apigee Analytics because I need to see separate metrics for each flow.

Initially, I tried using the "Flow Resource" dimension, but it always shows as "not set"

svargasm_1-1740067419760.png

Using the request path doesn't work either because, with path parameters, each request is detected as a different path.

Now, I’m trying to use the StatisticsCollector policy to capture the environment variables current.flow.name or current.flow.description by placing the policy inside each flow, but the values always appear empty.

svargasm_2-1740067545546.png

svargasm_3-1740067705318.png

As a workaround, I’m creating an AssignMessage policy to generate a custom variable custom.flow.name, but I haven't found a way to dynamically pass the flow name as a parameter.

This is just an example of what I need for this last idea, I know it doesn't work this way.

svargasm_6-1740067910870.png

svargasm_7-1740068010395.png

 

I’d really appreciate any help or guidance on how to properly capture flow-specific metrics in Apigee Analytics.

Thanks in advance!

Solved Solved
0 9 278
1 ACCEPTED SOLUTION

@svargasm - I was able to reproduce your issue and find a solution for it.

For each conditional flow, you will need to create a Stat Collector policy. I tried using a variable but it wasnt working since it has a special character. This is what I did. I created 3 different Stat Collector policy (one for lines, brands and vehicle)

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<StatisticsCollector async="false" continueOnError="false" enabled="true" name="StatCollect-Brands">
    <DisplayName>StatCollect-Brands</DisplayName>
    <Properties/>
    <Statistics>
        <Statistic name="customPath" type="string">/brands</Statistic>
    </Statistics>
</StatisticsCollector>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<StatisticsCollector async="false" continueOnError="false" enabled="true" name="StatCollect-Lines">
    <DisplayName>StatCollect-Lines</DisplayName>
    <Properties/>
    <Statistics>
        <Statistic name="customPath" type="string">/lines</Statistic>
    </Statistics>
</StatisticsCollector>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<StatisticsCollector async="false" continueOnError="false" enabled="true" name="StatCollect-Vehicles">
    <DisplayName>StatCollect-Vehicles</DisplayName>
    <Properties/>
    <Statistics>
        <Statistic name="customPath" type="string">/vehicles</Statistic>
    </Statistics>
</StatisticsCollector>

And then added each of the policies to the Response for each flows

<Flow name="getLinesByCode">
            <Description/>
            <Request/>
            <Response>
                <Step>
                    <Name>StatCollect-Lines</Name>
                </Step>
                <Step>
                    <Name>AM-SetVehicleLineResponse</Name>
                </Step>
            </Response>
            <Condition>proxy.pathsuffix MatchesPath "/lines/*" and request.verb = "GET"</Condition>
        </Flow>
        <Flow name="getVehicleByPlate">
            <Description/>
            <Request/>
            <Response>
                <Step>
                    <Name>StatCollect-Vehicles</Name>
                </Step>
                <Step>
                    <Name>AM-SetVehicleResponse</Name>
                </Step>
            </Response>
            <Condition>proxy.pathsuffix MatchesPath "/vehicles/*" and request.verb = "GET"</Condition>
        </Flow>
        <Flow name="getBrands">
            <Description/>
            <Request/>
            <Response>
                <Step>
                    <Name>StatCollect-Brands</Name>
                </Step>
                <Step>
                    <Name>AM-SetBrandResponse</Name>
                </Step>
            </Response>
            <Condition>proxy.pathsuffix MatchesPath "/brands/*" and request.verb = "GET"</Condition>
        </Flow>

This create a custom dimension called "customPath". I then created a Custom report with "customPath" as the first dimension and then Proxy Path suffix as 2nd. After a few mins, the graph showed up the way you asked.

Not elegant but works for your use case. Apigee considers anything in the Path as part of the URI, so it considers each as separate records for the GET APIs as they are unique path parameters.

Hope this helps!

View solution in original post

9 REPLIES 9

Hey @svargasm,

We’ve noticed your question hasn’t been answered yet, but we’ll keep it on our radar and reach out to others in the community to chime in.

@svargasm - can you select "Proxy Path Suffix"

That should generate it per path within the proxy. If you want you can add another dimension with "Proxy" so that it filters through against each proxy

Hi @ssvaidyanathan 

Thank you for your response! However, using "Proxy Path Suffix" in my case yields the same result as using "Request Path." Since I have a path parameter for the license plate, each plate is distinguished separately rather than by "Flow Name."

svargasm_1-1740757270215.png

 

 

 

@svargasm - can you give me an example of the calls being made to Apigee with different IDs and then what do you want to see in the report?

 

@ssvaidyanathan 

My API proxy receives the following example requests:

URL: www.api.com
Base path: apivehicle/v1

Request Paths:

  • /vehicles/1234
  • /vehicles/5678
  • /vehicles/7899
  • /vehicles/7899
  • /vehicles/lines/2
  • /vehicles/lines/3
  • /brands/cod1
  • /brands/cod2
  • /brands/cod5

I want to see a custom report where I can view the number of requests without considering path parameters:

Flow Traffic

/vehicles4
/vehicles/lines2
/brands3

Thank you for that and I am assuming you have individual conditional flows for each of those.. like this in your proxy

<Flows>
    <Flow name="Get-Vehicle">
      <Condition>(proxy.pathsuffix MatchesPath "/vehicle/{id}") AND (request.verb = "GET")</Condition>
      <Request/>
      <Response/>
    </Flow>
    <Flow name="Get-Vehicle-line">
      <Condition>(proxy.pathsuffix MatchesPath "/vehicle/lines/{id}") AND (request.verb = "GET")</Condition>
      <Request/>
      <Response/>
    </Flow>
    <Flow name="Get-Brand">
      <Condition>(proxy.pathsuffix MatchesPath "/branhds/{id}") AND (request.verb = "GET")</Condition>
      <Request/>
      <Response/>
    </Flow>
</Flows>

@ssvaidyanathan  

That's right!

@svargasm - I was able to reproduce your issue and find a solution for it.

For each conditional flow, you will need to create a Stat Collector policy. I tried using a variable but it wasnt working since it has a special character. This is what I did. I created 3 different Stat Collector policy (one for lines, brands and vehicle)

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<StatisticsCollector async="false" continueOnError="false" enabled="true" name="StatCollect-Brands">
    <DisplayName>StatCollect-Brands</DisplayName>
    <Properties/>
    <Statistics>
        <Statistic name="customPath" type="string">/brands</Statistic>
    </Statistics>
</StatisticsCollector>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<StatisticsCollector async="false" continueOnError="false" enabled="true" name="StatCollect-Lines">
    <DisplayName>StatCollect-Lines</DisplayName>
    <Properties/>
    <Statistics>
        <Statistic name="customPath" type="string">/lines</Statistic>
    </Statistics>
</StatisticsCollector>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<StatisticsCollector async="false" continueOnError="false" enabled="true" name="StatCollect-Vehicles">
    <DisplayName>StatCollect-Vehicles</DisplayName>
    <Properties/>
    <Statistics>
        <Statistic name="customPath" type="string">/vehicles</Statistic>
    </Statistics>
</StatisticsCollector>

And then added each of the policies to the Response for each flows

<Flow name="getLinesByCode">
            <Description/>
            <Request/>
            <Response>
                <Step>
                    <Name>StatCollect-Lines</Name>
                </Step>
                <Step>
                    <Name>AM-SetVehicleLineResponse</Name>
                </Step>
            </Response>
            <Condition>proxy.pathsuffix MatchesPath "/lines/*" and request.verb = "GET"</Condition>
        </Flow>
        <Flow name="getVehicleByPlate">
            <Description/>
            <Request/>
            <Response>
                <Step>
                    <Name>StatCollect-Vehicles</Name>
                </Step>
                <Step>
                    <Name>AM-SetVehicleResponse</Name>
                </Step>
            </Response>
            <Condition>proxy.pathsuffix MatchesPath "/vehicles/*" and request.verb = "GET"</Condition>
        </Flow>
        <Flow name="getBrands">
            <Description/>
            <Request/>
            <Response>
                <Step>
                    <Name>StatCollect-Brands</Name>
                </Step>
                <Step>
                    <Name>AM-SetBrandResponse</Name>
                </Step>
            </Response>
            <Condition>proxy.pathsuffix MatchesPath "/brands/*" and request.verb = "GET"</Condition>
        </Flow>

This create a custom dimension called "customPath". I then created a Custom report with "customPath" as the first dimension and then Proxy Path suffix as 2nd. After a few mins, the graph showed up the way you asked.

Not elegant but works for your use case. Apigee considers anything in the Path as part of the URI, so it considers each as separate records for the GET APIs as they are unique path parameters.

Hope this helps!

Not elegant but works!

Thank you!