Google Stackdriver Logging 擴充功能

您目前查看的是 Apigee Edge 說明文件。
前往 Apigee X 說明文件。
info

1.3.7 版

將項目寫入 Stackdriver Logging 記錄。

這項內容提供設定及使用這項擴充功能的參考資料。

必要條件

如要透過 API Proxy 使用這項擴充功能,請務必先完成下列步驟:

  1. 在 IAM 中,將「記錄」>「記錄寫入者」和「記錄」>「記錄檢視者」角色指派給專案成員,代表擴充功能與 Stackdriver Logging 系統互動。如需授予角色的操作說明,請參閱「將特定資源的角色授予服務帳戶」。如要進一步瞭解記錄角色,請參閱「存取控管指南」。

  2. 使用 GCP 控制台產生服務帳戶的金鑰。

  3. 使用產生的金鑰 JSON 檔案內容,透過設定參考資料新增及設定擴充功能。

這個擴充功能支援由 PostClientFlow 中的 ExtensionCallout 政策呼叫。 如要使用 ExtensionCallout 政策從 PostClientFlow 呼叫這個擴充功能,請確保貴機構的 features.allowExtensionsInPostClientFlow 旗標設為 true。

  • 如果您是 Apigee Edge Public Cloud 客戶,請務必聯絡 Apigee Edge 支援團隊,確保貴機構的 features.allowExtensionsInPostClientFlow 旗標設為 true。

  • 如果您是 Apigee Edge for Private Cloud 客戶,請使用「更新機構屬性」API,將 features.allowExtensionsInPostClientFlow 標記設為 true。

關於 Stackdriver Logging

Stackdriver Logging 是 Google Cloud Platform (GCP) Stackdriver 系列產品之一。其中包括記錄檔的儲存空間、稱為記錄檢視器的使用者介面,以及以程式化方式管理記錄的 API。您可以使用 Stackdriver Logging 讀取及寫入記錄項目、搜尋及篩選記錄、匯出記錄,以及建立記錄指標。

這項擴充功能目前會將項目寫入記錄檔。詳情請參閱 Stackdriver Logging 文件。

範例

下列範例說明如何使用 ExtensionCallout 政策,設定 Stackdriver Logging 擴充功能動作的支援功能。

全域記錄

下列政策會將「This is a test」訊息寫入 Stackdriver 全域性資源中名為 example-log 的記錄。在實際使用時,您可能會將訊息納入流程變數,並在 API Proxy 的其他位置設定該變數的值。

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ConnectorCallout async="false" continueOnError="true" enabled="true" name="Logging-Extension">
    <DisplayName>Logging Connector</DisplayName>
    <Connector>stackdriver-extension-sample</Connector>
    <Action>log</Action>
    <Input><![CDATA[{
        "logName": "example-log",
        "metadata": {
            "resource": {
                "type": "global",
                "labels": {
                    "project_id": "my-test"
                }
            }
        },
        "message": "This is a test"
    }]]></Input>
</ConnectorCallout>

這項內容提供設定及使用這項擴充功能的參考資料。如要瞭解如何使用 Apigee 控制台設定擴充功能,請參閱「新增及設定擴充功能」。

動作

log

將訊息寫入記錄。

這項動作會寫入 Stackdriver 記錄項目。記錄項目包含中繼資料和項目資料。如要進一步瞭解記錄項目,請參閱「項目參考資料」。如要瞭解 metadata 屬性的內容,請參閱 Stackdriver Logging 說明文件中的 LogEntry 物件。

語法

<Action>log</Action>
<Input><![CDATA[{
  "logName" : "stackdriver-log-name-to-use",
  "metadata" : JSON-structured-metadata,
  "message" : "data-to-log-as-entry"
}]]></Input>

範例

<Action>log</Action>
<Input><![CDATA[{
  "logName" : "stackdriver-log-name-to-use",
  "metadata" : { "resource" : { "type" : "global" } },
  "message" : "data-to-log-as-entry"
}]]></Input>

要求參數

參數 說明 類型 預設 必填
logName 這個項目所屬的記錄名稱。 字串 無。 是。
中繼資料 記錄項目相關中繼資料。
如要進一步瞭解如何設定 type 和 labels,請參閱 metadata 中的「MonitoredResource」。
JSON 無。 不會。
訊息 要當做這個記錄項目值的資料。 字串 無。 是。

回應

如果訊息已寫入記錄,則為無。否則要求會傳回錯誤。另請參閱「偵錯擴充功能」。

設定參照

設定及部署這個擴充功能,以便在 API Proxy 中使用時,請參考下列資訊。

常見擴充功能屬性

每個擴充功能都有下列屬性。

屬性 說明 預設 必要
name 您要為這項擴充功能設定的名稱。 無 相容
packageName Apigee Edge 指定的擴充功能套件名稱。 無 相容
version 擴充功能的擴充功能套件版本號碼。 無 相容
configuration 您要新增的擴充功能專屬的設定值。請參閱「這個擴充功能套件的屬性」一文 無 相容

這個擴充功能套件的屬性

請為這個擴充功能專用的下列設定屬性指定值。

屬性 說明 預設 必填
projectId 要建立記錄的 GCP 專案 ID。 無。 是。
憑證 在 Apigee Edge 控制台中輸入的內容,就是服務帳戶金鑰檔案的內容。透過 Management API 傳送時,這是從服務帳戶金鑰檔案產生的 Base64 編碼值。 無。 是。