本頁內容適用於 Apigee 和 Apigee Hybrid。
查看
Apigee Edge 說明文件。
您可以使用 TraceCapture 政策,在 Apigee 執行階段的追蹤資料中新增其他變數。如果您已為 Apigee 執行階段啟用分散式追蹤,執行階段預設會追蹤一組預先定義的變數。詳情請參閱「追蹤報表中的預設追蹤變數」。不過,如要讓 Apigee 執行階段追蹤其他流程、政策或自訂變數,請使用 TraceCapture 政策。您可以在要求或回應流程中使用這項政策。在分散式追蹤報告中,您可以在 TraceCaptureExecution span 中查看 TraceCapture 政策新增的變數。
這項政策是可擴充政策,使用這項政策可能會產生費用或影響用量,具體情況取決於您的 Apigee 授權。如要瞭解政策類型和使用方式的影響,請參閱「政策類型」。
<TraceCapture>
定義 TraceCapture 政策。
| 預設值 | 不適用 |
| 必填與否 | 必填 |
| 類型 | 複雜型別 |
| 父項元素 | 不適用 |
| 子元素 |
<DisplayName><IgnoreUnresolvedVariables><ThrowExceptionOnLimit><Variables> |
<TraceCapture> 元素使用下列語法:
語法
<?xml version="1.0" encoding="UTF-8"?>
<TraceCapture continueOnError="true" enabled="true" name="DistributedTraceCapture-1">
<DisplayName>POLICY_DISPLAY_NAME</DisplayName>
<Variables>
<Variable name="TRACE_VARIABLE_NAME" ref="FLOW_VARIABLE_NAME">DEFAULT_VALUE</Variable>
<Variable name="TRACE_VARIABLE_NAME" ref="FLOW_VARIABLE_NAME">DEFAULT_VALUE</Variable>
</Variables>
<IgnoreUnresolvedVariables>BOOLEAN_VALUE</IgnoreUnresolvedVariables>
<ThrowExceptionOnLimit>BOOLEAN_VALUE</ThrowExceptionOnLimit>
</TraceCapture>範例
以下範例顯示 TraceCapture 政策定義:
<?xml version="1.0" encoding="UTF-8"?> <TraceCapture continueOnError="true" enabled="true" name="DistributedTraceCapture-1"> <DisplayName>Distributed-Trace-Capture-Policy-1</DisplayName> <Variables> <Variable name="trace-variable-1" ref="flow-variable-1">default-val-1</Variable> <Variable name="trace-variable-2" ref="flow-variable-2">default-val-2</Variable> </Variables> <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables> <ThrowExceptionOnLimit>false</ThrowExceptionOnLimit> </TraceCapture>
這個元素包含下列所有政策都適用的屬性:
| 屬性 | 預設 | 是否必要? | 說明 |
|---|---|---|---|
name |
不適用 | 必要 |
政策的內部名稱。 您可以選擇使用 |
continueOnError |
false | 選用 | 將其設為 false,即可在政策失敗時傳回錯誤。這是大多數政策的預期行為。將其設為 true,即使政策失敗,流程執行作業仍會繼續進行。另請參閱:
|
enabled |
是 | 選用 | 設為 true 即可強制執行政策。設為 false 即可關閉政策。即使政策仍附加至流程,系統也不會強制執行這項政策。 |
async |
false | 已淘汰 | 此屬性已淘汰。 |
下表簡要說明 <TraceCapture> 的子元素:
| 子元素 | 是否必要 | 說明 |
|---|---|---|
<DisplayName> |
選用 | 指定政策的自訂名稱。 |
<Variables> |
選用 | 指定要追蹤的變數清單。 |
<IgnoreUnresolvedVariables> |
選用 | 指定遇到無法解析的變數時,是否要停止處理。 |
<ThrowExceptionOnLimit> |
選用 | 指定變數大小超過 256 位元組限制時,是否必須截斷變數。 |
| 其他子元素 | ||
<MergeBehavior> |
選用 | 指定回覆訊息的合併行為。 |
子元素參照
本節說明<TraceCapture> 的子元素。
<DisplayName>
除了 name 屬性之外,您也可以在管理 UI 代理程式編輯器中使用其他更自然的名稱標記政策。
<DisplayName> 元素適用於所有政策。
| 預設值 | 不適用 |
| 是否必要? | (非必要) 如果省略 <DisplayName>,系統會使用政策的 name 屬性值。 |
| 類型 | 字串 |
| 上層元素 | <PolicyElement> |
| 子元素 | 無 |
<DisplayName> 元素使用以下語法:
語法
<PolicyElement> <DisplayName>POLICY_DISPLAY_NAME</DisplayName> ... </PolicyElement>
範例
<PolicyElement> <DisplayName>My Validation Policy</DisplayName> </PolicyElement>
<DisplayName> 元素沒有屬性或子項元素。
<Variables>
指定要追蹤的變數清單。
| 預設值 | 不適用 |
| 必填與否 | 必填 |
| 類型 | 複雜型別 |
| 父項元素 |
<TraceCapture> |
| 子元素 |
<Variable> |
<Variables> 元素使用下列語法:
語法
<Variables>
<Variable name="TRACE_VARIABLE_NAME" ref="FLOW_VARIABLE_NAME">DEFAULT_VALUE</Variable>
<Variable name="TRACE_VARIABLE_NAME" ref="FLOW_VARIABLE_NAME">DEFAULT_VALUE</Variable>
</Variables>範例
以下範例會追蹤 flow-variable-1 和 flow-variable-2 流程變數:
<Variables> <Variable name="trace-variable-1" ref="flow-variable-1">default-val-1</Variable> <Variable name="trace-variable-2" ref="flow-variable-2">default-val-2</Variable> </Variables>
<Variable>
指定要在追蹤記錄資料中加入的變數。
| 預設值 | 不適用 |
| 必填與否 | 必填 |
| 類型 | 複雜型別 |
| 父項元素 |
<Variables> |
| 子元素 | 無 |
<Variable> 元素使用下列語法:
語法
<Variable name="TRACE_VARIABLE_NAME" ref="FLOW_VARIABLE_NAME">DEFAULT_VALUE</Variable>
範例
以下範例會將 trace-variable-1 追蹤變數設為 flow-variable-1 流程變數的值:
<Variable name="trace-variable-1" ref="flow-variable-1">default-val-1</Variable>
如果 flow-variable-1 流程變數無法使用,trace-variable-1 會設為預設值 default-val-1。
下表說明 <Variable> 的屬性:
| 屬性 | 是否必要 | 類型 | 說明 |
|---|---|---|---|
name |
必填 | 字串 | 用於參照指定變數所收集資料的名稱。這個名稱會顯示在分散式追蹤報表中。 |
ref |
必填 | 字串 | 您要收集追蹤資料的變數。這個變數可以是 Apigee 預先定義的流程變數,也可以是 API Proxy 中的自訂變數。 |
<IgnoreUnresolvedVariables>
判斷遇到無法解析的變數時,是否停止處理。
| 預設值 | 不適用 |
| 必填與否 | 選用 |
| 類型 | 布林值 |
| 父項元素 |
<TraceCapture> |
| 子元素 | 無 |
設為 true 可忽略未解析的變數並繼續處理;否則設為 false。預設值為 true。
將 <IgnoreUnresolvedVariables> 設為 true 與將 <TraceCapture> 的 continueOnError 設為 true 不同。如果將 continueOnError 設為 true,Apigee 會忽略所有錯誤,而不只是變數中的錯誤。
<IgnoreUnresolvedVariables> 元素使用下列語法:
語法
<IgnoreUnresolvedVariables>BOOLEAN_VALUE</IgnoreUnresolvedVariables>
範例
以下範例會將 <IgnoreUnresolvedVariables> 設為 false:
<IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
<ThrowExceptionOnLimit>
指定變數大小超過 256 位元組上限時的政策行為。
- 如果設為
true,當變數大小超過限制時,政策就會擲回錯誤。 - 如果設為
false,這項政策會截斷超過限制的變數。變數會截斷至大小上限。
| 預設值 | 不適用 |
| 必填與否 | 選用 |
| 類型 | 布林值 |
| 父項元素 |
<TraceCapture> |
| 子元素 | 無 |
<ThrowExceptionOnLimit> 元素使用下列語法:
語法
<ThrowExceptionOnLimit>BOOLEAN_VALUE</ThrowExceptionOnLimit>
範例
以下範例會將 值設為 <ThrowExceptionOnLimit>true。
<ThrowExceptionOnLimit>false</ThrowExceptionOnLimit>
錯誤代碼
This section describes the fault codes and error messages that are returned and fault variables that are set by Apigee when this policy triggers an error. This information is important to know if you are developing fault rules to handle faults. To learn more, see What you need to know about policy errors and Handling faults.
Runtime errors
These errors can occur when the policy executes.
| Fault code | HTTP status | Cause |
|---|---|---|
steps.tracecapture.UnresolvedVariable |
500 |
This error occurs if a variable specified in the TraceCapture policy is either:
|
steps.tracecapture.VariableValueLimitExceeded |
500 |
This error occurs if the |
Fault variables
Whenever there are execution errors in a policy, Apigee generates error messages. You can view these error messages in the error response. Many a time, system generated error messages might not be relevant in the context of your product. You might want to customize the error messages based on the type of error to make the messages more meaningful.
To customize the error messages, you can use either fault rules or the RaiseFault policy. For
information about differences between fault rules and the RaiseFault policy, see
FaultRules vs. the RaiseFault policy.
You must check for conditions using the Condition element in both the fault rules and the RaiseFault policy.
Apigee provides fault variables unique to each policy and the values of the fault variables are set when a policy triggers runtime errors.
By using these variables, you can check for specific error conditions and take appropriate actions. For more information about checking error
conditions, see Building conditions.
The following table describes the fault variables specific to this policy.
| Variables | Where | Example |
|---|---|---|
fault.name |
The fault.name can match to any of the faults listed in the Runtime errors table.
The fault name is the last part of the fault code. |
fault.name Matches "UnresolvedVariable" |
tracecapture.POLICY_NAME.failed |
POLICY_NAME is the user-specified name of the policy that threw the fault. | tracecapture.trace-capture-1.failed = true |