Statistics Collector Policy - Flow Name not captured

Hello,

I am trying to collect the current flow name for proxy transactions. My Statistics Collection policy is as below:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<StatisticsCollector async="false" continueOnError="false" enabled="true" name="STATS-StatisticsCollector">
    <DisplayName>STATS-StatisticsCollector</DisplayName>
    <Statistics>
        <Statistic name="flowname" ref="current.flow.name" type="string">Unknown</Statistic>
    </Statistics>
</StatisticsCollector>

I have placed the same collection policy in each of my proxy conditional flows (in the response).

However, when I view the statistics, I can see that the current.flow.name is set to 'PostClientFlow' rather than the name of the conditional flow. When I use an assign message or javascript callout in the same place, the current flow name is returned correctly.

Has anyone else faced this issue? Also, should the variables set by the policy show up during trace?

Solved Solved
2 4 384
1 ACCEPTED SOLUTION

I don't quite understand. Maybe the misunderstanding is on your side?

The StatsCollector is a thing that helps you add data items to the record that is collected for each request.

The Stats Collector always runs in the PostClientFlow. You can attach the StatsCollector policy anywhere, but it really executes after the client is finished receiving the response. You can understand why it runs after the response has been delivered - only then can the stats collector possibly know the response times for the client response.

Therefore if you add a statistic and refer to "current.flow.name" , then when the StatisticsCollector runs, that variable will always return a value of PostClientFlow.

What is it that you REALLY want to do? If you want to record the name of the conditional flow that executed, then I suggest assigning, within the conditional flow, to a non-volatile, non-system variable, maybe with a name like "flow-that-handled-the-call". a variable with that name will never be overwritten.

<AssignMessage name='AM-RecordFlowName'>
  <AssignVariable>
    <Name>conditional-flow-that-handled-the-call</Name>
    <Ref>current.flow.name</Ref>
  </AssignVariable>
</AssignMessage>

And then add the StatisticsCollector in the PostFlow:

<StatisticsCollector name="STATS-StatisticsCollector">
    <DisplayName>STATS-StatisticsCollector</DisplayName>
    <Statistics>
        <Statistic name="flowname" ref="conditional-flow-that-handled-the-call" type="string">Unknown</Statistic>
    </Statistics>
</StatisticsCollector>

View solution in original post

4 REPLIES 4

I don't quite understand. Maybe the misunderstanding is on your side?

The StatsCollector is a thing that helps you add data items to the record that is collected for each request.

The Stats Collector always runs in the PostClientFlow. You can attach the StatsCollector policy anywhere, but it really executes after the client is finished receiving the response. You can understand why it runs after the response has been delivered - only then can the stats collector possibly know the response times for the client response.

Therefore if you add a statistic and refer to "current.flow.name" , then when the StatisticsCollector runs, that variable will always return a value of PostClientFlow.

What is it that you REALLY want to do? If you want to record the name of the conditional flow that executed, then I suggest assigning, within the conditional flow, to a non-volatile, non-system variable, maybe with a name like "flow-that-handled-the-call". a variable with that name will never be overwritten.

<AssignMessage name='AM-RecordFlowName'>
  <AssignVariable>
    <Name>conditional-flow-that-handled-the-call</Name>
    <Ref>current.flow.name</Ref>
  </AssignVariable>
</AssignMessage>

And then add the StatisticsCollector in the PostFlow:

<StatisticsCollector name="STATS-StatisticsCollector">
    <DisplayName>STATS-StatisticsCollector</DisplayName>
    <Statistics>
        <Statistic name="flowname" ref="conditional-flow-that-handled-the-call" type="string">Unknown</Statistic>
    </Statistics>
</StatisticsCollector>

Sorry, this was a misunderstanding on my behalf. I know the analytics are recorded in the post client flow, but I thought if I attached the policy on the conditional flow it would capture the current flow name at the time. Thanks for your explanation.

@Dino-at-Google Do you have any other idea to capture the executed conditional flow name? I have a lot of existing proxies I have to change(Add same assign message policy at different spots)/deploy(which i want to avoid) if i chose this route. per my use case i need to get the executed flow name in the sharedflow that is part of post client flow. Appreciate your suggestion.

Not applicable

If you are not interested to modify the proxies, you can add one extra header or query param in the request which you can add to the statistic collector using flow hook.