Does Edge generate a unique ID for each API request?

Not applicable

I need a unique ID generated for logging/troubleshooting purposes and wanted to check if there was one already available from Edge instead of generating a custom one with a policy.

Solved Solved
3 4 6,230
1 ACCEPTED SOLUTION

Not applicable

There's a flow variable, messageid, that's available for use and contains a unique identifier for each API request. This messageid is used in Edge application logs and can be useful for troubleshooting issues without knowing where they originate. Below is an example policy which adds the ID to a request header before sending to a backend service:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage enabled="true" continueOnError="true" async="false" name="setUniqueIdHeader" type="request">
    <Set>
        <Headers>
            <Header name="x-request-id">{messageid}</Header>
        </Headers>
    </Set>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
</AssignMessage>

Note: I set continueOnError to true because I don't want this policy, for any reason, to stop API request processing.

By adding this ID to a request header before the request is sent to the backend service, you allow any backend APIs to extract the ID and log it as well. You now have a trace for each API request from the edge to the backend service.

For more information on Edge predefined variables, check out the doc page @ http://apigee.com/docs/api-services/reference/variables-reference#requestmessagevariables

View solution in original post

4 REPLIES 4

Not applicable

There's a flow variable, messageid, that's available for use and contains a unique identifier for each API request. This messageid is used in Edge application logs and can be useful for troubleshooting issues without knowing where they originate. Below is an example policy which adds the ID to a request header before sending to a backend service:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage enabled="true" continueOnError="true" async="false" name="setUniqueIdHeader" type="request">
    <Set>
        <Headers>
            <Header name="x-request-id">{messageid}</Header>
        </Headers>
    </Set>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
</AssignMessage>

Note: I set continueOnError to true because I don't want this policy, for any reason, to stop API request processing.

By adding this ID to a request header before the request is sent to the backend service, you allow any backend APIs to extract the ID and log it as well. You now have a trace for each API request from the edge to the backend service.

For more information on Edge predefined variables, check out the doc page @ http://apigee.com/docs/api-services/reference/variables-reference#requestmessagevariables

Here is the doc page on messageid: http://apigee.com/docs/api-services/reference/variables-reference

Stephen

@Michael Russo Can this message ID be configured to suppress the router hostname which it contains?

OK. I could confirm that unfortunately this will not be possible because that messageId is constructed in the router code and attempting this might break the random/unique nature of it.